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.gzip-importer | |
parent | d67c456242e7c05eb77f0dc78856c1d704fba846 (diff) | |
download | lorry-cad5b2c2bbbac7015f3f2bf66f8af01bdbf943f8.tar.gz |
Commit changes from from black and isort
Diffstat (limited to 'lorry.gzip-importer')
-rwxr-xr-x | lorry.gzip-importer | 70 |
1 files changed, 43 insertions, 27 deletions
diff --git a/lorry.gzip-importer b/lorry.gzip-importer index 5c0c6d0..4f4fb61 100755 --- a/lorry.gzip-importer +++ b/lorry.gzip-importer @@ -4,65 +4,81 @@ # gzip archive frontend for git-fast-import -from gzip import GzipFile import os.path import struct import subprocess import sys +from gzip import GzipFile - -branch_name = 'master' -branch_ref = 'refs/heads/%s' % branch_name -committer_name = 'Lorry Gzip Importer' -committer_email = 'lorry-gzip-importer@lorry' +branch_name = "master" +branch_ref = "refs/heads/%s" % branch_name +committer_name = "Lorry Gzip Importer" +committer_email = "lorry-gzip-importer@lorry" # The size of a gzip file is stored in the last 4 bytes def uncompressedsize(filename): - with open(filename, 'rb') as f: + with open(filename, "rb") as f: f.seek(-4, 2) - return struct.unpack('I', f.read(4))[0] + return struct.unpack("I", f.read(4))[0] 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") # Gzip does have an encoded mtime, however Python's GzipFile # just ignores it, so we just yank the mtime of the zip file itself. - mtime = os.path.getmtime(zipfile); - file_size = uncompressedsize (zipfile); - zip = GzipFile(zipfile, 'rb') + mtime = os.path.getmtime(zipfile) + file_size = uncompressedsize(zipfile) + zip = GzipFile(zipfile, "rb") - printlines(('blob', 'mark :1', 'data ' + str(file_size))) + printlines(("blob", "mark :1", "data " + str(file_size))) fast_import.write(zip.read() + b"\n") - committer = committer_name + ' <' + committer_email + '> %d +0000' % \ - mtime + committer = committer_name + " <" + committer_email + "> %d +0000" % mtime zipfile_basename = os.path.basename(zipfile) - printlines(('commit ' + branch_ref, 'committer ' + committer, \ - 'data <<EOM', 'Imported from ' + zipfile_basename + '.', 'EOM', \ - '', 'deleteall')) - - last_dot = zipfile_basename[:-1].rfind('.') + printlines( + ( + "commit " + branch_ref, + "committer " + committer, + "data <<EOM", + "Imported from " + zipfile_basename + ".", + "EOM", + "", + "deleteall", + ) + ) + + last_dot = zipfile_basename[:-1].rfind(".") unzipped_file = zipfile_basename[:last_dot] - printlines(('M 100644 :1 ' + unzipped_file,)); + printlines(("M 100644 :1 " + unzipped_file,)) 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], '<gzipfile>...') + print("usage:", sys.argv[0], "<gzipfile>...") 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() |