Beispiel #1
0
def setup_argparser(name,
                    description,
                    command_line_options,
                    version=__VERSION__):
    parser = argparse.ArgumentParser(
        description='{} - {}'.format(name, description))
    parser.add_argument('-V',
                        '--version',
                        action='version',
                        version='{} {}'.format(name, version))
    parser.add_argument('-l',
                        '--log_file',
                        help='path to log file',
                        default=None)
    parser.add_argument('-L',
                        '--log_level',
                        help='define the log level',
                        choices=['DEBUG', 'INFO', 'WARNING', 'ERROR'],
                        default=None)
    parser.add_argument('-d',
                        '--debug',
                        action='store_true',
                        default=False,
                        help='print debug messages')
    parser.add_argument('-C',
                        '--config_file',
                        help='set path to config File',
                        default='{}/main.cfg'.format(get_config_dir()))
    parser.add_argument('FILE_PATH',
                        type=str,
                        help='Path to file that should be extracted')
    return parser.parse_args(command_line_options[1:])
Beispiel #2
0
def start_uwsgi_server(config_path=None):
    config_parameter = ' --pyargv {}'.format(
        config_path) if config_path else ''
    command = 'uwsgi --ini  {}/uwsgi_config.ini{}'.format(
        get_config_dir(), config_parameter)
    process = Popen(split(command), cwd=get_src_dir())
    return process
def start_uwsgi_server(config_path=None):
    config_parameter = ' --pyargv {}'.format(
        config_path) if config_path else ''
    p = Popen('(cd {} && uwsgi --ini  {}/uwsgi_config.ini{})'.format(
        get_src_dir(), get_config_dir(), config_parameter),
              shell=True)
    return p
def main():
    config = load_config('{}/main.cfg'.format(get_config_dir()))
    setup_logging(debug=False)

    input_dir = Path(config.get('unpack', 'data_folder'), 'input')
    input_file = list(input_dir.iterdir())[0]

    unpack(input_file, config)

    return 0
Beispiel #5
0
 def __init__(self, config=None, auth=True):
     self.config = config
     try:
         self.mongo_log_path = config['Logging']['mongoDbLogFile']
     except (KeyError, TypeError):
         self.mongo_log_path = '/tmp/fact_mongo.log'
     self.config_path = os.path.join(get_config_dir(), 'mongod.conf')
     self.mongo_db_file_path = get_mongo_path(self.config_path)
     logging.debug('Data Storage Path: {}'.format(self.mongo_db_file_path))
     create_dir_for_file(self.mongo_log_path)
     os.makedirs(self.mongo_db_file_path, exist_ok=True)
     self.start(_authenticate=auth)
Beispiel #6
0
def setup_argparse():
    parser = argparse.ArgumentParser()
    parser.add_argument(
        '-v',
        '--version',
        action='version',
        version='FACT User Management (FACTUM) {}'.format(__VERSION__))
    parser.add_argument('-C',
                        '--config_file',
                        help='set path to config File',
                        default='{}/main.cfg'.format(get_config_dir()))
    return parser.parse_args()
def _setup_argparser():
    parser = argparse.ArgumentParser(
        description="{} - {}".format(PROGRAM_NAME, PROGRAM_DESCRIPTION))
    parser.add_argument('-V',
                        '--version',
                        action='version',
                        version="{} {}".format(PROGRAM_NAME, PROGRAM_VERSION))
    parser.add_argument("-C",
                        "--config_file",
                        help="set path to config File",
                        default="{}/main.cfg".format(get_config_dir()))
    return parser.parse_args()
def main(args):
    config = load_config('{}/main.cfg'.format(get_config_dir()))
    setup_logging(debug=False)

    input_dir = Path(config.get('unpack', 'data_folder'), 'input')
    input_file = list(input_dir.iterdir())[0]

    unpack(input_file, config)

    if args.chown:
        output_dir = Path(config.get('unpack', 'data_folder'), 'files')
        return _change_owner_of_output_files(output_dir, args.chown)

    return 0
Beispiel #9
0
def _setup_argparser(name,
                     description,
                     command_line_options,
                     version=__VERSION__):
    '''
    Sets up an ArgumentParser with some default flags and parses
    command_line_options.

    :return: The populated namespace from ArgumentParser.parse_args
    '''

    parser = argparse.ArgumentParser(
        description='{} - {}'.format(name, description))
    parser.add_argument('-V',
                        '--version',
                        action='version',
                        version='{} {}'.format(name, version))
    parser.add_argument('-l',
                        '--log_file',
                        help='path to log file',
                        default=None)
    parser.add_argument('-L',
                        '--log_level',
                        help='define the log level',
                        choices=['DEBUG', 'INFO', 'WARNING', 'ERROR'],
                        default=None)
    parser.add_argument('-d',
                        '--debug',
                        action='store_true',
                        default=False,
                        help='print debug messages')
    parser.add_argument('-s',
                        '--silent',
                        action='store_true',
                        default=False,
                        help='don\'t log to command line')
    parser.add_argument('-C',
                        '--config_file',
                        help='set path to config File',
                        default='{}/main.cfg'.format(get_config_dir()))
    parser.add_argument('-t',
                        '--testing',
                        default=False,
                        action='store_true',
                        help='shutdown system after one iteration')
    return parser.parse_args(command_line_options[1:])
Beispiel #10
0
def _setup_argparser(name,
                     description,
                     command_line_options,
                     version=__VERSION__):
    parser = argparse.ArgumentParser(
        description='{} - {}'.format(name, description))
    parser.add_argument('-V',
                        '--version',
                        action='version',
                        version='{} {}'.format(name, version))
    parser.add_argument('-l',
                        '--log_file',
                        help='path to log file',
                        default=None)
    parser.add_argument('-L',
                        '--log_level',
                        help='define the log level',
                        choices=['DEBUG', 'INFO', 'WARNING', 'ERROR'],
                        default=None)
    parser.add_argument('-d',
                        '--debug',
                        action='store_true',
                        default=False,
                        help='print debug messages')
    parser.add_argument('-s',
                        '--silent',
                        action='store_true',
                        default=False,
                        help='don\'t log to command line')
    parser.add_argument('-C',
                        '--config_file',
                        help='set path to config File',
                        default='{}/main.cfg'.format(get_config_dir()))
    parser.add_argument('-t',
                        '--testing',
                        default=False,
                        action='store_true',
                        help='shutdown system after one iteration')
    # Convert argument strings to objects and assign them as attributes of the namespace. Return the populated namespace.
    # 解析输入参数
    # 例如运行./start_all_installed_components 输出结果为:
    # Namespace(config_file='/home/hui/A/FACT_clone_3.0/src/config/main.cfg', debug=False, log_file=None, log_level=None, silent=False, testing=False)
    return parser.parse_args(command_line_options[1:])
Beispiel #11
0
def _setup_argparser():
    parser = argparse.ArgumentParser(
        description='{} - {}'.format(PROGRAM_NAME, PROGRAM_DESCRIPTION))
    parser.add_argument('-V',
                        '--version',
                        action='version',
                        version='{} {}'.format(PROGRAM_NAME, PROGRAM_VERSION))
    parser.add_argument('-C',
                        '--config_file',
                        help='set path to config file',
                        default='{}/main.cfg'.format(get_config_dir()))
    parser.add_argument('-s',
                        '--shutdown_db',
                        action='store_true',
                        default=False,
                        help='shutdown mongo server after update')
    parser.add_argument('-d',
                        '--debug',
                        action='store_true',
                        default=False,
                        help='print debug messages')
    return parser.parse_args()
Beispiel #12
0
def _setup_argparser(name, description):
    parser = argparse.ArgumentParser(
        description='{} - {}'.format(name, description))
    parser.add_argument('-V',
                        '--version',
                        action='version',
                        version='{} {}'.format(name, __VERSION__))
    parser.add_argument('-l',
                        '--log_file',
                        help='path to log file',
                        default=None)
    parser.add_argument('-L',
                        '--log_level',
                        help='define the log level',
                        choices=['DEBUG', 'INFO', 'WARNING', 'ERROR'],
                        default=None)
    parser.add_argument('-d',
                        '--debug',
                        action='store_true',
                        default=False,
                        help='print debug messages')
    parser.add_argument('-s',
                        '--silent',
                        action='store_true',
                        default=False,
                        help='don\'t log to command line')
    parser.add_argument('-C',
                        '--config_file',
                        help='set path to config File',
                        default='{}/main.cfg'.format(get_config_dir()))
    parser.add_argument('-t',
                        '--testing',
                        default=False,
                        action='store_true',
                        help='shutdown system after one iteration')
    return parser.parse_args()
Beispiel #13
0
def test_get_config_dir():
    assert os.path.exists('{}/main.cfg'.format(get_config_dir())), 'main config file not found'
class ArgumentMock():
    config_file = '{}/main.cfg'.format(get_config_dir())
    log_level = 'WARNING'
    log_file = '/tmp/fact_test_log'
    silent = False
    debug = False
def test_load_config():
    config = load_config('{}/main.cfg'.format(get_config_dir()))
    assert config['ExpertSettings']['unpack_threshold'] == '0.8'
Beispiel #16
0
 def test_get_config_dir(self):
     from helperFunctions.config import get_config_dir
     self.assertTrue(os.path.exists('{}/main.cfg'.format(get_config_dir())), 'main config file not found')