From e0c4fd1e416c60ebc07f441f7e6ff7b7feec9e4e Mon Sep 17 00:00:00 2001 From: Benjamin Drung Date: Fri, 8 Jan 2010 19:06:09 +0100 Subject: * moz-version: - Add parameter for converting Mozilla versions into Debian upstream versions and the other way round. - update man/moz-version.1 - update src/moz_version.py - update src/moz-version --- debian/changelog | 8 ++++++- man/moz-version.1 | 19 ++++++++++++----- src/moz-version | 61 ++++++++++++++++++++++++++++++++++++++++-------------- src/moz_version.py | 33 +++++++++++++++++++++++++---- 4 files changed, 95 insertions(+), 26 deletions(-) diff --git a/debian/changelog b/debian/changelog index 6fbe494..55f2214 100644 --- a/debian/changelog +++ b/debian/changelog @@ -62,6 +62,12 @@ mozilla-devscripts (0.19) UNRELEASED; urgency=low - add --install-dir parameter to install-xpi - update man/install-xpi.1 - update src/install-xpi + * moz-version: + - Add parameter for converting Mozilla versions into Debian upstream + versions and the other way round. + - update man/moz-version.1 + - update src/moz_version.py + - update src/moz-version * packaging: - add homepage field - update debian/control @@ -74,7 +80,7 @@ mozilla-devscripts (0.19) UNRELEASED; urgency=low - update src/dh_xul-ext - update debian/control - -- Benjamin Drung Fri, 08 Jan 2010 02:07:43 +0100 + -- Benjamin Drung Fri, 08 Jan 2010 19:04:37 +0100 mozilla-devscripts (0.18) unstable; urgency=low diff --git a/man/moz-version.1 b/man/moz-version.1 index bd820fd..7eb68d6 100644 --- a/man/moz-version.1 +++ b/man/moz-version.1 @@ -23,18 +23,27 @@ moz-version \- version format handling tool .SH SYNOPSIS .B moz-version [\fIoptions\fP] -\fI--compare ver1 comparator ver2\fR +\fIaction\fR .SH DESCRIPTION .B moz-version is a tool for working with version string from the Mozilla suite. -Currently it can only compare versions. +It can compare Mozilla versions, convert Mozilla version into Debian upstream +version and the other way round. .SH ACTIONS .TP -.B \-\-compare \fIver1 comparator ver2\fP +\fB\-c\fR, \fB\-\-compare\fR \fIversion1 comparator version2\fP Compare version numbers, where \fIcomparator\fP is a binary operator. \fBmoz-version\fP returns success (zero result) if the specified condition is -satisfied, and failure (nonzero result) otherwise. The comparator must be one of -\fBlt le eq ne ge gt\fP. +satisfied, and failure (non-zero result) otherwise. The comparator must be one +of \fBlt le eq ne ge gt\fP. +.TP +\fB\-d\fR, \fB\-\-to\-deb\fR \fIversion\fP +Converts Mozilla \fIversion\fP into a Debian upstream version. For a full +Debian version you have to add a revision. +.TP +\fB\-m\fR, \fB\-\-to\-moz\fR \fIversion\fP +Converts Debian \fIversion\fP into a Mozilla version. The Debian revision and +the epoch will be stripped away. .SH OPTIONS .TP \fB\-h\fR, \fB\-\-help\fR diff --git a/src/moz-version b/src/moz-version index ddf4ac5..cea49b7 100755 --- a/src/moz-version +++ b/src/moz-version @@ -21,9 +21,10 @@ # THE SOFTWARE. import getopt +import os import sys -from moz_version import compare_versions +from moz_version import compare_versions, convert_debian_to_moz_version, convert_moz_to_debian_version # error codes COMMAND_LINE_SYNTAX_ERROR = 2 @@ -64,35 +65,48 @@ def moz_version_compare(version1, comparator, version2, silent=False, verbose=Fa def usage(output): - print >> output, """Usage: %s --compare version1 comparator version2 + name = os.path.basename(sys.argv[0]) + print >> output, """Usage: %s [options] action - -h, --help display this help and exit - -s, --silent do not print anything and die silent on errors - -v, --verbose print more information +Actions: + -c, --compare version1 comparator version2 + compare both Mozilla version numbers + comparator must be one of %s + -d, --to-deb version converts Mozilla into a Debian upstream version + -m, --to-moz version converts Debian into a Mozilla version -comparator must be one of %s.""" % (sys.argv[0], ", ".join(comparators)) +Options: + -h, --help display this help and exit + -s, --silent do not print anything and die silent on errors + -v, --verbose print more information + +See %s(1) for more info.""" % (name, ", ".join(comparators), name) if __name__ == "__main__": try: - long_opts = ["compare", "help", "silent", "verbose"] - opts, args = getopt.gnu_getopt(sys.argv[1:], "chsv", long_opts) + long_opts = ["compare", "help", "silent", "to-deb", "to-moz", "verbose"] + opts, args = getopt.gnu_getopt(sys.argv[1:], "cdhmsv", long_opts) except getopt.GetoptError, e: # print help information and exit: print >> sys.stderr, str(e) # will print something like "option -a not recognized" usage(sys.stderr) sys.exit(COMMAND_LINE_SYNTAX_ERROR) - compare = False + actions = set() silent = False verbose = False for o, a in opts: if o in ("-c", "--compare"): - compare = True + actions.add("compare") + elif o in ("-d", "--to-deb"): + actions.add("to-deb") elif o in ("-h", "--help"): usage(sys.stdout) sys.exit() + elif o in ("-m", "--to-moz"): + actions.add("to-moz") elif o in ("-s", "--silent"): silent = True elif o in ("-v", "--verbose"): @@ -100,7 +114,15 @@ if __name__ == "__main__": else: assert False, "unhandled option" - if compare: + if len(actions) != 1: + if not silent: + print >> sys.stderr, "E: You must specify an action." + usage(sys.stderr) + sys.exit(COMMAND_LINE_SYNTAX_ERROR) + + action = actions.pop() + + if action == "compare": if len(args) != 3: if not silent: usage(sys.stderr) @@ -113,8 +135,15 @@ if __name__ == "__main__": if verbose: print "I: Compare expression false." sys.exit(1) - else: - if not silent: - print >> sys.stderr, "E: You should specify the command --compare." - usage(sys.stderr) - sys.exit(COMMAND_LINE_SYNTAX_ERROR) + elif action == "to-deb": + if len(args) != 1: + if not silent: + print >> sys.stderr, "E: The action --to-deb takes exactly one argument." + sys.exit(COMMAND_LINE_SYNTAX_ERROR) + print convert_moz_to_debian_version(args[0], 0, verbose) + elif action == "to-moz": + if len(args) != 1: + if not silent: + print >> sys.stderr, "E: The action --to-moz takes exactly one argument." + sys.exit(COMMAND_LINE_SYNTAX_ERROR) + print convert_debian_to_moz_version(args[0], verbose) diff --git a/src/moz_version.py b/src/moz_version.py index 832d65f..24c4680 100644 --- a/src/moz_version.py +++ b/src/moz_version.py @@ -124,6 +124,17 @@ def extract_upstream_version(debian_version): del parts[-1] upstream_version = '-'.join(parts) + # remove epoch + parts = upstream_version.split(':') + if len(parts) > 1: + del parts[0] + upstream_version = ':'.join(parts) + + return upstream_version + +def convert_debian_to_moz_version(debian_version, verbose=False): + upstream_version = extract_upstream_version(debian_version) + # compatibility: strip +nobinonly and +build parts = upstream_version.split('+') if len(parts) > 1 and parts[-1] == "nobinonly": @@ -132,9 +143,23 @@ def extract_upstream_version(debian_version): del parts[-1] upstream_version = '+'.join(parts) - return upstream_version - -def convert_debian_to_moz_version(debian_version, verbose=False): - upstream_version = extract_upstream_version(debian_version) moz_version = upstream_version.replace("~", "") return moz_version + +def convert_moz_to_debian_version(moz_version, epoch=0, verbose=False): + parts = decode_version(moz_version, verbose) + # tranform parts + for i in xrange(len(parts)): + (number_a, string_b, number_c, string_d) = parts[i] + part = "" + if string_d != "": + part = "~" + string_d + if number_c != 0 or string_d != "": + part = str(number_c) + part + if string_b != "": + part = "~" + string_b + part + parts[i] = str(number_a) + part + debian_version = ".".join(parts) + if epoch != 0: + debian_version = str(epoch) + ":" + debian_version + return debian_version -- cgit v1.2.3