Ejemplo n.º 1
0
def get_parser():
    parser = argparse.ArgumentParser(prog='ambry', description='Ambry {}. Management interface for ambry, libraries '
                                                               'and repositories. '.format(ambry._meta.__version__))

    parser.add_argument('-l', '--library', dest='library_name', default="default",
                        help="Name of library, from the library secton of the config")
    parser.add_argument('-c', '--config', default=os.getenv(AMBRY_CONFIG_ENV_VAR), action='append',
                        help="Path to a run config file. Alternatively, set the AMBRY_CONFIG env var")
    parser.add_argument('--single-config', default=False, action="store_true",
                        help="Load only the config file specified")
    parser.add_argument('-E', '--exceptions', default=False, action="store_true",
                        help="Show full exception trace on all exceptions")

    cmd = parser.add_subparsers(title='commands', help='command help')

    from .library import library_parser
    from .warehouse import warehouse_parser
    from .remote import remote_parser
    from test import test_parser
    from config import config_parser
    from source import source_parser
    from bundle import bundle_parser
    from root import root_parser
    
    library_parser(cmd)
    warehouse_parser(cmd)
    source_parser(cmd)
    remote_parser(cmd)
    test_parser(cmd)
    config_parser(cmd)
    bundle_parser(cmd)
    root_parser(cmd)

    return parser
Ejemplo n.º 2
0
def main():
    import argparse
    from .library import library_command #@UnresolvedImport
    from .warehouse import warehouse_command, warehouse_parser #@UnresolvedImport
    from .remote import remote_command  #@UnresolvedImport 
    from .library import library_parser
    from test import test_command #@UnresolvedImport
    from install import install_command #@UnresolvedImport
    from ckan import ckan_command #@UnresolvedImport
    from source import source_command, source_parser  #@UnresolvedImport    
    parser = argparse.ArgumentParser(prog='python -mdatabundles',
                                     description='Databundles {}. Management interface for databundles, libraries and repositories. '.format(__version__))
    
    #parser.add_argument('command', nargs=1, help='Create a new bundle') 
 
    parser.add_argument('-c','--config', default=None, action='append', help="Path to a run config file") 
    parser.add_argument('-v','--verbose', default=None, action='append', help="Be verbose") 
    parser.add_argument('--single-config', default=False,action="store_true", help="Load only the config file specified")

  
    cmd = parser.add_subparsers(title='commands', help='command help')
    

    #
    # library  Command
    #

    library_parser(cmd)

    #
    # warehouse  Command
    #
    
    warehouse_parser(cmd)
 
    #
    # ckan Command
    #
    lib_p = cmd.add_parser('ckan', help='Access a CKAN repository')
    lib_p.set_defaults(command='ckan')
    lib_p.add_argument('-n','--name',  default='default',  help='Select the configuration name for the repository')
    asp = lib_p.add_subparsers(title='CKAN commands', help='Access a CKAN repository')
    
    sp = asp.add_parser('package', help='Dump a package by name, as json or yaml')
    sp.set_defaults(subcommand='package')   
    sp.add_argument('term', type=str,help='Query term')
    group = sp.add_mutually_exclusive_group()
    group.add_argument('-y', '--yaml',  default=True, dest='use_json',  action='store_false')
    group.add_argument('-j', '--json',  default=True, dest='use_json',  action='store_true')
    
    #
    # Install Command
    #
    lib_p = cmd.add_parser('install', help='Install configuration files')
    lib_p.set_defaults(command='install')
    asp = lib_p.add_subparsers(title='Install', help='Install configuration files')
    
    #
    # Config Command
    #
    sp = asp.add_parser('config', help='Install the global configuration')
    sp.set_defaults(subcommand='config')
    sp.add_argument('-p', '--print',  dest='prt', default=False, action='store_true', help='Print, rather than save, the config file')
    sp.add_argument('-f', '--force',  default=False, action='store_true', help="Force using the default config; don't re-use the xisting config")
    sp.add_argument('-r', '--root',  default=None,  help="Set the root dir")
    sp.add_argument('-R', '--remote',  default=None,  help="Url of remote library")


    source_parser(cmd)
   
    #
    # Remote Command
    #
    
    lib_p = cmd.add_parser('remote', help='Access the remote library')
    lib_p.set_defaults(command='remote')
    asp = lib_p.add_subparsers(title='remote commands', help='Access the remote library')
    lib_p.add_argument('-n','--name',  default='default',  help='Select a different name for the library, from which the remote is located')
 
    group = lib_p.add_mutually_exclusive_group()
    group.add_argument('-s', '--server',  default=False, dest='is_server',  action='store_true', help = 'Select the server configuration')
    group.add_argument('-c', '--client',  default=False, dest='is_server',  action='store_false', help = 'Select the client configuration')
        
    sp = asp.add_parser('info', help='Display the remote configuration')
    sp.set_defaults(subcommand='info')
    sp.add_argument('term',  nargs='?', type=str,help='Name or ID of the bundle or partition to print information for')
    
  
    sp = asp.add_parser('list', help='List remote files')
    sp.set_defaults(subcommand='list')
    sp.add_argument('-m','--meta', default=False,  action='store_true',  help="Force fetching metadata for remotes that don't provide it while listing, like S3")
    sp.add_argument('datasets', nargs=argparse.REMAINDER)
        
    sp = asp.add_parser('find', help='Search for the argument as a bundle or partition name or id')
    sp.set_defaults(subcommand='find')   
    sp.add_argument('term', type=str, nargs=argparse.REMAINDER,help='Query term')


    #
    # BigQuery
    #
    lib_p = cmd.add_parser('bq', help='BigQuery administration')
    lib_p.set_defaults(command='bq')
    asp = lib_p.add_subparsers(title='Bigquerry Commands', help='command help')
    
    sp = asp.add_parser('cred', help='Setup access credentials')
    sp.set_defaults(subcommand='cred')
    
    sp = asp.add_parser('list', help='List datasets')
    sp.set_defaults(subcommand='list')
          
    #
    # Test Command
    #
    lib_p = cmd.add_parser('test', help='Test and debugging')
    lib_p.set_defaults(command='test')
    asp = lib_p.add_subparsers(title='Test commands', help='command help')
    
    sp = asp.add_parser('config', help='Dump the configuration')
    sp.set_defaults(subcommand='config')
    group.add_argument('-v', '--version',  default=False, action='store_true', help='Display module version')
 
    sp = asp.add_parser('spatialite', help='Test spatialite configuration')
    sp.set_defaults(subcommand='spatialite')
         
    args = parser.parse_args()

    if args.single_config:
        if args.config is None or len(args.config) > 1:
            raise Exception("--single_config can only be specified with one -c")
        else:
            rc_path = args.config
    elif args.config is not None and len(args.config) == 1:
            rc_path = args.config.pop()
    else:
        rc_path = args.config
  
    funcs = {
        'library':library_command,
        'warehouse':warehouse_command,
        'remote':remote_command,
        'test':test_command,
        'install':install_command,
        'ckan':ckan_command,
        'source': source_command,
    }
        
    f = funcs.get(args.command, False)
        
    if f != install_command:
        rc = get_runconfig(rc_path)
        src = get_runconfig(rc_path, is_server = True)
    else:
        rc = None
        src = None
        
    global logger

    logger = get_logger("{}.{}".format(args.command,args.subcommand  ))
    logger.setLevel(logging.INFO) 


    if not f:
        err("Error: No command: "+args.command)
    else:
        try:
            f(args, rc, src)
        except KeyboardInterrupt:
            prt('\nExiting...')
            pass
Ejemplo n.º 3
0
def main(argsv = None, ext_logger=None):

    ##
    ## Hack -- set up the parser twice, so 'ambry --version' will work with no following command
    ##

    _first_arg_parse(argsv)

    ##
    ## Do it again.
    ##

    parser = argparse.ArgumentParser(prog='python -mdatabundles',
                                     description='Databundles {}. Management interface for ambry, libraries and repositories. '.format(
                                         __version__),
                                     prefix_chars='-+')


    parser.add_argument('-l', '--library', dest='library_name', default="default",
                        help="Name of library, from the library secton of the config")
    parser.add_argument('-c', '--config', default=None, action='append', help="Path to a run config file")
    parser.add_argument('-v', '--version', default=None, action="store_true", help="Display version")
    parser.add_argument('--single-config', default=False, action="store_true", help="Load only the config file specified")

    cmd = parser.add_subparsers(title='commands', help='command help')

    from .library import library_parser, library_command
    from .warehouse import warehouse_command, warehouse_parser
    from .remote import remote_parser,remote_command
    from test import test_parser, test_command
    from config import config_parser, config_command
    from ckan import ckan_parser, ckan_command
    from source import source_command, source_parser
    from bundle import bundle_command, bundle_parser
    from root import root_command, root_parser

    library_parser(cmd)  
    warehouse_parser(cmd)
    ckan_parser(cmd)
    source_parser(cmd)
    remote_parser(cmd)
    test_parser(cmd)
    config_parser(cmd)
    bundle_parser(cmd)
    root_parser(cmd)

    argsv = shlex.split(' '.join(argsv)) if argsv else None
    args = parser.parse_args(argsv)

    if args.version:
        import ambry
        import sys
        print ("Ambry {}".format(ambry.__version__))
        sys.exit(0)

    if args.single_config:
        if args.config is None or len(args.config) > 1:
            raise Exception("--single_config can only be specified with one -c")
        else:
            rc_path = args.config
    elif args.config is not None and len(args.config) == 1:
            rc_path = args.config.pop()
    else:
        rc_path = args.config
  
    funcs = {
        'bundle':bundle_command,
        'library':library_command,
        'warehouse':warehouse_command,
        'remote':remote_command,
        'test':test_command,
        'ckan':ckan_command,
        'source': source_command,
        'config': config_command,
        'root': root_command,

    }


    f = funcs.get(args.command, False)

    if args.command == 'config' and args.subcommand == 'install':
        rc = None
    else:
        rc = get_runconfig(rc_path)


    global logger


    if ext_logger:
        logger = ext_logger
    else:
        logger = get_logger("{}.{}".format(args.command, args.subcommand),
                            template="%(message)s")

    logger.setLevel(logging.INFO)

    if not f:
        fatal("Error: No command: "+args.command)
    else:
        try:
            f(args, rc)
        except KeyboardInterrupt:
            prt('\nExiting...')
            pass
Ejemplo n.º 4
0
def main(argsv=None, ext_logger=None):
    import ambry._meta
    import os
    import sys

    parser = argparse.ArgumentParser(
        prog='ambry',
        description='Ambry {}. Management interface for ambry, libraries and repositories. '.format(
            ambry._meta.__version__))

    parser.add_argument(
        '-l',
        '--library',
        dest='library_name',
        default="default",
        help="Name of library, from the library secton of the config")
    parser.add_argument(
        '-c',
        '--config',
        default=os.getenv(AMBRY_CONFIG_ENV_VAR),
        action='append',
        help="Path to a run config file. Alternatively, set the AMBRY_CONFIG env var")
    parser.add_argument(
        '--single-config',
        default=False,
        action="store_true",
        help="Load only the config file specified")
    parser.add_argument(
        '-E',
        '--exceptions',
        default=False,
        action="store_true",
        help="Show full exception trace on all exceptions")

    cmd = parser.add_subparsers(title='commands', help='command help')

    from .library import library_parser, library_command
    from .warehouse import warehouse_command, warehouse_parser
    from .remote import remote_parser, remote_command
    from test import test_parser, test_command
    from config import config_parser, config_command
    from ckan import ckan_parser, ckan_command
    from source import source_command, source_parser
    from bundle import bundle_command, bundle_parser
    from root import root_command, root_parser
    from ..dbexceptions import ConfigurationError

    library_parser(cmd)
    warehouse_parser(cmd)
    ckan_parser(cmd)
    source_parser(cmd)
    remote_parser(cmd)
    test_parser(cmd)
    config_parser(cmd)
    bundle_parser(cmd)
    root_parser(cmd)

    args = parser.parse_args()

    if args.single_config:
        if args.config is None or len(args.config) > 1:
            raise Exception(
                "--single_config can only be specified with one -c")
        else:
            rc_path = args.config
    elif args.config is not None and len(args.config) == 1:
        rc_path = args.config.pop()
    else:
        rc_path = args.config

    funcs = {
        'bundle': bundle_command,
        'library': library_command,
        'warehouse': warehouse_command,
        'remote': remote_command,
        'test': test_command,
        'ckan': ckan_command,
        'source': source_command,
        'config': config_command,
        'root': root_command,

    }

    global global_logger

    if ext_logger:
        global_logger = ext_logger
    else:
        name = "{}.{}".format(args.command, args.subcommand)
        global_logger = get_logger(name, template="%(levelname)s: %(message)s")

    global_logger.setLevel(logging.INFO)

    f = funcs.get(args.command, False)

    if args.command == 'config' and args.subcommand == 'install':
        rc = None
    else:
        try:
            rc = get_runconfig(rc_path)

        except ConfigurationError:
            fatal(
                "Could not find configuration file at {}\nRun 'ambry config install; to create one ",
                rc_path)

        global global_run_config
        global_run_config = rc

    if not f:
        fatal("Error: No command: " + args.command)
    else:
        try:
            f(args, rc)
        except KeyboardInterrupt:
            prt('\nExiting...')
            pass
        except ConfigurationError as e:
            if args.exceptions:
                raise
            fatal("{}: {}".format(str(e.__class__.__name__), str(e)))