From 2234eae5baddeee7f41b41b40cf5cfb5d61436a1 Mon Sep 17 00:00:00 2001 From: Ben Hutchings Date: Mon, 4 May 2020 19:28:48 +0100 Subject: lorry.{g,}zip-importer: Only import modules and classes into module scope Currently these scripts import a bunch of functions into module scope, which is a bit confusing. Change them to access functions through their enclosing module names. In lorry.gzip-importer, hexversion and stderr weren't used at all. --- lorry.gzip-importer | 26 +++++++++++++------------- lorry.zip-importer | 27 ++++++++++++++------------- 2 files changed, 27 insertions(+), 26 deletions(-) diff --git a/lorry.gzip-importer b/lorry.gzip-importer index 4248f8b..8bc18ed 100755 --- a/lorry.gzip-importer +++ b/lorry.gzip-importer @@ -2,23 +2,23 @@ # gzip archive frontend for git-fast-import -from os import popen, path -from os.path import splitext -from os.path import getmtime -from sys import argv, exit, hexversion, stderr from gzip import GzipFile +import os +import os.path import struct +import sys -if len(argv) < 2: - print('usage:', argv[0], '...') - exit(1) + +if len(sys.argv) < 2: + print('usage:', sys.argv[0], '...') + 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 = popen('git fast-import --quiet', 'w') +fast_import = os.popen('git fast-import --quiet', 'w') def printlines(list): for str in list: fast_import.write(str + "\n") @@ -29,11 +29,11 @@ def uncompressedsize(filename): f.seek(-4, 2) return struct.unpack('I', f.read(4))[0] -for zipfile in argv[1:]: +for zipfile in sys.argv[1:]: # 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 = getmtime (zipfile); + mtime = os.path.getmtime(zipfile); file_size = uncompressedsize (zipfile); zip = GzipFile(zipfile, 'rb') @@ -43,7 +43,7 @@ for zipfile in argv[1:]: committer = committer_name + ' <' + committer_email + '> %d +0000' % \ mtime - zipfile_basename = path.basename(zipfile) + zipfile_basename = os.path.basename(zipfile) printlines(('commit ' + branch_ref, 'committer ' + committer, \ 'data <...') - exit(1) + +if len(sys.argv) < 2: + print('usage:', sys.argv[0], '...') + sys.exit(1) branch_name = 'master' branch_ref = 'refs/heads/%s' % branch_name committer_name = 'Lorry Zip Importer' committer_email = 'lorry-zip-importer@lorry' -fast_import = popen('git fast-import --quiet', 'w') +fast_import = os.popen('git fast-import --quiet', 'w') def printlines(list): for str in list: fast_import.write(str + "\n") -for zipfile in argv[1:]: +for zipfile in sys.argv[1:]: commit_time = 0 next_mark = 1 common_prefix = None @@ -59,9 +60,9 @@ for zipfile in argv[1:]: fast_import.write(zip.read(name) + "\n") committer = committer_name + ' <' + committer_email + '> %d +0000' % \ - mktime(commit_time + (0, 0, 0)) + time.mktime(commit_time + (0, 0, 0)) - zipfile_basename = path.basename(zipfile) + zipfile_basename = os.path.basename(zipfile) printlines(('commit ' + branch_ref, 'committer ' + committer, \ 'data <