py3.8 compat

This commit is contained in:
caryoscelus 2023-07-26 07:56:31 +00:00
parent eeaded23f9
commit 40ae09dca8
2 changed files with 19 additions and 2 deletions

View file

@ -3,6 +3,7 @@ import sys
import stat
import time
import logging
from util.compat import *
startup_errors = []
def startupError(msg):
@ -54,12 +55,12 @@ def importBundle(bundle):
else:
prefix = ''
top_2 = list(set(filter(lambda f: len(f)>0,
map(lambda f: f.removeprefix(prefix).split('/')[0], all_files))))
map(lambda f: removeprefix(f, prefix).split('/')[0], all_files))))
for d in top_2:
if isValidAddress(d):
logging.info(f'unpack {d} into {config.data_dir}')
for fname in filter(lambda f: f.startswith(prefix+d) and not f.endswith('/'), all_files):
tgt = config.data_dir + '/' + fname.removeprefix(prefix)
tgt = config.data_dir + '/' + removeprefix(fname, prefix)
logging.info(f'-- {fname} --> {tgt}')
info = zf.getinfo(fname)
info.filename = tgt

16
src/util/compat.py Normal file
View file

@ -0,0 +1,16 @@
import sys
if sys.version_info.major == 3 and sys.version_info.minor < 9:
def removeprefix(s, prefix, /):
if s.startswith(prefix):
return s[len(prefix):]
return s
def removesuffix(s, suffix, /):
if s.endswith(suffix):
return s[:-len(suffix)]
return s
else:
def removeprefix(s, prefix, /):
return s.removeprefix(prefix)
def removesuffix(s, suffix, /):
return s.removesuffix(suffix)