From 8b5a955077bb7fb652fb2e6082c45b845ba58541 Mon Sep 17 00:00:00 2001 From: Jesse Keating Date: Fri, 20 Aug 2010 14:33:52 -0700 Subject: Move commit out of the PackageModule object. Outside of clog, there is no reason why commit should need data from the spec file. This fixes a bug when marking a package as dead so that one can commit again. Ticket #54 --- src/fedpkg.py | 3 +- src/pyfedpkg/__init__.py | 76 ++++++++++++++++++++++++++---------------------- 2 files changed, 42 insertions(+), 37 deletions(-) (limited to 'src') diff --git a/src/fedpkg.py b/src/fedpkg.py index 0a60b64..187f517 100755 --- a/src/fedpkg.py +++ b/src/fedpkg.py @@ -431,8 +431,7 @@ def clone(args): def commit(args): try: - mymodule = pyfedpkg.PackageModule(args.path) - mymodule.commit(args.message, args.file, args.files) + pyfedpkg.commit(args.path, args.message, args.file, args.files) except pyfedpkg.FedpkgError, e: log.error('Could not commit: %s' % e) sys.exit(1) diff --git a/src/pyfedpkg/__init__.py b/src/pyfedpkg/__init__.py index ae3db2c..a9fcc0d 100644 --- a/src/pyfedpkg/__init__.py +++ b/src/pyfedpkg/__init__.py @@ -423,6 +423,47 @@ def clone_with_dirs(module, user, path=None): # successful. return 0 +def commit(path=None, message=None, file=None, files=[]): + """Commit changes to a module (optionally found at path) + + Can take a message to use as the commit message + + a file to find the commit message within + + and a list of files to commit. + + Requires the caller be a real tty or a message passed. + + Logs the output and returns nothing. + + """ + + # First lets see if we got a message or we're on a real tty: + if not sys.stdin.isatty(): + if not message or not file: + raise FedpkgError('Must have a commit message or be on a real tty.') + + # Deal with path + curdir = os.getcwd() + if path: + os.chdir(path) + + # construct the git command + # We do this via subprocess because the git module is terrible. + cmd = ['git', 'commit'] + if message: + cmd.extend(['-m', message]) + elif file: + cmd.extend(['-F', os.path.abspath(file)]) + if not files: + cmd.append('-a') + else: + cmd.extend(files) + # make it so + _run_command(cmd) + os.chdir(curdir) + return + def get_latest_commit(module): """Discover the latest commit has for a given module and return it""" @@ -1041,41 +1082,6 @@ class PackageModule: clogfile.writelines(cloglines) return - def commit(self, message=None, file=None, files=[]): - """Commit changes to a module. - - Can take a message to use as the commit message - - a file to find the commit message within - - and a list of files to commit. - - Requires the caller be a real tty or a message passed. - - Logs the output and returns nothing. - - """ - - # First lets see if we got a message or we're on a real tty: - if not sys.stdin.isatty(): - if not message or not file: - raise FedpkgError('Must have a commit message or be on a real tty.') - - # construct the git command - # We do this via subprocess because the git module is terrible. - cmd = ['git', 'commit'] - if message: - cmd.extend(['-m', message]) - elif file: - cmd.extend(['-F', os.path.abspath(file)]) - if not files: - cmd.append('-a') - else: - cmd.extend(files) - # make it so - _run_command(cmd) - return - def compile(self, arch=None, short=False): """Run rpm -bc on a module -- cgit