diff options
author | Jesse Keating <jkeating@redhat.com> | 2010-09-20 14:33:41 -0700 |
---|---|---|
committer | Jesse Keating <jkeating@redhat.com> | 2010-09-20 14:33:41 -0700 |
commit | dcdcc603823c45bf7cb223ceece463d677e03cc0 (patch) | |
tree | 22192ebadbfbf2285e11e76ae23b605693f14556 | |
parent | cc2f096d584358ca7010c509ef37fe966754afc5 (diff) | |
parent | bfbb12faf3124c8f4a4729dd55ac13c2dcb98f8f (diff) | |
download | fedora-packager-dcdcc603823c45bf7cb223ceece463d677e03cc0.tar.gz fedora-packager-dcdcc603823c45bf7cb223ceece463d677e03cc0.tar.xz fedora-packager-dcdcc603823c45bf7cb223ceece463d677e03cc0.zip |
Merge branch 'jochen' into bash
Conflicts:
src/fedpkg.bash
-rw-r--r-- | src/fedpkg.bash | 15 | ||||
-rwxr-xr-x | src/fedpkg.py | 112 | ||||
-rw-r--r-- | src/pyfedpkg/__init__.py | 159 |
3 files changed, 234 insertions, 52 deletions
diff --git a/src/fedpkg.bash b/src/fedpkg.bash index f1bf36c..c4e3a81 100644 --- a/src/fedpkg.bash +++ b/src/fedpkg.bash @@ -36,8 +36,8 @@ _fedpkg() local options="--help -v -q" local options_value="--user --path" local commands="build chain-build ci clean clog clone co commit compile diff gimmespec giturl help \ - import install lint local mockbuild new new-sources patch prep push scratch-build sources srpm \ - switch-branch tag-request unused-patches update upload verrel" + import install lint local mockbuild new new-sources patch prep pull push scratch-build sources srpm \ + switch-branch tag tag-request unused-patches update upload verrel" # parse main options and get command @@ -113,7 +113,7 @@ _fedpkg() after="package" ;; commit|ci) - options="--push" + options="--push --clog --tag" options_string="--message" options_file="--file" after="file" @@ -133,6 +133,9 @@ _fedpkg() options_branch="--branch" after="srpm" ;; + lint) + options="--info" + ;; local) options="--md5" options_arch="--arch" @@ -153,6 +156,12 @@ _fedpkg() sources) options_dir="--outdir" ;; + tag) + options="--clog --force --list --delete" + options_string="--message -m" + options_file="--file -F" + after_more=true + ;; srpm) options="--md5" ;; diff --git a/src/fedpkg.py b/src/fedpkg.py index 4f707b8..48fb1d4 100755 --- a/src/fedpkg.py +++ b/src/fedpkg.py @@ -440,11 +440,29 @@ def clone(args): sys.exit(1) def commit(args): + mymodule = None + if args.clog: + try: + mymodule = pyfedpkg.PackageModule(args.path) + mymodule.clog() + except pyfedpkg.FedpkgError, e: + log.error('coult not create clog: %s' % e) + sys.exit(1) + args.file = os.path.abspath(self.path.join(args.path, 'clog')) try: pyfedpkg.commit(args.path, args.message, args.file, args.files) except pyfedpkg.FedpkgError, e: log.error('Could not commit: %s' % e) sys.exit(1) + if args.tag: + try: + if not mymodule: + mymodule = pyfedpkg.PackageModule(args.path) + tagname = mymodule.nvr() + pyfedpkg.add_tag(tagname, True, args.message, args.file) + except pyfedpkg.FedpkgError, e: + log.error('Coult not create a tag: %s' % e) + sys.exit(1) if args.push: push(args) @@ -464,8 +482,7 @@ def compile(args): def diff(args): try: - mymodule = pyfedpkg.PackageModule(args.path) - return mymodule.diff(args.cached, args.files) + return pyfedpkg.diff(args.path, args.cached, args.files) except pyfedpkg.FedpkgError, e: log.error('Could not diff: %s' % e) sys.exit(1) @@ -528,7 +545,7 @@ def install(args): def lint(args): try: mymodule = pyfedpkg.PackageModule(args.path) - return mymodule.lint() + return mymodule.lint(info) except pyfedpkg.FedpkgError, e: log.error('Could not run rpmlint: %s' % e) sys.exit(1) @@ -598,10 +615,16 @@ def prep(args): log.error('Could not prep: %s' % e) sys.exit(1) +def pull(args): + try: + pyfedpkg.pull(path=args.path) + except pyfedpkg.FedpkgError, e: + log.error('Could not push: %s' % e) + sys.exit(1) + def push(args): try: - mymodule = pyfedpkg.PackageModule(args.path) - mymodule.push() + pyfedpkg.push(path=args.path) except pyfedpkg.FedpkgError, e: log.error('Could not push: %s' % e) sys.exit(1) @@ -652,6 +675,35 @@ def switch_branch(args): print('Locals:\n%s\nRemotes:\n %s' % ('\n'.join(locals), '\n '.join(remotes))) +def tag(args): + if args.list: + try: + pyfedpkg.list_tag(args.tag) + except pyfedpkg.FedpkgError, e: + log.error('Could not create a list of the tag: %s' % e) + sys.exit(1) + elif args.delete: + try: + pyfedpkg.delete_tag(args.tag, args.path) + except pyfedpkg.FedpkgError, e: + log.error('Coult not delete tag: %s' % e) + sys.exit(1) + else: + filename = args.file + tagname = args.tag + try: + if not tagname or args.clog: + mymodule = pyfedpkg.PackageModule(args.path) + if not tagname: + tagname = mymodule.nvr + if clog: + mymodule.clog() + filename = 'clog' + pyfedpkg.add_tag(tagname, args.force, args.message, filename) + except pyfedpkg.FedpkgError, e: + log.error('Coult not create a tag: %s' % e) + sys.exit(1) + def tagrequest(args): # not implimented log.warning('Not implimented yet, got %s' % args) @@ -871,10 +923,17 @@ packages will be built sequentially. conflict_handler = 'resolve', help = 'Alias for clone') parser_co.set_defaults(command = clone) - # commit stuff parser_commit = subparsers.add_parser('commit', help = 'Commit changes') + parser_commit.add_argument('-c', '--clog', + default = False, + action = 'store_true', + help = 'Generate the commit message from the %Changelog section') + parser_commit.add_argument('-t', '--tag', + default = False, + action = 'store_true', + help = 'Create a tag for this commit') parser_commit.add_argument('-m', '--message', default = None, help = 'Use the given <msg> as the commit message') @@ -955,6 +1014,10 @@ packages will be built sequentially. # rpmlint target parser_lint = subparsers.add_parser('lint', help = 'Run rpmlint against local build output') + parser_lint.add_argument('--info', '-i', + default = False, + action = 'store_true', + help = 'Display explanations for reported messages') parser_lint.set_defaults(command = lint) # Build locally @@ -996,6 +1059,12 @@ packages will be built sequentially. parser_prep.add_argument('--arch', help = 'Prep for a specific arch') parser_prep.set_defaults(command = prep) + # Pull stuff + parser_pull = subparsers.add_parser('pull', + help = 'Pull changes from remote repository and update working copy') + parser_pull.set_defaults(command = pull) + + # Push stuff parser_push = subparsers.add_parser('push', help = 'Push changes to remote repository') @@ -1036,6 +1105,37 @@ packages will be built sequentially. action = 'store_true') parser_switchbranch.set_defaults(command = switch_branch) + # tag stuff + parser_tag = subparsers.add_parser('tag', + help = 'Management of git tags') + parser_tag.add_argument('-f', '--force', + default = False, + action = 'store_true', + help = 'Force the creation of the tag') + parser_tag.add_argument('-m', '--message', + default = None, + help = 'Use the given <msg> as the tag message') + parser_tag.add_argument('-c', '--clog', + default = False, + action = 'store_true', + help = 'Generate the tag message from the spec changelog section') + parser_tag.add_argument('-F', '--file', + default = None, + help = 'Take the tag message from the given file') + parser_tag.add_argument('-l', '--list', + default = False, + action = 'store_true', + help = 'List all tags with a given pattern, or all if not pattern is given') + parser_tag.add_argument('-d', '--delete', + default = False, + action = 'store_true', + help = 'Delete a tag') + parser_tag.add_argument('tag', + nargs = '?', + default = None, + help = 'Name of the tag') + parser_tag.set_defaults(command = tag) + # Create a releng tag request parser_tagrequest = subparsers.add_parser('tag-request', help = 'Submit last build as a releng tag request') diff --git a/src/pyfedpkg/__init__.py b/src/pyfedpkg/__init__.py index 5991fce..df788cb 100644 --- a/src/pyfedpkg/__init__.py +++ b/src/pyfedpkg/__init__.py @@ -311,6 +311,33 @@ def _srpmdetails(srpm): return((name, files, uploadfiles)) +def add_tag(tagname, force=False, message=None, file=None): + """Add a git tag to the repository + + Takes a tagname + + Optionally can force the tag, include a message, + or reference a message file. + + Runs the tag command and returns nothing + + """ + + cmd = ['git', 'tag'] + cmd.extend(['-a']) + # force tag creation, if tag already exists + if force: + cmd.extend(['-f']) + # Description for the tag + if message: + cmd.extend(['-m', message]) + elif file: + cmd.extend(['-F', os.path.abspath(file)]) + cmd.append(tagname) + # make it so + _run_command(cmd) + log.info('Tag \'%s\' was created' % tagname) + def clean(dry=False, useignore=True): """Clean a module checkout of untracked files. @@ -331,7 +358,7 @@ def clean(dry=False, useignore=True): # Run it! _run_command(cmd) return - + def clone(module, user, path=None, branch=None, bare_dir=None): """Clone a repo, optionally check out a specific branch. @@ -479,6 +506,43 @@ def commit(path=None, message=None, file=None, files=[]): _run_command(cmd, cwd=path) return +def delete_tag(tagname, path=None): + """Delete a git tag from the repository found at optional path""" + + if not path: + path = os.getcwd() + cmd = ['git', 'tag', '-d', tagname] + _run_command(cmd, cwd=path) + log.info ('Tag %s was deleted' % tagname) + +def diff(path, cached=False, files=[]): + """Excute a git diff + + optionally diff the cached or staged changes + + Takes an optional list of files to diff relative to the module base + directory + + Logs the output and returns nothing + + """ + + # Things work better if we're in our module directory + oldpath = os.getcwd() + os.chdir(path) + # build up the command + cmd = ['git', 'diff'] + if cached: + cmd.append('--cached') + if files: + cmd.extend(files) + + # Run it! + _run_command(cmd) + # popd + os.chdir(oldpath) + return + def get_latest_commit(module): """Discover the latest commit has for a given module and return it""" @@ -582,6 +646,20 @@ def import_srpm(srpm, path=None): os.chdir(oldpath) return(uploadfiles) +def list_tag(tagname=None): + """Create a list of all tags in the repository which match a given tagname. + + if tagname == '*' all tags will been shown. + + """ + + cmd = ['git', 'tag'] + cmd.extend(['-l']) + if tagname != '*': + cmd.extend([tagname]) + # make it so + _run_command(cmd) + def new(path=None): """Return changes in a repo since the last tag""" @@ -598,6 +676,24 @@ def new(path=None): log.debug('Diffing from tag %s' % tag) return repo.git.diff('-M', tag) +def pull(path=None): + """Pull changes from the main repository using optional path""" + + if not path: + path = os.getcwd() + cmd = ['git', 'pull'] + _run_command(cmd, cwd=path) + return + +def push(path=None): + """Push changes to the main repository using optional path""" + + if not path: + path = os.getcwd() + cmd = ['git', 'push'] + _run_command(cmd, cwd=path) + return + def sources(path, outdir=None): """Download source files""" @@ -799,7 +895,6 @@ class Lookaside(object): raise FedpkgError('Lookaside failure. Check your cert.') curl.close() - class GitIgnore(object): """ Smaller wrapper for managing a .gitignore file and it's entries. """ @@ -966,7 +1061,7 @@ class PackageModule: self.hashtype = 'sha256' if self.branch.startswith('el5') or self.branch.startswith('el4'): self.hashtype = 'md5' - + def build(self, skip_tag=False, scratch=False, background=False, url=None, chain=None): """Initiate a build of the module. Available options are: @@ -1139,35 +1234,6 @@ class PackageModule: _run_command(cmd, shell=True) return - def diff(self, cached=False, files=[]): - """Excute a git diff - - optionally diff the cached or staged changes - - Takes an optional list of files to diff reletive to the module base - directory - - Logs the output and returns nothing - - """ - - # Things work better if we're in our module directory - oldpath = os.getcwd() - os.chdir(self.path) - - # build up the command - cmd = ['git', 'diff'] - if cached: - cmd.append('--cached') - if files: - cmd.extend(files) - - # Run it! - _run_command(cmd) - # popd - os.chdir(oldpath) - return - def getver(self): """Return the version-release of a package module.""" @@ -1186,6 +1252,10 @@ class PackageModule: # Get just the output, then split it by space, grab the first return output[0].split()[0] + def getnvr(self): + """Return Name-Version-Release of a package""" + return self.nvr + def getrel(self): """Return the version-release of a package module.""" @@ -1207,13 +1277,20 @@ class PackageModule: def gimmespec(self): """Return the name of a specfile within a package module""" + deadpackage = False + # Get a list of files in the path we're looking at files = os.listdir(self.path) # Search the files for the first one that ends with ".spec" for f in files: if f.endswith('.spec'): return f - raise FedpkgError('No spec file found.') + if f == 'dead.package': + deadpackage = True + if deadpackage: + raise FedpkgError('No spec file found. This package is retired') + else: + raise FedpkgError('No spec file found. Please import a new package') def giturl(self): """Return the git url that would be used for building""" @@ -1328,7 +1405,7 @@ class PackageModule: _run_command(cmd, shell=True) return - def lint(self): + def lint(self, info=False): """Run rpmlint over a built srpm Log the output and returns nothing @@ -1347,7 +1424,10 @@ class PackageModule: rpms.extend([os.path.join(self.path, arch, file) for file in os.listdir(os.path.join(self.path, arch)) if file.endswith('.rpm')]) - cmd = ['rpmlint', os.path.join(self.path, srpm)] + cmd = ['rpmlint'] + if info: + cmd.extend(['-i']) + cmd.extend([os.path.join(self.path, srpm)]) cmd.extend(rpms) # Run the command _run_command(cmd, shell=True) @@ -1500,14 +1580,7 @@ class PackageModule: # Run the command _run_command(cmd, shell=True) return - - def push(self): - """Push changes to the main repository""" - - cmd = ['git', 'push'] - _run_command(cmd) - return - + def srpm(self, hashtype=None): """Create an srpm using hashtype from content in the module |