Exemplo n.º 1
0
def main(args=sys.argv):
    peeringdb._config_logs()

    parser = ArgumentParser()
    parser.add_argument("--version",
                        action="version",
                        version="%(prog)s " + peeringdb.__version__)
    parser.add_argument(
        "-C",
        "--config-dir",
        default=os.environ.get("PEERINGDB_HOME", config.DEFAULT_CONFIG_DIR),
        help="Directory containing configuration files",
    )

    cmd = commands.CommandGroup(COMMANDS)
    cmd.add_arguments(parser)

    try:
        options = parser.parse_args(args[1:])
    except SystemExit as e:
        return e.code
    cfg = check_load_config(options.config_dir)

    handler = getattr(options, "handler", options.usage_handler)
    try:
        return handler(config=cfg, **vars(options))
    except peeringdb._fetch.CompatibilityError as e:
        print(e, file=sys.stderr)
        return 1
Exemplo n.º 2
0
 def __init__(self, fetcher, strip_tz=True, dry_run=False, **_):
     self._fetcher = fetcher
     self.strip_tz = strip_tz
     self.dry_run = dry_run
     # allow dep. injection for testing
     self._ContextClass = UpdateContext
     # Must initialize logs now
     _config_logs()
     self._log = logging.getLogger(__name__)
Exemplo n.º 3
0
    def handle(config, verbose, quiet, init, **kwargs):
        rs = resource.all_resources()
        # if only: rs = [resource.get_resource(tag) for tag in only]

        loglvl = 1 + (verbose or 0) - (quiet or 0)
        if loglvl > 1:
            peeringdb._config_logs(logging.DEBUG)
        if loglvl < 1:
            peeringdb._config_logs(logging.WARNING)

        client = Client(config, **kwargs)
        # todo verify table schema
        if init: return

        if loglvl >= 0:
            print("Syncing to", config['sync']['url'])

        client.update_all(rs)
Exemplo n.º 4
0
from __future__ import print_function
import pytest
import logging
import sys, os, tempfile
import os.path as _path
import sqlite3
from contextlib import contextmanager
sys.path.append(_path.join(_path.dirname(__file__)))

import helper
import peeringdb

from peeringdb.client import Client

peeringdb._config_logs(logging.DEBUG)


@pytest.fixture
def config0_dir():
    return _path.join(helper.data_path(), 'config0')


client_empty = helper.client_fixture(None)


@pytest.fixture
def patch_version(monkeypatch):
    @contextmanager
    def func():
        with monkeypatch.context() as mc:
            mc.setattr('peeringdb.__version__', '0.1.0')