Пример #1
0
def container_args(
    positional: arg(container=tuple, type=int),
    optional: arg(type=int) = (),
    another_optional: arg(container=list, type=float) = None,
    third_optional=(42,),
):
    return MockResult((positional, optional, another_optional, third_optional))
Пример #2
0
def bycycle(service: arg(choices=('lookup', 'route')), q):
    """Run a byCycle service."""
    module_name = 'bycycle.core.service.{service}'.format(service=service)
    service_factory = load_object(module_name, 'Service')

    if service == 'route':
        q = re.split('\s+to\s+', q, re.I)
        if len(q) < 2:
            abort(1, 'Route must be specified as "A to B"')

    engine = get_engine()
    session_factory = get_session_factory(engine)
    session = session_factory()

    start_time = time.time()
    try:
        service = service_factory(session)
        response = service.query(q)
    except Exception:
        session.rollback()
        raise
    else:
        session.close()
        print(response)
    print('{:.2f} seconds'.format(time.time() - start_time))
Пример #3
0
def load_osm_data(db,
                  bbox: arg(type=float, nargs=4),
                  directory='../osm',
                  graph_path='../graph.marshal',
                  streets=True,
                  places=True,
                  actions: arg(container=tuple, type=int) = (),
                  show_actions: arg(short_option='-a') = False,
                  log_to=None):
    """Read OSM data from file and load into database."""
    importer = OSMImporter(bbox, directory, graph_path, db, streets, places,
                           actions)
    if show_actions:
        printer.header('Available actions:')
        for action in importer.all_actions:
            printer.info(action)
        return
    importer.run()
    if log_to:
        message = f'Loaded OSM data from {importer.data_directory} to {importer.engine.url}'
        log_to_file(log_to, message)
Пример #4
0
def sass(sources: arg(container=tuple), watch=False, quiet=False):
    args = []
    destinations = []
    for source in sources:
        name = os.path.basename(source)
        root, ext = os.path.splitext(name)
        destination = os.path.join('public', 'build', f'{root}.css')
        args.append(f'{source}:{destination}')
        destinations.append(destination)
    local(('sass', '--watch' if watch else None, *args))
    if not quiet:
        for source, destination in zip(sources, destinations):
            print(f'Compiled {source} to {destination}')
Пример #5
0
def rollup(env, live_reload: arg(type=bool) = None, watch=False, quiet=False):
    environ = {'NODE_ENV': env}
    if live_reload is not None:
        environ['LIVE_RELOAD'] = str(int(live_reload))
    kwargs = {
        'environ': environ,
        'stdout': 'hide' if quiet else None,
        'stderr': 'capture',
        'raise_on_error': False,
    }
    result = local(('rollup', '--config', '--watch' if watch else None),
                   **kwargs)
    if result.failed:
        abort(result.return_code, result.stderr)
Пример #6
0
def fetch_osm_data(bbox: arg(type=float, nargs=4),
                   directory='../osm',
                   file_name=None,
                   query='highways',
                   url=None,
                   log_to=None):
    """Fetch OSM data and save to file.

    The bounding box must be passed as min X, min Y, max X, max Y.

    """
    if not file_name:
        file_name = f'{query}.json'
    path = Path(directory) / file_name
    fetcher = OSMDataFetcher(bbox, path, query, url)
    fetcher.run()
    if log_to:
        message = f'Saved OSM data from {fetcher.url} to {fetcher.path}'
        log_to_file(log_to, message)
Пример #7
0
def sub(subcommand: arg(default=None), optional=None):
    return MockResult(f"sub {subcommand} {optional}")
Пример #8
0
def base(subcommand: arg(default=None)):
    return MockResult(f"base {subcommand}")
Пример #9
0
 def sub1(cmd: arg(default=None), a=None, flag=True):
     return MockResult(f"sub1({cmd}, {a}, {flag})")