diff options
author | Jun Wang <junbill.wang@samsung.com> | 2016-03-09 18:44:48 +0800 |
---|---|---|
committer | Jun Wang <junbill.wang@samsung.com> | 2016-03-09 18:44:48 +0800 |
commit | b8b2060a6f941eb1124f313d306d3fff7269aa10 (patch) | |
tree | 0e3d17e481110cc71c23ebcb1a4740872eea5e76 /gbp/rpm | |
parent | d20f0d6411c9bf719b2838445ed3f7b886acef15 (diff) | |
download | git-buildpackage-b8b2060a6f941eb1124f313d306d3fff7269aa10.tar.gz git-buildpackage-b8b2060a6f941eb1124f313d306d3fff7269aa10.tar.bz2 git-buildpackage-b8b2060a6f941eb1124f313d306d3fff7269aa10.zip |
add compose_version_str function
Change-Id: Id1944627b2ec5cf450c978f77002c72d46206572
Diffstat (limited to 'gbp/rpm')
-rw-r--r-- | gbp/rpm/__init__.py | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/gbp/rpm/__init__.py b/gbp/rpm/__init__.py index 4c5c22bf..d47fb302 100644 --- a/gbp/rpm/__init__.py +++ b/gbp/rpm/__init__.py @@ -901,5 +901,34 @@ def string_to_int(val_str): else: return int(val_str) - +def compose_version_str(evr): + """ + Compose a full version string from individual "version components", + i.e. epoch, version and release + + @param evr: dict of version components + @type evr: C{dict} of C{str} + @return: full version + @rtype: C{str} + + >>> compose_version_str({'epoch': '', 'upstreamversion': '1.0'}) + '1.0' + >>> compose_version_str({'epoch': '2', 'upstreamversion': '1.0', 'release': None}) + '2:1.0' + >>> compose_version_str({'epoch': None, 'upstreamversion': '1', 'release': '0'}) + '1-0' + >>> compose_version_str({'epoch': '2', 'upstreamversion': '1.0', 'release': '2.3'}) + '2:1.0-2.3' + >>> compose_version_str({'epoch': '2', 'upstreamversion': '', 'release': '2.3'}) + """ + if 'upstreamversion' in evr and evr['upstreamversion']: + version = "" + if 'epoch' in evr and evr['epoch']: + version += "%s:" % evr['epoch'] + version += evr['upstreamversion'] + if 'release' in evr and evr['release']: + version += "-%s" % evr['release'] + if version: + return version + return None # vim:et:ts=4:sw=4:et:sts=4:ai:set list listchars=tab\:»·,trail\:·: |