Skip to content

Commit

Permalink
py3.8 compat
Browse files Browse the repository at this point in the history
  • Loading branch information
caryoscelus committed Jul 26, 2023
1 parent eeaded2 commit 40ae09d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import stat
import time
import logging
from util.compat import *

startup_errors = []
def startupError(msg):
Expand Down Expand Up @@ -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
Expand Down
16 changes: 16 additions & 0 deletions src/util/compat.py
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 40ae09d

Please sign in to comment.