From 9458b75cd770e13668c13e9bbe006afd0a9c9891 Mon Sep 17 00:00:00 2001 From: Jon Bernard Date: Sat, 18 Sep 2010 12:28:31 -0400 Subject: Initial commit --- bin/pepseq | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100755 bin/pepseq (limited to 'bin') diff --git a/bin/pepseq b/bin/pepseq new file mode 100755 index 0000000..ef824fc --- /dev/null +++ b/bin/pepseq @@ -0,0 +1,60 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- + +import gettext +import logging +import optparse +import os +import sys + +import gettext +from gettext import gettext as _ +gettext.textdomain('pepseq') + +# Add project root directory (enable symlink, and trunk execution). +PROJECT_ROOT_DIRECTORY = os.path.abspath( + os.path.dirname(os.path.dirname(os.path.realpath(sys.argv[0])))) + +if (os.path.exists(os.path.join(PROJECT_ROOT_DIRECTORY, 'pepseq')) + and PROJECT_ROOT_DIRECTORY not in sys.path): + sys.path.insert(0, PROJECT_ROOT_DIRECTORY) + os.putenv('PYTHONPATH', PROJECT_ROOT_DIRECTORY) # for subprocesses + +from pepseq import pepseqconfig + +LEVELS = ( logging.ERROR, + logging.WARNING, + logging.INFO, + logging.DEBUG, + ) + +if __name__ == "__main__": + + version = pepseqconfig.__pepseq_data_directory__ + # Support for command line options. + usage = _("pepseq [options]") + parser = optparse.OptionParser(version="pepseq %s" % version, usage=usage) + parser.add_option('-d', '--debug', dest='debug_mode', action='store_true', + help=_('Print the maximum debugging info (implies -vv)')) + parser.add_option('-v', '--verbose', dest='logging_level', action='count', + help=_('set error_level output to warning, info, and then debug')) + # exemple of silly CLI option + parser.add_option("-f", "--foo", action="store", dest="foo", + help=_("foo should be assigned to bar")) + parser.set_defaults(logging_level=0, foo=None) + (options, args) = parser.parse_args() + + # set the verbosity + if options.debug_mode: + options.logging_level = 3 + logging.basicConfig(level=LEVELS[options.logging_level], format='%(asctime)s %(levelname)s %(message)s') + + + # this is the easter egg (: + if options.foo == 'bar': + logging.warning(_('easter egg found')) + print(_("Schweet")) + + # Run your cli application there. + print _("I'm launched and my args are: %s") % (" ".join(args)) + logging.debug(_('end of prog')) -- cgit v1.2.3