From 14cbfc425f114dc376c0512c59d816595d0dfb4e Mon Sep 17 00:00:00 2001 From: Jesse Keating Date: Tue, 6 Jul 2010 16:12:18 -0700 Subject: Rename source uploading function This way we can reuse it for new-sources as well as just plain upload. The difference is new-sources replaces current content, upload just adds additional content. --- src/fedpkg.py | 2 +- src/pyfedpkg/__init__.py | 18 ++++++++++++++---- 2 files changed, 15 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/fedpkg.py b/src/fedpkg.py index a86bd37..2c8acac 100755 --- a/src/fedpkg.py +++ b/src/fedpkg.py @@ -533,7 +533,7 @@ def new(args): def new_sources(args): try: mymodule = pyfedpkg.PackageModule(args.path) - mymodule.new_sources(args.files) + mymodule.upload(args.files, replace=True) except pyfedpkg.FedpkgError, e: log.error('Could not upload new sources: %s' % e) sys.exit(1) diff --git a/src/pyfedpkg/__init__.py b/src/pyfedpkg/__init__.py index e958722..3e64c87 100644 --- a/src/pyfedpkg/__init__.py +++ b/src/pyfedpkg/__init__.py @@ -1099,14 +1099,21 @@ class PackageModule: _run_command(cmd) return - def new_sources(self, files): - """Replace source file(s) in the lookaside cache""" + def upload(self, files, replace=False): + """Upload source file(s) in the lookaside cache + + Can optionally replace the existing tracked sources + + """ oldpath = os.getcwd() os.chdir(self.path) - # Overwrite existing sources file: - sources_file = open('sources', 'w') + # Decide to overwrite or append to sources: + if replace: + sources_file = open('sources', 'w') + else: + sources_file = open('sources', 'a') # Will add new sources to .gitignore if they are not already there. gitignore = GitIgnore(os.path.join(self.path, '.gitignore')) @@ -1117,6 +1124,9 @@ class PackageModule: file_hash = _hash_file(f, self.lookasidehash) log.info("Uploading: %s %s" % (file_hash, f)) file_basename = os.path.basename(f) + # When we are in append mode, this /may/ trash the file if the + # file doesn't end in a new line. Insert some code here to + # prevent that. sources_file.write("%s %s\n" % (file_hash, file_basename)) # Add this file to .gitignore if it's not already there: -- cgit