summaryrefslogtreecommitdiffstats
path: root/src/pyfedpkg
diff options
context:
space:
mode:
authorJesse Keating <jkeating@redhat.com>2010-06-23 21:53:30 -0700
committerJesse Keating <jkeating@redhat.com>2010-06-23 21:53:30 -0700
commitd36e9ea5bc55d189735ef9f55433ffff5b52550a (patch)
tree15f30614e4a1d6877322743dcdfe619c1c25c680 /src/pyfedpkg
parentde54e4350bec675ad9ded1dc745aae3c5887de1a (diff)
downloadfedora-packager-d36e9ea5bc55d189735ef9f55433ffff5b52550a.tar.gz
fedora-packager-d36e9ea5bc55d189735ef9f55433ffff5b52550a.tar.xz
fedora-packager-d36e9ea5bc55d189735ef9f55433ffff5b52550a.zip
Move import_srpm out of the class
This is so that we can use it before we have a full fledged module to deal with, like creating something local to play with.
Diffstat (limited to 'src/pyfedpkg')
-rw-r--r--src/pyfedpkg/__init__.py160
1 files changed, 79 insertions, 81 deletions
diff --git a/src/pyfedpkg/__init__.py b/src/pyfedpkg/__init__.py
index bf9481f..a42bc51 100644
--- a/src/pyfedpkg/__init__.py
+++ b/src/pyfedpkg/__init__.py
@@ -251,6 +251,85 @@ def get_latest_commit(module):
# Return the hash sum
return output.split()[0]
+def import_srpm(repo, srpm, path=os.getcwd()):
+ """Import the contents of an srpm into a repo.
+
+ repo: a git repo object to use for the import
+
+ srpm: File to import contents from
+
+ path: optional path to work in, defaults to cwd.
+
+ This function will add/remove content to match the srpm,
+
+ upload new files to the lookaside, and stage the changes.
+
+ Returns a list of files to upload.
+
+ """
+
+ # see if the srpm even exists
+ srpm = os.path.abspath(srpm)
+ if not os.path.exists(srpm):
+ raise FedpkgError('File not found.')
+ # bail if we're dirty
+ if repo.is_dirty():
+ raise FedpkgError('There are uncommitted changes in your repo')
+ # Get the details of the srpm
+ name, files, uploadfiles = _srpmdetails(srpm)
+
+ # Need a way to make sure the srpm name matches the repo some how.
+
+ # Get a list of files we're currently tracking
+ ourfiles = repo.git.ls_files().split()
+ # Trim out sources and .gitignore
+ try:
+ ourfiles.remove('.gitignore')
+ ourfiles.remove('sources')
+ except ValueError:
+ pass
+ try:
+ ourfiles.remove('sources')
+ except ValueError:
+ pass
+
+ # Things work better if we're in our module directory
+ oldpath = os.getcwd()
+ os.chdir(path)
+
+ # Look through our files and if it isn't in the new files, remove it.
+ for file in ourfiles:
+ if file not in files:
+ log.info("Removing no longer used file: %s" % file)
+ rv = repo.index.remove([file])
+ os.remove(file)
+
+ # Extract new files
+ cmd = ['rpm2cpio', srpm]
+ # We have to force cpio to copy out (u) because git messes with
+ # timestamps
+ cmd2 = ['cpio', '-iud', '--quiet']
+
+ rpmcall = subprocess.Popen(cmd, stdout=subprocess.PIPE)
+ cpiocall = subprocess.Popen(cmd2, stdin=rpmcall.stdout)
+ output, err = cpiocall.communicate()
+ if output:
+ log.debug(output)
+ if err:
+ os.chdir(oldpath)
+ raise FedpkgError("Got an error from rpm2cpio: %s" % err)
+
+ # And finally add all the files we know about (and our stock files)
+ for file in ('.gitignore', 'sources'):
+ if not os.path.exists(file):
+ # Create the file
+ open(file, 'w').close()
+ files.append(file)
+ rv = repo.index.add(files)
+ # Return to the caller and let them take it from there.
+ os.chdir(oldpath)
+ return(uploadfiles)
+
def new(path=os.getcwd()):
"""Return changes in a repo since the last tag"""
@@ -548,87 +627,6 @@ class PackageModule:
self.kojisession.uploadWrapper(file, path, callback = callback)
return
- def import_srpm(self, srpm):
- """Import the contents of an srpm into a repo.
-
- srpm: File to import contents from
-
- This function will add/remove content to match the srpm,
-
- upload new files to the lookaside, and stage the changes.
-
- Returns nothing or raises.
-
- """
-
-
- # see if the srpm even exists
- srpm = os.path.abspath(srpm)
- if not os.path.exists(srpm):
- raise FedpkgError('File not found.')
- # bail if we're dirty
- if self.repo.is_dirty():
- raise FedpkgError('There are uncommitted changes in your repo')
- # Get the details of the srpm
- name, files, uploadfiles = _srpmdetails(srpm)
-
- # See if our module matches the srpm we're trying to imoprt
- if name != self.module:
- raise FedpkgError('Srpm does not match module')
-
- # Get a list of files we're currently tracking
- ourfiles = self.repo.git.ls_files().split()
- # Trim out sources and .gitignore
- try:
- ourfiles.remove('.gitignore')
- ourfiles.remove('sources')
- except ValueError:
- pass
- try:
- ourfiles.remove('sources')
- except ValueError:
- pass
-
- # Things work better if we're in our module directory
- oldpath = os.getcwd()
- os.chdir(self.path)
-
- # Look through our files and if it isn't in the new files, remove it.
- for file in ourfiles:
- if file not in files:
- log.info("Removing no longer used file: %s" % file)
- rv = self.repo.index.remove([file])
- os.remove(file)
-
- # Extract new files
- cmd = ['rpm2cpio', srpm]
- # We have to force cpio to copy out (u) because git messes with
- # timestamps
- cmd2 = ['cpio', '-iud', '--quiet']
-
- rpmcall = subprocess.Popen(cmd, stdout=subprocess.PIPE)
- cpiocall = subprocess.Popen(cmd2, stdin=rpmcall.stdout)
- output, err = cpiocall.communicate()
- if output:
- log.debug(output)
- if err:
- os.chdir(oldpath)
- raise FedpkgError("Got an error from rpm2cpio: %s" % err)
-
- # now process the upload files
- if uploadfiles:
- self.new_sources(uploadfiles)
- # And finally add all the files we know about (and our stock files)
- for file in ('.gitignore', 'sources'):
- if not os.path.exists(file):
- # Create the file
- open(file, 'w').close()
- files.append(file)
- rv = self.repo.index.add(files)
- # Return to the caller and let them take it from there.
- os.chdir(oldpath)
- return
-
def init_koji(self, user, kojiconfig=None, url=None):
"""Initiate a koji session. Available options are: