Ejemplo n.º 1
0
    def add_arguments(self, parser):
        """Add custom arguments."""
        parser.add_argument("--clean-frequency",
                            help="How much time to wait between two clean.",
                            default=24 * 60 * 60,
                            type=int)
        parser.add_argument("--repair-frequency",
                            help="How much time to wait between two repair.",
                            default=24 * 60 * 60,
                            type=int)
        parser.add_argument("--listen-on",
                            help="Port on which the http server will listen",
                            default=8080,
                            type=int)

        # To avoid to fail to add the same option twice
        old_fn = parser.add_argument

        def add_arg(*args, **kwargs):
            try:
                old_fn(*args, **kwargs)
            except Exception:
                pass

        parser.add_argument = add_arg
        command_repair.CommandRepair.add_arguments(
            command_repair.CommandRepair(), parser)
        command_clean.CommandClean.add_arguments(command_clean.CommandClean(),
                                                 parser)
Ejemplo n.º 2
0
    def test_run(self):
        cmd = command_repair.CommandRepair()

        parser = argparse.ArgumentParser()
        bg_settings.add_argparse_arguments(parser)
        cmd.add_arguments(parser)
        opts = parser.parse_args(["--shard=0", "--nshards=5"])
        cmd.run(self.accessor, opts)
Ejemplo n.º 3
0
    def test_run(self):
        cmd = command_repair.CommandRepair()

        parser = argparse.ArgumentParser()
        bg_utils.add_argparse_arguments(parser)
        cmd.add_arguments(parser)
        opts = parser.parse_args(['--shard=0', '--nshards=5'])
        cmd.run(self.accessor, opts)
Ejemplo n.º 4
0
    def _run_repair(self, worker, accessor, opts):
        logging.info("Repair started at %s" % time.strftime("%c"))

        fake_stderr = StringIO()
        pbar = progressbar.ProgressBar(fd=fake_stderr)

        def on_progress(done, total):
            fake_stderr.seek(0)
            pbar.max_value = total
            pbar.update(done)
            worker["status"] = fake_stderr.getvalue()

        repair = command_repair.CommandRepair()
        repair.pbar = pbar
        repair.run(accessor, opts, on_progress=on_progress)

        logging.info("Repair finished at %s" % time.strftime("%c"))
        logging.info("Going to sleep for %d seconds " % opts.repair_frequency)
        time.sleep(opts.repair_frequency)
Ejemplo n.º 5
0
    command_syncdb,
    command_test,
    command_write,
)

COMMANDS = [
    command_clean.CommandClean(),
    command_copy.CommandCopy(),
    command_daemon.CommandDaemon(),
    command_delete.CommandDelete(),
    command_du.CommandDu(),
    command_graphite_web.CommandGraphiteWeb(),
    command_info.CommandInfo(),
    command_list.CommandList(),
    command_read.CommandRead(),
    command_repair.CommandRepair(),
    command_shell.CommandShell(),
    command_stats.CommandStats(),
    command_syncdb.CommandSyncdb(),
    command_test.CommandTest(),
    command_write.CommandWrite(),
]


def _parse_opts(args):
    """Parse command line arguments."""
    parser = argparse.ArgumentParser(
        description="BigGraphite command line utility.")
    bg_utils.add_argparse_arguments(parser)
    subparsers = parser.add_subparsers(help="commands")
    for command in COMMANDS: