diff options
author | Jesse Keating <jkeating@redhat.com> | 2010-07-06 16:12:18 -0700 |
---|---|---|
committer | Jesse Keating <jkeating@redhat.com> | 2010-07-06 16:12:18 -0700 |
commit | 14cbfc425f114dc376c0512c59d816595d0dfb4e (patch) | |
tree | 87b1575b91752b55b611b45391b39e2ee6b467cb | |
parent | 31d33995d14e49ac02e49998f21fdf8ab64af655 (diff) | |
download | fedora-packager-14cbfc425f114dc376c0512c59d816595d0dfb4e.tar.gz fedora-packager-14cbfc425f114dc376c0512c59d816595d0dfb4e.tar.xz fedora-packager-14cbfc425f114dc376c0512c59d816595d0dfb4e.zip |
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.
-rwxr-xr-x | src/fedpkg.py | 2 | ||||
-rw-r--r-- | src/pyfedpkg/__init__.py | 18 |
2 files changed, 15 insertions, 5 deletions
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: |