Exemplo n.º 1
0
def execute_putsite(ui_, repo, params):
    """ Run the putsite command. """
    def progress(dummy, msg):
        """ Message callback which writes to the hg ui instance."""

        if msg[0] == 'SimpleProgress':
            ui_.status(
                "Progress: (%s/%s/%s)\n" %
                (msg[1]['Succeeded'], msg[1]['Required'], msg[1]['Total']))
        else:
            ui_.status("Progress: %s\n" % msg[0])

    if params.get('SITE_CREATE_CONFIG', False):
        write_default_config(ui_, repo)
        return

    # Remove trailing /
    params['SITE_KEY'] = params['SITE_KEY'].split('/')[0].strip()
    try:
        do_freenet_insert(ui_, repo, params, get_insert_uri(params), progress)
    finally:
        tmp_dump = os.path.join(params['TMP_DIR'], TMP_DUMP_DIR)
        if os.path.exists(tmp_dump):
            # REDFLAG: DCI, failure here is horrible.
            # i.e. untrusted unencrypted data on your disk
            shutil.rmtree(tmp_dump)
Exemplo n.º 2
0
def execute_wiki(ui_, repo, params):
    """ Run the wiki command. """
    def out_func(text):
        """ Helper displays output from serve_wiki via ui.status. """
        ui_.status(text + '\n')

    if params['WIKI'] == 'run':
        ui_.status("wikitext version: %s\n" % get_hg_version(repo)[:12])
        if not os.path.exists(os.path.join(repo.root, 'fnwiki.cfg')):
            raise util.Abort("Can't read fnwiki.cfg. Did you forget hg " +
                             "fn-wiki --createconfig?")

        servepiki.serve_wiki(params['HTTP_PORT'], params['HTTP_BIND'],
                             out_func)
        return

    # Hmmmm... some basic UI depends on wikitext. not sure
    # how useful a completely empty wiki is.
    if params['WIKI'] == 'createconfig':
        if os.path.exists(os.path.join(repo.root, 'fnwiki.cfg')):
            raise util.Abort("fnwiki.cfg already exists!")

        if os.path.exists(os.path.join(repo.root, 'wiki_root')):
            raise util.Abort("The wiki_root subdirectory already exists! " +
                             "Move it out of the way to continue.")

        create_default_wiki(os.path.join(repo.root, 'wiki_root'))
        ui_.status("Created skeleton wiki_root dir.\n")
        write_default_config(ui_, repo, True)
        return

    raise util.Abort("Unsupported subcommand: " +
                     params.get('WIKI', 'unknown'))
Exemplo n.º 3
0
def execute_wiki(ui_, repo, params):
    """ Run the wiki command. """
    def out_func(text):
        """ Helper displays output from serve_wiki via ui.status. """
        ui_.status(text + '\n')
    if params['WIKI'] == 'run':
        ui_.status("wikitext version: %s\n" % get_hg_version(repo)[:12])
        if not os.path.exists(os.path.join(repo.root, 'fnwiki.cfg')):
            raise util.Abort("Can't read fnwiki.cfg. Did you forget hg " +
                             "fn-wiki --createconfig?")

        servepiki.serve_wiki(params['HTTP_PORT'], params['HTTP_BIND'], out_func)
        return

    # Hmmmm... some basic UI depends on wikitext. not sure
    # how useful a completely empty wiki is.
    if params['WIKI'] == 'createconfig':
        if os.path.exists(os.path.join(repo.root, 'fnwiki.cfg')):
            raise util.Abort("fnwiki.cfg already exists!")

        if os.path.exists(os.path.join(repo.root, 'wiki_root')):
            raise util.Abort("The wiki_root subdirectory already exists! " +
                             "Move it out of the way to continue.")

        create_default_wiki(os.path.join(repo.root, 'wiki_root'))
        ui_.status("Created skeleton wiki_root dir.\n")
        write_default_config(ui_, repo, True)
        return

    raise util.Abort("Unsupported subcommand: " + params.get('WIKI', 'unknown'))
Exemplo n.º 4
0
def execute_putsite(ui_, repo, params):
    """ Run the putsite command. """
    def progress(dummy, msg):
        """ Message callback which writes to the hg ui instance."""

        if msg[0] == 'SimpleProgress':
            ui_.status("Progress: (%s/%s/%s)\n" % (msg[1]['Succeeded'],
                                                   msg[1]['Required'],
                                                   msg[1]['Total']))
        else:
            ui_.status("Progress: %s\n" % msg[0])


    if params.get('SITE_CREATE_CONFIG', False):
        write_default_config(ui_, repo)
        return

    # Remove trailing /
    params['SITE_KEY'] = params['SITE_KEY'].split('/')[0].strip()
    try:
        do_freenet_insert(ui_, repo, params,
                          get_insert_uri(params),
                          progress)
    finally:
        tmp_dump = os.path.join(params['TMP_DIR'], TMP_DUMP_DIR)
        if os.path.exists(tmp_dump):
            # REDFLAG: DCI, failure here is horrible.
            # i.e. untrusted unencrypted data on your disk
            shutil.rmtree(tmp_dump)
Exemplo n.º 5
0
def darbup(args, default_config):
    logger = logging.getLogger()
    logger.setLevel(args.loglevel)

    errlogHandler = logging.StreamHandler(sys.stderr)
    errlogHandler.setLevel(logging.ERROR)
    logger.addHandler(errlogHandler)

    if not os.path.exists(args.config) and args.config == default_config:
        config.write_default_config(default_config)
        return 1

    try:
        conf = config.Config(args.config)
    except Exception as e:
        sys.stderr.write('Failed to read configuration: {}\n'
                         .format(exc_str(e)))
        return 1

    for cfg in conf.instances:
        os.makedirs(os.path.dirname(cfg.logfilename), exist_ok=True)
        log_handler = LogFileHandler(cfg.logfilename,
                                     backupCount=cfg.logsbackupcount)
        logger.addHandler(log_handler)
        log_formatter = logging.Formatter(
            '{asctime} {levelname[0]}{levelname[0]} {message}', style='{')
        log_handler.setFormatter(log_formatter)
        try:
            run(cfg, args.full, args.incr)
        except (BackupError, OSError) as e:
            logging.error(str(e))
        except (KeyboardInterrupt, TerminatedSignal) as e:
            logging.error(exc_str(e))
            return 1
        except Exception as e:
            logging.exception(e)
            raise
        finally:
            logger.removeHandler(log_handler)