diff options
author | Ben Brown <ben@demerara.io> | 2022-02-05 15:47:35 +0000 |
---|---|---|
committer | Ben Brown <ben@demerara.io> | 2022-02-05 16:12:52 +0000 |
commit | cad5b2c2bbbac7015f3f2bf66f8af01bdbf943f8 (patch) | |
tree | e45e09fb18593b9dcf2c0d039d95526f4df0dcbb /lorry.zip-importer | |
parent | d67c456242e7c05eb77f0dc78856c1d704fba846 (diff) | |
download | lorry-cad5b2c2bbbac7015f3f2bf66f8af01bdbf943f8.tar.gz |
Commit changes from from black and isort
Diffstat (limited to 'lorry.zip-importer')
-rwxr-xr-x | lorry.zip-importer | 78 |
1 files changed, 46 insertions, 32 deletions
diff --git a/lorry.zip-importer b/lorry.zip-importer index 6d973dd..972ab2d 100755 --- a/lorry.zip-importer +++ b/lorry.zip-importer @@ -20,25 +20,24 @@ import subprocess import sys from zipfile import ZipFile - -branch_name = 'master' -branch_ref = 'refs/heads/%s' % branch_name -committer_name = 'Lorry Zip Importer' -committer_email = 'lorry-zip-importer@lorry' +branch_name = "master" +branch_ref = "refs/heads/%s" % branch_name +committer_name = "Lorry Zip Importer" +committer_email = "lorry-zip-importer@lorry" # File header 'extra' field tags -EXT_TAG_UNIX0 = 0x000d # PKWARE Unix, aka Unix type 0 -EXT_TAG_TIME = 0x5455 # Extended Timestamp +EXT_TAG_UNIX0 = 0x000D # PKWARE Unix, aka Unix type 0 +EXT_TAG_TIME = 0x5455 # Extended Timestamp EXT_TIME_FLAG_MTIME = 1 # mtime present (and first) -EXT_TAG_UNIX1 = 0x5855 # Info-ZIP Unix type 1 +EXT_TAG_UNIX1 = 0x5855 # Info-ZIP Unix type 1 # Iterate over fields within a file header 'extra' block def zip_extra_fields(extra): pos = 0 while len(extra) >= pos + 4: - tag, size = struct.unpack('<HH', extra[pos : pos + 4]) + tag, size = struct.unpack("<HH", extra[pos : pos + 4]) pos += 4 if len(extra) < pos + size: return @@ -52,11 +51,11 @@ def zip_info_mtime(info): for tag, data in zip_extra_fields(info.extra): format = None if tag in [EXT_TAG_UNIX0, EXT_TAG_UNIX1]: - format = '<4xL' # AcTime, ModTime + format = "<4xL" # AcTime, ModTime elif tag == EXT_TAG_TIME: # First byte indicates which timestamps follow if len(data) >= 1 and data[0] & EXT_TIME_FLAG_MTIME: - format = '<xL' # Flags, ModTime + format = "<xL" # Flags, ModTime if format: min_len = struct.calcsize(format) if len(data) >= min_len: @@ -70,60 +69,75 @@ def zip_info_mtime(info): def export(zipfile, fast_import): def printlines(list): for str in list: - fast_import.write(str.encode('utf-8') + b"\n") + fast_import.write(str.encode("utf-8") + b"\n") commit_time = 0 next_mark = 1 common_prefix = None mark = dict() - zip = ZipFile(zipfile, 'r') + zip = ZipFile(zipfile, "r") for name in zip.namelist(): - if name.endswith('/'): + if name.endswith("/"): continue info = zip.getinfo(name) commit_time = max(commit_time, zip_info_mtime(info)) if common_prefix == None: - common_prefix = name[:name.rfind('/') + 1] + common_prefix = name[: name.rfind("/") + 1] else: while not name.startswith(common_prefix): - last_slash = common_prefix[:-1].rfind('/') + 1 + last_slash = common_prefix[:-1].rfind("/") + 1 common_prefix = common_prefix[:last_slash] - mark[name] = ':' + str(next_mark) + mark[name] = ":" + str(next_mark) next_mark += 1 - printlines(('blob', 'mark ' + mark[name], \ - 'data ' + str(info.file_size))) + printlines(("blob", "mark " + mark[name], "data " + str(info.file_size))) fast_import.write(zip.read(name) + b"\n") - committer = committer_name + ' <' + committer_email + '> %d +0000' % \ - commit_time + committer = committer_name + " <" + committer_email + "> %d +0000" % commit_time zipfile_basename = os.path.basename(zipfile) - printlines(('commit ' + branch_ref, 'committer ' + committer, \ - 'data <<EOM', 'Imported from ' + zipfile_basename + '.', 'EOM', \ - '', 'deleteall')) + printlines( + ( + "commit " + branch_ref, + "committer " + committer, + "data <<EOM", + "Imported from " + zipfile_basename + ".", + "EOM", + "", + "deleteall", + ) + ) for name in mark.keys(): - printlines(('M 100644 ' + mark[name] + ' ' + - name[len(common_prefix):],)) + printlines(("M 100644 " + mark[name] + " " + name[len(common_prefix) :],)) zipname, _ = os.path.splitext(zipfile_basename) - printlines(('', 'tag ' + zipname, \ - 'from ' + branch_ref, 'tagger ' + committer, \ - 'data <<EOM', 'Package ' + zipfile, 'EOM', '')) + printlines( + ( + "", + "tag " + zipname, + "from " + branch_ref, + "tagger " + committer, + "data <<EOM", + "Package " + zipfile, + "EOM", + "", + ) + ) def main(): if len(sys.argv) < 2: - print('usage:', sys.argv[0], '<zipfile>...') + print("usage:", sys.argv[0], "<zipfile>...") sys.exit(1) - with subprocess.Popen('git fast-import --quiet', shell=True, - stdin=subprocess.PIPE) as import_proc: + with subprocess.Popen( + "git fast-import --quiet", shell=True, stdin=subprocess.PIPE + ) as import_proc: for zipfile in sys.argv[1:]: export(zipfile, import_proc.stdin) import_proc.stdin.close() |