diff options
author | Benjamin Drung <bdrung@ubuntu.com> | 2010-01-08 19:06:09 +0100 |
---|---|---|
committer | Benjamin Drung <bdrung@ubuntu.com> | 2010-01-08 19:06:09 +0100 |
commit | e0c4fd1e416c60ebc07f441f7e6ff7b7feec9e4e (patch) | |
tree | aa1f120c665c782d4a6e0b60604ad3df0f228ce1 /src/moz-version | |
parent | 4659a9734b357d1918bdd831a3974cbb041cd7a3 (diff) |
* 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
Diffstat (limited to 'src/moz-version')
-rwxr-xr-x | src/moz-version | 61 |
1 files changed, 45 insertions, 16 deletions
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) |