Beispiel #1
1
def read_parameters():
    SECTION = "default"

    parser = OptionParser()
    config = configparser.ConfigParser()
    config.read("environments.conf")
    environments = OrderedDict()

    for option in config.options(SECTION):
        environments[option] = config.get(SECTION, option)

    opt_environments = ", ".join(environments.keys())
    default = next(reversed(environments))
    parser.add_option(
        "-e",
        "--environment",
        dest="environment",
        default=default,
        type="choice",
        choices=list(environments.keys()),
        help="set default environment to: " + opt_environments,
    )

    (options, args) = parser.parse_args()

    return environments.get(options.environment, None)
def ParseInputs():
    global DOMAIN_PAIRS

    usage = """usage: %prog -d <domain> -u <admin_user> -p <admin_pass>\n"""
    parser = OptionParser()
    parser.add_option("-u", dest="admin_user", help="admin user")
    parser.add_option("-p", dest="admin_pass", help="admin pass")
    parser.add_option("-d", dest="domain", help="Domain name")
    parser.add_option("-n", dest="nick_domain", help="The domain of the nick that should exist.")
    parser.add_option(
        "--apply",
        action="store_true",
        dest="apply",
        help="""If present, changes will be applied, otherwise
                            will run in dry run mode with no changes made""",
    )

    (options, args) = parser.parse_args()

    if options.admin_user is None:
        print "-u (admin user) is required"
        sys.exit(1)
    if options.admin_pass is None:
        print "-p (admin password) is required"
        sys.exit(1)
    if (options.domain and not options.nick_domain) or (options.nick_domain and not options.domain):
        print "Both -d and -n need to be given"
        sys.exit(1)
    if not options.domain and not options.nick_domain and not DOMAIN_PAIRS:
        print "No domain pairs given"
        sys.exit(1)

    return options
Beispiel #3
0
def main():

    usage = "usage: %prog [options]\n Fetch mysql status"
    parser = OptionParser(usage)
    parser.add_option(
        "-H", "--host", action="store", dest="host", type="string", default="localhost", help="Connect to mysql host."
    )
    parser.add_option("-d", "--debug", action="store_true", dest="debug", default=False, help="if output all process")
    parser.add_option(
        "-i", "--item", action="store", dest="item", type="string", default="Uptime", help="which item to fetch"
    )

    (options, args) = parser.parse_args()
    if 1 >= len(sys.argv):
        parser.print_help()
        return

    hostname = options.host
    mysql = Mysql(hostname, debug=options.debug)
    try:
        print mysql.get_item_val(options.item)

    except Exception as expt:
        import traceback

        tb = traceback.format_exc()
        mysql.get_logger().error(tb)
def main(instance_map, templates, service_group=None, with_heartbeat=False, with_stats_worker=False, config_spec=None):
    """Entry point"""
    from optparse import OptionParser

    parser = OptionParser()
    parser.add_option(
        "-n", "--dry-run", dest="dry_run", action="store_true", help="Show the generated config via stdout."
    )
    options, args = parser.parse_args()

    for server_name, env_service_map in instance_map.items():
        config_content = generate_server_config(
            server_name,
            env_service_map,
            config_spec,
            templates,
            service_group,
            with_heartbeat,
            with_stats_worker,
            with_header=True,
        )
        if options.dry_run:
            print config_content
        else:
            filename = "configs/supervisor-%s.conf" % (server_name,)
            with open(os.path.join(get_rootdir(), filename), "w") as f:
                f.write(config_content)
Beispiel #5
0
def svndump_transform_revprop_cmdline(appname, args):
    """
    Parses the commandline and executes the transformation.

    Usage:

        >>> svndump_transform_cmdline( sys.argv[0], sys.argv[1:] )

    @type appname: string
    @param appname: Name of the application (used in help text).
    @type args: list( string )
    @param args: Commandline arguments.
    @rtype: integer
    @return: Return code (0 = OK).
    """

    usage = "usage: %s propname regex replace source destination" % appname
    parser = OptionParser(usage=usage, version="%prog " + __version)
    (options, args) = parser.parse_args(args)

    if len(args) != 5:
        print "specify exactly one propname to transform, one regex to match the value against,\none replacement string, one source dump file and one destination dump file."
        return 1

    copy_dump_file(args[3], args[4], RevisionPropertyTransformer(args[0], args[1], args[2]))
    return 0
def main():
    import sys
    from optparse import OptionParser

    progname = os.path.basename(sys.argv[0])
    usage = progname + " dir"
    parser = OptionParser(usage, version="v1")
    (options, args) = parser.parse_args(sys.argv[1:])

    myhashes = []

    ## there are 84 places were the "long_computation_test.py" program
    ## saves its state; we simulate a program failure in all of them.
    ## the program "long_computation_test.py" will "abnormally" exit
    ## when the "program_state_stack" function has been called "counter" times.
    for counter in xrange(2, 84):
        os.system("rm -rf a")
        os.system("mkdir -p a/a1")
        os.system("mkdir -p a/a2")
        os.system("rm -f my_state.json ; mpirun --tag-output -np 2 python long_computation_test.py %d a/a1/" % counter)
        os.system("mpirun --tag-output -np 2 python long_computation_test.py 100000 a/a2/")
        myhashes.append(GetHashofDirs("a"))

        sys.stdout.write("%d " % counter + str(len(set(myhashes)) == 1) + " \n")
        sys.stdout.flush()

    print
    print
    print len(set(myhashes)) == 1
    print myhashes
Beispiel #7
0
class CommandDispatch:
    def __init__(self):
        self.commands = {}
        self.default = ""

    def register_command(self, command, default=False):
        self.commands[command.name.lower()] = command
        if default:
            self.default = command.name.lower()

    def __call__(self, command=False):
        if command:
            self.commands[command]()
        else:
            self.default_command()

    def default_command(self):
        if self.default:
            self.commands[self.default]()
        else:
            usage = "%prog command [options]\n"
            usage += "Available commands: "
            usage += " ".join(sorted(self.commands.keys()))
            self.parser = OptionParser(usage=usage, version=__version__)
            self.parser.parse_args()
            self.parser.print_help()
Beispiel #8
0
def getProgOptions():
    from optparse import OptionParser, make_option

    option_list = [
        make_option("-i", "--in-seq", action="append", type="string", dest="inSeq"),
        make_option("-o", "--out-name", action="store", type="string", dest="outName"),
        make_option("-s", "--num-splits", action="store", type="int", dest="nSplits", default=3),
        make_option("-m", "--min-samp-count", action="store", type="int", dest="minSampCount", default=100),
        make_option("-t", "--max-samp-seq", action="store", type="int", dest="maxSampCountPerSeq"),
        make_option("-l", "--samp-len", action="store", type="int", dest="sampLen", default=1000),
        make_option("-f", "--samp-offset", action="store", type="int", dest="sampOffset", default=0),
        make_option("-d", "--make-other", action="store_true", dest="makeOther", default=False),
        make_option(
            "-a",
            "--alphabet",
            action="store",
            type="choice",
            choices=("dna", "protein"),
            dest="alphabet",
            default="dna",
        ),
        make_option("-e", "--degen-len", action="store", type="int", dest="degenLen", default=1),
    ]
    parser = OptionParser(usage="usage: %prog [options]", option_list=option_list)
    (options, args) = parser.parse_args()

    return options, args
Beispiel #9
0
def main():
    parser = OptionParser(usage="usage: %prog [options]")
    parser.add_option(
        "-c",
        "--cmd",
        action="store",
        dest="cmd",
        type="choice",
        choices=["dtrace", "agent"],
        default="agent",
        help="command to run",
    )
    parser.add_option("--app", action="append", dest="apps", default=[], help="application(s) under test")
    parser.add_option(
        "-d", "--debug", action="store_true", dest="debug", default=False, help="run examples without post processing"
    )
    parser.add_option("--no-agent", action="store_false", dest="agent", default=True, help="run without logging agent")

    (opt, args) = parser.parse_args()

    global debug, agent
    debug = opt.debug
    agent = opt.agent

    f = globals()["run_" + opt.cmd]
    if opt.apps:
        for app in opt.apps:
            r = f(args, app)
            if r:
                return r
    else:
        return f(args)
def ParseOptions():

    parser = OptionParser(usage="python evaluatePrediction.py --file filename")

    parser.add_option("-f", dest="input_file", default=None, help="Input file (one file only)")

    return parser.parse_args()
def main(args):

    usage = "usage: %prog [options] <html directory>"
    parser = OptionParser(usage=usage)
    parser.add_option(
        "-v", "--verbose", action="store_true", dest="verbose", default=False, help="Provides verbose output"
    )
    opts, args = parser.parse_args(args)

    try:
        path = args[0]
    except IndexError:
        sys.stderr.write("Error - Expecting path to html directory:" "sphinx-to-github <path>\n")
        return

    dir_helper = DirHelper(os.path.isdir, os.listdir, os.walk, shutil.rmtree)

    file_helper = FileSystemHelper(open, os.path.join, shutil.move, os.path.exists)

    operations_factory = OperationsFactory()
    handler_factory = HandlerFactory()

    layout_factory = LayoutFactory(
        operations_factory, handler_factory, file_helper, dir_helper, opts.verbose, sys.stdout, force=False
    )

    try:
        layout = layout_factory.create_layout(path)
    except NoDirectoriesError:
        sys.stderr.write("Error - No top level directories starting with an underscore " "were found in '%s'\n" % path)
        return

    layout.process()
def process_arg():
    from optparse import OptionParser

    usage = "Password_change.py -f Filename"
    parser = OptionParser(usage)
    parser.add_option("-f", dest="filename", help="File Name")
    return parser.parseargs(sys.argv)
Beispiel #13
0
def main():
    parser = OptionParser(usage=usage())
    options, args = parser.parse_args()

    if not args:
        print "No queues specified"
        parser.print_usage()
        sys.exit(1)

    # Nested import/functions to prevent unnecessary overhead when no
    # queues are specified
    import Globals
    from Products.ZenUtils.GlobalConfig import getGlobalConfiguration

    global_conf = getGlobalConfiguration()
    hostname = global_conf.get("amqphost", "localhost")
    port = global_conf.get("amqpport", "5672")
    username = global_conf.get("amqpuser", "zenoss")
    password = global_conf.get("amqppassword", "zenoss")
    vhost = global_conf.get("amqpvhost", "/zenoss")
    ssl = global_conf.get("amqpusessl", "0")
    use_ssl = True if ssl in ("1", "True", "true") else False

    cxn = Connection(
        host="%s:%s" % (hostname, port), userid=username, password=password, virtual_host=vhost, ssl=use_ssl
    )

    with closing(cxn) as conn, closing(conn.channel()) as channel:
        for queue in args:
            print "Removing queue: %s" % queue
            try:
                channel.queue_delete(queue)
            except Exception as e:
                print "ERROR: Unable to remove %s; does it exist?" % queue
                sys.exit(1)
Beispiel #14
0
def parse_arguments(argv):
    usage = "i18nreport [-h] [--path PATH] [--format FORMAT]" + " [--all-languages]"

    parser = OptionParser(usage=usage)

    parser.add_option("-p", "--path", dest="path", help="Path to scan for translations (defaults to pwd)")

    parser.add_option(
        "-f",
        "--format",
        dest="format",
        type="choice",
        help="Formats: %s" % ", ".join(FORMATTERS.keys()),
        choices=FORMATTERS.keys(),
    )

    parser.add_option(
        "-a", "--all-languages", help="Show also languages wich are not translated at all", action="store_true"
    )

    options, args = parser.parse_args(argv)
    if len(args) != 0:
        parser.print_help()
        sys.exit(1)

    # make a dict of options which are not None
    options = dict([(key, value) for (key, value) in vars(options).items() if value is not None])

    return options
Beispiel #15
0
def main(allowed_options=None, description=None, usage=None):
    from os import getcwd
    from sys import argv
    from optparse import OptionParser
    from rabbitvcs.util.helper import get_common_directory

    parser = OptionParser(usage=usage, description=description)

    if allowed_options:
        for (option_args, option_kwargs) in allowed_options:
            parser.add_option(*option_args, **option_kwargs)

    (options, args) = parser.parse_args(argv)

    # Convert "." to current working directory
    paths = args[1:]
    for i in range(0, len(paths)):
        if paths[i] == ".":
            paths[i] = getcwd()

    if not paths:
        paths = [getcwd()]

    if parser.has_option("--base-dir") and not options.base_dir:
        options.base_dir = get_common_directory(paths)

    return (options, paths)
    def __init__(self):
        gr.top_block.__init__(self)

        parser = OptionParser(option_class=eng_option)
        parser.add_option(
            "-O", "--audio-output", type="string", default="", help="pcm output device name.  E.g., hw:0,0 or /dev/dsp"
        )
        parser.add_option(
            "-i", "--input-rate", type="eng_float", default=8000, help="set input sample rate to RATE (%default)"
        )
        parser.add_option(
            "-o", "--output-rate", type="eng_float", default=48000, help="set output sample rate to RATE (%default)"
        )
        (options, args) = parser.parse_args()
        if len(args) != 0:
            parser.print_help()
            raise SystemExit, 1

        input_rate = int(options.input_rate)
        output_rate = int(options.output_rate)

        interp = gru.lcm(input_rate, output_rate) / input_rate
        decim = gru.lcm(input_rate, output_rate) / output_rate

        print "interp =", interp
        print "decim  =", decim

        ampl = 0.1
        src0 = analog.sig_source_f(input_rate, analog.GR_SIN_WAVE, 650, ampl)
        rr = filter.rational_resampler_fff(interp, decim)
        dst = audio.sink(output_rate, options.audio_output)
        self.connect(src0, rr, (dst, 0))
Beispiel #17
0
    def __init__(self, command_line_args):
        parser = OptionParser(usage="%prog [options] <back end command> [args]")
        parser.disable_interspersed_args()
        parser.add_option("--sgf-dir", metavar="PATHNAME")
        parser.add_option("--filename-template", metavar="TEMPLATE", help="eg '%03d.sgf'")
        opts, args = parser.parse_args(command_line_args)

        if not args:
            parser.error("must specify a command")
        self.subprocess_command = args

        self.filename_template = "%04d.sgf"
        try:
            opts.filename_template % 3
        except Exception:
            pass
        else:
            self.filename_template = opts.filename_template

        self.sgf_dir = opts.sgf_dir
        if self.sgf_dir:
            self.check_sgf_dir()
            self.do_savesgf = True
        else:
            self.do_savesgf = False
Beispiel #18
0
    def test_forgetting_services(self):
        """Are services correctly forgotten?

        Technically, this means "never saved."

        Chances are good my fake service names won't ever be real services, so
        unless somebody's trying to outsmart the test, there's nothing to worry
        about.

        """
        url = "sharky_with_angry_hats"
        service = "omg its a fake service name, haha."

        options = OptionParser()
        options.config = "../data/test.cfg"

        (keyid, lang, protocols, connectors) = santiago_test.load_config(options)

        listeners, senders, monitors = santiago_test.configure_connectors(protocols, connectors)

        hosting = {keyid: {service: [url]}}
        consuming = {keyid: {service: [url]}}

        freedombuddy = santiago.Santiago(hosting=hosting, consuming=consuming, save_services=False, me=keyid)
        freedombuddy1 = santiago.Santiago(me=keyid)

        self.cycle(freedombuddy)
        self.cycle(freedombuddy1)

        self.assertNotIn(service, freedombuddy1.hosting)
        self.assertNotIn(service, freedombuddy1.consuming)
Beispiel #19
0
def parse_options():
    parser = OptionParser()
    parser.add_option(
        "-f", "--file", dest="filename", default="/etc/sssd/sssd.conf", help="Set input file to FILE", metavar="FILE"
    )
    parser.add_option(
        "-o", "--outfile", dest="outfile", default=None, help="Set output file to OUTFILE", metavar="OUTFILE"
    )
    parser.add_option(
        "",
        "--no-backup",
        action="store_false",
        dest="backup",
        default=True,
        help="""Do not provide backup file after conversion.
The script copies the original file with the suffix .bak
by default""",
    )
    parser.add_option("-v", "--verbose", action="store_true", dest="verbose", default=False, help="Be verbose")
    (options, args) = parser.parse_args()
    if len(args) > 0:
        print >>sys.stderr, "Stray arguments: %s" % " ".join([a for a in args])
        return None

    # do the conversion in place by default
    if not options.outfile:
        options.outfile = options.filename

    return options
Beispiel #20
0
def get_option_parser():
    parser = OptionParser(version=__version__, usage="Usage: pep257 [options] [<file|dir>...]")
    parser.config_options = ("explain", "source", "ignore", "match", "match-dir", "debug", "verbose", "count")
    option = parser.add_option
    option("-e", "--explain", action="store_true", help="show explanation of each error")
    option("-s", "--source", action="store_true", help="show source for each error")
    option(
        "--ignore",
        metavar="<codes>",
        default="",
        help="ignore a list comma-separated error codes, " "for example: --ignore=D101,D202",
    )
    option(
        "--match",
        metavar="<pattern>",
        default="(?!test_).*\.py",
        help="check only files that exactly match <pattern> regular "
        "expression; default is --match='(?!test_).*\.py' which "
        "matches files that don't start with 'test_' but end with "
        "'.py'",
    )
    option(
        "--match-dir",
        metavar="<pattern>",
        default="[^\.].*",
        help="search only dirs that exactly match <pattern> regular "
        "expression; default is --match-dir='[^\.].*', which matches "
        "all dirs that don't start with a dot",
    )
    option("-d", "--debug", action="store_true", help="print debug information")
    option("-v", "--verbose", action="store_true", help="print status information")
    option("--count", action="store_true", help="print total number of errors to stdout")
    return parser
def main():
    os.chdir(os.path.dirname(os.path.realpath(__file__)))
    parser = OptionParser()
    parser.add_option(
        "-d",
        dest="debug",
        action="store_true",
        default=False,
        help="Enable debug mode (different starting board configuration)",
    )
    parser.add_option("-t", dest="text", action="store_true", default=False, help="Use text-based GUI")
    parser.add_option("-o", dest="old", action="store_true", default=False, help="Use old graphics in pygame GUI")
    parser.add_option(
        "-p",
        dest="pauseSeconds",
        metavar="SECONDS",
        action="store",
        default=0,
        help="Sets time to pause between moves in AI vs. AI games (default = 0)",
    )

    (options, args) = parser.parse_args()

    game = PythonChessMain(options)
    game.SetUp(options)
    game.MainLoop()
def main():
    usage = "Usage: %prog [options] pathStats_hg19.xml sequencesDir"
    parser = OptionParser(usage=usage)
    Stack.addJobTreeOptions(parser)

    initOptions(parser)
    options, args = parser.parse_args()
    checkOptions(args, options, parser)

    insertions = readfile(args[0], options.minsize, options.filteredSamples)
    # HLA-DRB region: chr6:32,414,165-32,605,002
    start = 32414165
    end = 32605002
    numDRBins = 0
    for s in insertions:
        for ins in insertions[s]:
            if start <= ins.refstart and ins.refstart <= end:
                numDRBins += 1
    sys.stderr.write("Number of insertions in HLA-DRB region: %d\n" % numDRBins)
    # return

    getInsertedSeqs(insertions, args[1])
    printInsertSeqs(insertions)

    # mapSeqs(insertions, options)
    i = Stack(MapSeqs(insertions, options)).startJobTree(options)
    if i:
        raise RuntimeError("The jobTree contains %d failed jobs\n" % i)
Beispiel #23
0
def svndump_eolfix_prop_cmdline(appname, args):
    """
    Parses the commandline and executes the transformation.

    Usage:

        >>> svndump_eolfix_prop_cmdline( sys.argv[0], sys.argv[1:] )

    @type appname: string
    @param appname: Name of the application (used in help text).
    @type args: list( string )
    @param args: Commandline arguments.
    @rtype: integer
    @return: Return code (0 = OK).
    """

    usage = "usage: %s propname source destination" % appname
    parser = OptionParser(usage=usage, version="%prog " + __version)
    (options, args) = parser.parse_args(args)

    if len(args) != 3:
        print "specify exactly one propname to fix EOL, one source dump file and one destination dump file."
        return 1

    copy_dump_file(args[1], args[2], EolPropertyTransformer(args[0]))
    return 0
Beispiel #24
0
    def run(self):
        parser = OptionParser()
        parser.add_option(
            "-p",
            "--pattern",
            metavar="PATTERN",
            type="string",
            nargs=1,
            dest="pattern",
            help="Pattern of files to look out for",
        )
        parser.add_option(
            "-r",
            "--range",
            metavar="RANGE",
            type="string",
            nargs=1,
            dest="range",
            help="Range of file numbers, eg. -r 1,1800",
        )
        parser.add_option("-v", action="store_true", dest="verbose", default=False, help="be moderately verbose")
        parser.add_option("-?", help=SUPPRESS_HELP, action="help")
        self._opts, args = parser.parse_args()

        if self._opts.pattern and self._opts.range:
            self.watch()
Beispiel #25
0
def main():
    # No need for options currently, use this for --help, --version
    parser = OptionParser(usage="%prog [options] input_file output_file", version="%%prog %s" % get_version_string())
    parser.add_option(
        "-e", "--encoding", default="UTF-8", help="Set parser encoding. Default is UTF-8.", metavar="ENCODING"
    )
    options, args = parser.parse_args()

    if len(args) < 2:
        return help()

    input_filename = args[0]
    output_filename = args[1]

    if not os.path.exists(input_filename):
        print "input file does not exist"
        sys.exit(0)

    input_file = None
    try:
        input_file = open(input_filename, "r")
        input_data = input_file.read()
    except IOError, e:
        print "failed to open input file %s" % input_filename
        sys.exit(0)
Beispiel #26
0
def main():
    """
    Start-up web server.
    """
    parser = OptionParser()
    parser.add_option("-c", "--config", dest="config", default=False, help="provide cherrypy configuration file")
    opts, _ = parser.parse_args()

    # Read server configuration
    conf_file = opts.config
    config = {}
    if conf_file:
        fdesc = open(conf_file, "r")
        config = yaml.load(fdesc.read())
        fdesc.close()
    else:
        config = readconfig()
    config["port"] = config["server_port"]

    root = Root(config)
    print root.config
    # subscribe plugins
    cherrypy.engine.qbm = QueryBuilderBus(cherrypy.engine, root.config["db_url"], root.config["map_file"])

    cherrypy.engine.qbm.subscribe()

    # Start PyQB server
    root.start()
Beispiel #27
0
class Formatter:
    def __init__(self, module_name=""):
        self.__step_started = False
        self.__step_name = ""
        self.__step_index = 1
        self.__step_total = 1
        self.__prefix = self.__output_format("<b>" + module_name + "</b>: ")
        self.option_parser = OptionParser()
        self.step = Step(self.__step_start, self.__step_update, self.__step_finish)

    def usage_error(self, message):
        self.option_parser.print_usage()
        self.error(message)

    def error(self, message):
        self.message("\a" + message)

    def message(self, message):
        print self.format(message)

    def format(self, message):
        return self.__output(self.__prefix + message)

    def __output(self, message):
        return u"" + self.__output_format(message)

    def __output_format(self, message):
        return message.replace("<b>", "\033[1m").replace("</b>", "\033[0m")

    def __step_start(self, name, total=1):
        if self.__step_started:
            self.__step_finish()
        else:
            self.__step_started = True

        self.__step_name = name
        self.__step_total = total
        self.__print(name)

        return self.step

    def __print(self, message):
        stdout.write("")
        stdout.flush()
        stdout.write(self.__output(message) + "\r")

    def __step_update(self):
        self.__print(self.__step_name + " (" + str(self.__step_index) + "/" + str(self.__step_total) + ")")
        self.__step_index += 1

        return self.step

    def __step_finish(self, message=""):
        if message:
            message += "\n"

        self.__step_index = 1
        self.__print("\n" + message)

        return self.step
Beispiel #28
0
def main(args=sys.argv[1:]):
    """console_script entry point"""

    # set up an option parser
    usage = "%prog [options] [command] ..."
    description = "%s. Use `help` to display commands" % __doc__.strip()
    parser = OptionParser(usage=usage, description=description)
    parser.add_option(
        "-s", "--strict", dest="strict", action="store_true", default=False, help="adhere strictly to errors"
    )
    parser.disable_interspersed_args()

    options, args = parser.parse_args(args)

    if not args:
        HelpCLI(parser)(options, args)
        parser.exit()

    # get the command
    command = args[0]
    if command not in commands:
        parser.error("Command must be one of %s (you gave '%s')" % (", ".join(sorted(commands.keys())), command))

    handler = commands[command](parser)
    handler(options, args[1:])
Beispiel #29
0
 def getArgvs():
     parser = OptionParser()
     parser = OptionParser()
     parser.add_option("-f", "--filter", dest="mal_filter", default=[], help="Filter the malwares.", action="append")
     parser.add_option(
         "-u", "--update", dest="update_bol", default=0, help="Updates the DB of theZoo.", action="store_true"
     )
     parser.add_option(
         "-v",
         "--version",
         dest="ver_bol",
         default=0,
         help="Shows version and licensing information.",
         action="store_true",
     )
     parser.add_option(
         "-w",
         "--license",
         dest="license_bol",
         default=0,
         help="Prints the GPLv3 license information.",
         action="store_true",
     )
     (options, args) = parser.parse_args()
     return options
Beispiel #30
0
def main(argv=None):
    """
    Wrapper for logresolvemerge.pl which moves the processed logfiles away after successful processing

    """
    if argv is None:
        argv = sys.argv

    parser = OptionParser()
    parser.add_option(
        "-d", "--debug", action="store_true", dest="debug", help="Turn on debugging output", default=False
    )
    (options, args) = parser.parse_args(argv)
    args = args[1:]

    OUTPUTDIR = "/opt/pysk/wwwlogs"

    if options.debug:
        print >>sys.stderr, "Debug mode activated"

    ret = call(["/opt/pysk/tools/logfiles/logresolvemerge.pl"] + args)

    if ret == 0:
        # print "Moving logfiles from pending to processed ..."
        for fname in args:
            vhostname = os.path.basename(os.path.dirname(fname))
            if not os.path.exists(os.path.join(OUTPUTDIR, "processed", vhostname)):
                os.makedirs(os.path.join(OUTPUTDIR, "processed", vhostname))
            os.rename(fname, os.path.join(OUTPUTDIR, "processed", vhostname, os.path.basename(fname)))

    return ret