Beispiel #1
0
def get_parser():
    """
    Creates and returns a new option parser object to be used for parsing the
    command line argument passed.

    :return: A new parser object
    """
    parser = optparse.OptionParser(usage="%prog [options]", version=version())

    with ParserGroup(parser, "Logging") as group:
        tmp_dir = tempfile.gettempdir()
        group.add_option('-f', '--log-file', metavar="FILE", action="store",
            dest="log_file", help="The logfile to use",
            default=os.path.join(tmp_dir, "{0}.log".format(__NAME__)))

        group.add_option('-o', '--std-out', action="store_true",
            dest='use_stdout', default=False,
            help="If set, also log to stdout.")

        group.add_option('-v', action="store_const", dest="level",
            const=logging.DEBUG, default=logging.INFO,
            help="Print extra information. Useful for debugging.")

        group.add_option('-q', action="store_const", dest="level",
            const=logging.WARNING, default=logging.INFO,
            help="Print less information")

    with ParserGroup(parser, "Config") as group:
        group.add_option("-C", "--config", action="append", dest="configs",
            metavar="FILE", default=[],
            help="Add a config file to use. Can be specified multiple times "\
                 "to add more files. Can be an absolute or relative path.")

    return parser
Beispiel #2
0
    def test_version_format(self):
        """The package version string should be properly formatted"""
        import re

        format = r'^\d{1,2}\.\d{1,2}(?:\.\d{1,2})?$'

        m = re.match(format, unameit.version())
        self.assertNotEqual(m, None)