Ejemplo n.º 1
0
    :copyright: © 2019 by the Choppy team.
    :license: AGPL, see LICENSE.md for more details.
"""

from __future__ import unicode_literals
import logging
import json
import os
import subprocess
import csv
import sys
from choppy import exit_code
from choppy.config import get_global_config

global_config = get_global_config()
module_logger = logging.getLogger(__name__)


class Validator:
    """Module to validate JSON inputs.
    """
    def __init__(self, wdl, json):
        self.wdl = os.path.abspath(wdl)
        self.json = os.path.abspath(json)
        womtool_path = global_config.get('general', 'womtool_path')
        if not womtool_path:
            raise Exception('You need to tell choppy-pipe where womtool is.')
        self.wdl_tool = os.path.abspath(womtool_path)
        self.logger = logging.getLogger('choppy.validator.Validator')
Ejemplo n.º 2
0
def parse_args():
    """parses and sets up the command line argument system above
    with config file parsing."""
    global parser, global_config, loglevel

    early_parser = argparse.ArgumentParser(
        description=__doc__,
        formatter_class=argparse.ArgumentDefaultsHelpFormatter,
        add_help=False)
    early_parser.add_argument('--config',
                              '-c',
                              type=os.path.exists,
                              action='store',
                              help='change default configuration location')
    group = early_parser.add_mutually_exclusive_group()
    group.add_argument('--debug',
                       action='store_true',
                       default=False,
                       help="Debug mode.")
    group.add_argument('-q',
                       '--quite',
                       action='store_true',
                       default=False,
                       help="Only display key message.")
    group.add_argument('-v',
                       '--verbose',
                       action='count',
                       default=0,
                       help='Increase output verbosity')

    args, remainder_argv = early_parser.parse_known_args()

    if args.debug:
        loglevel = logging.DEBUG
    elif args.verbose:
        verbose = args.verbose
        # Configure logger for requested verbosity.
        if verbose >= 3:
            loglevel = logging.SPAM
        elif verbose >= 2:
            loglevel = logging.DEBUG
        elif verbose >= 1:
            loglevel = logging.VERBOSE
    elif args.quite:
        loglevel = logging.ERROR

    set_logger('root', loglevel)

    # Override config file defaults if explicitly requested
    if args.config:
        init_config(config_file=args.config)
        global_config = get_global_config()
    else:
        init_config()
        global_config = get_global_config()

    if not (args.debug or args.verbose or args.quite):
        loglevel = global_config.get_loglevel('server', 'log_level')

    parser.add_argument('--handler',
                        action='store',
                        default='stream',
                        choices=('stream', 'file'),
                        help="Log handler, stream or file?")
    server = parser.add_argument_group()
    server.add_argument('-S',
                        '--server',
                        action='store',
                        default="localhost",
                        type=str,
                        choices=global_config.servers,
                        help='Choose a cromwell server from {}'.format(
                            global_config.servers))
    server.add_argument('-f',
                        '--framework',
                        action='store',
                        default='flask',
                        choices=['bjoern', 'gevent', 'flask'],
                        help='Run server with framework.')
    server.add_argument('-s',
                        '--swagger',
                        action='store_true',
                        default=False,
                        help="Enable swagger documentation.")
    server.set_defaults(func=call_server)

    argcomplete.autocomplete(parser)
    args = parser.parse_args(remainder_argv)

    return args