aboutsummaryrefslogtreecommitdiffstats
path: root/RepSys/command.py
diff options
context:
space:
mode:
authorNicolas Vigier <boklm@mageia.org>2011-01-11 00:35:59 +0000
committerNicolas Vigier <boklm@mageia.org>2011-01-11 00:35:59 +0000
commitad7fb7807ceaee96521d779993a5e1b28650723f (patch)
tree2ece42aa7e83b7fdb51702b298aa3eec95da3573 /RepSys/command.py
parent715e125cc8d0b3fc4a79752e28a8b76a4ce97d5a (diff)
downloadmgarepo-ad7fb7807ceaee96521d779993a5e1b28650723f.tar
mgarepo-ad7fb7807ceaee96521d779993a5e1b28650723f.tar.gz
mgarepo-ad7fb7807ceaee96521d779993a5e1b28650723f.tar.bz2
mgarepo-ad7fb7807ceaee96521d779993a5e1b28650723f.tar.xz
mgarepo-ad7fb7807ceaee96521d779993a5e1b28650723f.zip
rename repsys to mgarepo, RepSys to MgaRepo, and update docs and examples for Mageia
Diffstat (limited to 'RepSys/command.py')
-rw-r--r--RepSys/command.py61
1 files changed, 0 insertions, 61 deletions
diff --git a/RepSys/command.py b/RepSys/command.py
deleted file mode 100644
index 63f2df9..0000000
--- a/RepSys/command.py
+++ /dev/null
@@ -1,61 +0,0 @@
-#!/usr/bin/python
-from RepSys import SilentError, Error, config
-import sys, os
-import urlparse
-import optparse
-
-__all__ = ["OptionParser", "do_command", "default_parent"]
-
-class CapitalizeHelpFormatter(optparse.IndentedHelpFormatter):
-
- def format_usage(self, usage):
- return optparse.IndentedHelpFormatter \
- .format_usage(self, usage).capitalize()
-
- def format_heading(self, heading):
- return optparse.IndentedHelpFormatter \
- .format_heading(self, heading).capitalize()
-
-class OptionParser(optparse.OptionParser):
-
- def __init__(self, usage=None, help=None, **kwargs):
- if not "formatter" in kwargs:
- kwargs["formatter"] = CapitalizeHelpFormatter()
- optparse.OptionParser.__init__(self, usage, **kwargs)
- self._overload_help = help
-
- def format_help(self, formatter=None):
- if self._overload_help:
- return self._overload_help
- else:
- return optparse.OptionParser.format_help(self, formatter)
-
- def error(self, msg):
- raise Error, msg
-
-def do_command(parse_options_func, main_func):
- try:
- opt = parse_options_func()
- main_func(**opt.__dict__)
- except SilentError:
- sys.exit(1)
- except Error, e:
- sys.stderr.write("error: %s\n" % str(e))
- sys.exit(1)
- except KeyboardInterrupt:
- sys.stderr.write("interrupted\n")
- sys.stderr.flush()
- sys.exit(1)
-
-def default_parent(url):
- if url.find("://") == -1:
- default_parent = config.get("global", "default_parent")
- if not default_parent:
- raise Error, "received a relative url, " \
- "but default_parent was not setup"
- parsed = list(urlparse.urlparse(default_parent))
- parsed[2] = os.path.normpath(parsed[2] + "/" + url)
- url = urlparse.urlunparse(parsed)
- return url
-
-# vim:et:ts=4:sw=4