summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJochen Schmitt <Jochen@herr-schmitt.de>2010-09-16 20:05:45 +0200
committerJesse Keating <jkeating@redhat.com>2010-09-20 13:17:14 -0700
commit16a524c980984505914635c9c232366bf5aa27d2 (patch)
treec50169a8cf7b5cd53044726faa7e1651efd4cc43 /src
parent813ad6cee2034615a5571126bbd1c8886d5cfe2e (diff)
downloadfedora-packager-16a524c980984505914635c9c232366bf5aa27d2.zip
fedora-packager-16a524c980984505914635c9c232366bf5aa27d2.tar.gz
fedora-packager-16a524c980984505914635c9c232366bf5aa27d2.tar.xz
Implenentation of a tag command
Hello Jesse, this patch contains a tag command for fedpkg. I have divede the tag function in __init__.py into three functions for add, delete and list tags. All this functions lives outside of the PackageModule class. Best Regards: Jochen Schmitt
Diffstat (limited to 'src')
-rw-r--r--src/fedpkg.bash8
-rwxr-xr-xsrc/fedpkg.py61
-rw-r--r--src/pyfedpkg/__init__.py49
3 files changed, 113 insertions, 5 deletions
diff --git a/src/fedpkg.bash b/src/fedpkg.bash
index aab9ce2..8c81ccc 100644
--- a/src/fedpkg.bash
+++ b/src/fedpkg.bash
@@ -37,7 +37,7 @@ _fedpkg()
local options_value="-u --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"
+ switch-branch tag tag-request unused-patches update upload verrel"
# parse main options and get command
@@ -148,6 +148,12 @@ _fedpkg()
sources)
options_dir="--outdir"
;;
+ tag)
+ options="--clog -c --force -f --list -l --delete -d"
+ 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..0319c70 100755
--- a/src/fedpkg.py
+++ b/src/fedpkg.py
@@ -652,6 +652,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)
+ 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.getnvr()
+ 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,7 +900,6 @@ 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')
@@ -1036,6 +1064,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 = 'Managementz 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 %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..c975afc 100644
--- a/src/pyfedpkg/__init__.py
+++ b/src/pyfedpkg/__init__.py
@@ -311,6 +311,23 @@ def _srpmdetails(srpm):
return((name, files, uploadfiles))
+def add_tag(tagname, force=False, message=None, file=None):
+ """Add a git tag to the repository"""
+ 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 +348,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 +496,18 @@ def commit(path=None, message=None, file=None, files=[]):
_run_command(cmd, cwd=path)
return
+def delete_tag(tagname=None):
+ """Delete a git tag from the repository
+ """
+
+ if not tagname:
+ raise fedpkgError('Please specified a tagname')
+ cmd = ['git', 'tag']
+ cmd.extend(['-d'])
+ cmd.extend(tagname)
+ _run_command(cmd)
+ log.info ('Tag %s was deleted' % ', '.join(delete))
+
def get_latest_commit(module):
"""Discover the latest commit has for a given module and return it"""
@@ -582,6 +611,17 @@ 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 mathe a given pattern.
+ if list == '*' all tags will been shown.
+ """
+ cmd = ['git', 'tag']
+ cmd.extend(['-l'])
+ if not tagname == '*':
+ cmd.extend([tagname])
+ # make it so
+ _run_command(cmd)
+
def new(path=None):
"""Return changes in a repo since the last tag"""
@@ -799,7 +839,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 +1005,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:
@@ -1186,6 +1225,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."""