summaryrefslogtreecommitdiff
path: root/lorry.gzip-importer
diff options
context:
space:
mode:
authorBen Hutchings <ben.hutchings@codethink.co.uk>2020-05-04 19:48:13 +0100
committerBen Hutchings <ben.hutchings@codethink.co.uk>2020-05-29 20:35:30 +0100
commit4792912cecf52d63fdcc89e6f852e3a32f37c49c (patch)
treea59a0659b0f1d4749e0af4f12202ea8cdae9a1e6 /lorry.gzip-importer
parent2234eae5baddeee7f41b41b40cf5cfb5d61436a1 (diff)
downloadlorry-4792912cecf52d63fdcc89e6f852e3a32f37c49c.tar.gz
lorry,{g,}zip-importer: Move top-level code into functions
Split the top-level code of each script into: * export: Exports a single file to a 'git fast-import' pipe * main: Spawns 'git fast-import' and calls export for each file
Diffstat (limited to 'lorry.gzip-importer')
-rwxr-xr-xlorry.gzip-importer30
1 files changed, 19 insertions, 11 deletions
diff --git a/lorry.gzip-importer b/lorry.gzip-importer
index 8bc18ed..8d482b7 100755
--- a/lorry.gzip-importer
+++ b/lorry.gzip-importer
@@ -9,19 +9,11 @@ import struct
import sys
-if len(sys.argv) < 2:
- print('usage:', sys.argv[0], '<gzipfile>...')
- sys.exit(1)
-
branch_name = 'master'
branch_ref = 'refs/heads/%s' % branch_name
committer_name = 'Lorry Gzip Importer'
committer_email = 'lorry-gzip-importer@lorry'
-fast_import = os.popen('git fast-import --quiet', 'w')
-def printlines(list):
- for str in list:
- fast_import.write(str + "\n")
# The size of a gzip file is stored in the last 4 bytes
def uncompressedsize(filename):
@@ -29,7 +21,11 @@ def uncompressedsize(filename):
f.seek(-4, 2)
return struct.unpack('I', f.read(4))[0]
-for zipfile in sys.argv[1:]:
+
+def export(zipfile, fast_import):
+ def printlines(list):
+ for str in list:
+ fast_import.write(str + "\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.
@@ -57,5 +53,17 @@ for zipfile in sys.argv[1:]:
'from ' + branch_ref, 'tagger ' + committer, \
'data <<EOM', 'Package ' + zipfile, 'EOM', ''))
-if fast_import.close():
- sys.exit(1)
+
+def main():
+ if len(sys.argv) < 2:
+ print('usage:', sys.argv[0], '<gzipfile>...')
+ sys.exit(1)
+
+ fast_import = os.popen('git fast-import --quiet', 'w')
+ for zipfile in sys.argv[1:]:
+ export(zipfile, fast_import)
+ if fast_import.close():
+ sys.exit(1)
+
+
+main()