コード例 #1
0
    def make(cls):
        """Makes the conf object, merging in the following order:

            - ENV
            - default config: default.yml
            - stage config: {stage}.yml
            - remote config: remote_settings
        """
        anyconfig.merge(cls.conf, os.environ.copy())
        stage = cls.conf.get("stage", None)
        project_config_dir = cls.conf.get("project_config_dir", ".")

        project_default_config_file_path = os.path.join(
            project_config_dir, "default.yml")
        if os.path.exists(project_default_config_file_path):
            anyconfig.merge(cls.conf,
                            anyconfig.load(project_default_config_file_path))

        project_stage_config_file_path = os.path.join(project_config_dir,
                                                      f"{stage}.yml")
        if os.path.exists(project_stage_config_file_path):
            anyconfig.merge(cls.conf,
                            anyconfig.load(project_stage_config_file_path))
        remote_settings = cls.conf.get("use_remote_settings", None)
        if remote_settings:
            project_name = cls.conf.get("project_name", None)
            parameters_path = f"/{project_name}/{stage}/"
            remote_settings_class = cls.create_remote_settings_class()
            remote_conf = remote_settings_class.get_remote_params(
                parameters_path)
            anyconfig.merge(cls.conf, remote_conf)
コード例 #2
0
ファイル: test.py プロジェクト: jeremydeanw/LiveSimulation
def main():
    params_file = None
    if len(sys.argv) < 4:
        print('Usage: python test.py TEST_PARAMS_FILE DEFAULT_CONFIG_FILE NUM_ROUNDS')
        sys.exit(1)
    else:
        params_file = str(sys.argv[1])
        default_config = str(sys.argv[2])
        num_rounds = int(sys.argv[3])

    variable_params = anyconfig.load(params_file)
    default_config = anyconfig.load(default_config)

    configs = []
    for k, v in variable_params.items():
        if v is not None:
            options = v
            for option in options:
                new_config = copy.deepcopy(default_config)
                new_config[k] = option
                str_option = str(option)
                new_config['results_file'] = 'results_{}_{}.txt'.format(k, str_option.replace('.', '_'))
                new_config['num_rounds'] = num_rounds
                cs = anyconfig.dumps(new_config, ac_parser='yaml')
                configs.append(cs)

    pool = mp.Pool(processes=48)
    for config_str in configs:
        pool.apply_async(run_param_test, (config_str,))
    pool.join()
コード例 #3
0
def _is_project(project_path: Union[str, Path]) -> bool:
    metadata_file = Path(project_path).expanduser().resolve() / _PYPROJECT
    if not metadata_file.is_file():
        return False
    try:
        anyconfig.load(metadata_file)
    except Exception:  # pylint: disable=broad-except
        return False
    return True
コード例 #4
0
ファイル: __init__.py プロジェクト: lad1337/cec2mqtt
def load_config(path):
    default_configuration = anyconfig.load(resource_filename('cecmqtt.config', 'default.yaml'))
    try:
        config = anyconfig.load(path)
    except IOError:
        logger.warning("no config file found at: %s", path)
        config = {}
    config = default_configuration + AttrDict(config)
    return normalize_config(config)
コード例 #5
0
def init_config():
    getLogger(__name__).debug('Loading default configuration')
    cfg = load(_config_defaults,
               ignore_missing=False)
    getLogger(__name__).debug(f"Loading user configuration overrides {' '.join(_config_search)}")
    user_config = load(_config_search,
                       ac_merge=MS_REPLACE,
                       ignore_missing=True)
    merge(cfg, user_config)
    getLogger(__name__).debug(f"Configuration complete, dumping value")
    getLogger(__name__).debug(cfg)
    return cfg
コード例 #6
0
def _try_loads(files):
    for filepath in files:
        try:
            cnf = anyconfig.load(filepath, ac_parser="fortios")
            assert cnf

            exp_path = str(filepath).replace(".txt", ".json")
            ref = anyconfig.load(exp_path, ordered=True)

        except anyconfig.UnknownFileTypeError:
            print("all types=%r" % anyconfig.list_types())
            raise

        assert cnf == ref
コード例 #7
0
    def __init__(
        self,
        full_course: Path = Path("/app/head_chef/full_course.yaml")) -> None:
        """
        Give the Head Chef the instructions needed to prepare the full course

        i.e. Initialize the following from a YAML configuration file:
                - location (where to output the file)
                - python_format (the Python data type after processing)
                - file_format (the file format with which to save the data)

        Args:
            full_course (Path): A YAML file within the head_chef directory containing
                                the ingredients to prepare
        """
        sous_chef = SousChef()
        self.ingredients = sous_chef.prepare_ingredients()

        self.full_course = dict()
        self.tools = dict()

        # Load from full_course.yaml
        for key, value in anyconfig.load(full_course).items():
            self.full_course[key] = FullCourse(**value)

            # Find the right tool for the job (data saving)
            self.tools[key] = prepare_tools(
                python_format=self.full_course[key].python_format,
                file_format=self.full_course[key].file_format,
            )
コード例 #8
0
def render_secrets(
        config_path,
        secret_path,
):
    """combine a jinja template with a secret .ini file

    Args:
        config_path (str): path to .cfg file with jinja templating
        secret_path (str): path to .ini-like secrets file

    Returns:
        ProsperConfig: rendered configuration object

    """
    with open(secret_path, 'r') as s_fh:
        secret_ini = anyconfig.load(s_fh, ac_parser='ini')

    with open(config_path, 'r') as c_fh:
        raw_cfg = c_fh.read()

    rendered_cfg = anytemplate.renders(raw_cfg, secret_ini, at_engine='jinja2')

    p_config = ProsperConfig(config_path)
    local_config = configparser.ConfigParser()
    local_config.optionxform = str
    local_config.read_string(rendered_cfg)

    p_config.local_config = local_config

    return p_config
コード例 #9
0
ファイル: alerter.py プロジェクト: hanman18/chargers2
 def __init__(self):
    logging.basicConfig()
    self.logger = logging.getLogger()
    self.logger.setLevel(logging.INFO)
    self.garage_data = anyconfig.load("garage_data.json")['garage_data']
    self.sg = sendgrid.SendGridClient(SENDGRID_USERNAME, SENDGRID_PASSWORD)
    self.keen_client = None
コード例 #10
0
def load(filename, fpath=(), dpath=None, **kwds):
    '''Load a file and return its data structure.

    If dpath given, return substructure at that "path" in the
    resulting data structure.

    If filename is not absolute, it will be searched for first in the
    current working directory, then moo's built-in directory, then in
    any user-provided paths in "fpath" and finally in directories
    provided by moo.io.default_load_path.  The application is free to
    provide this fallback.  When moo is used from its CLI the
    MOO_LOAD_PATH environment variable is consulted.

    '''
    fmt = os.path.splitext(filename)[-1]

    paths = clean_paths(fpath) + list(default_load_path)
    filename = resolve(filename, paths)

    if fmt in (".jsonnet", ".schema"):
        data = moo.jsonnet.load(filename, paths, **kwds)
    elif fmt in (".csv", ):
        data = moo.csvio.load(filename, paths, **kwds)
    elif fmt in (".xls", ".xlsx"):
        data = moo.xls.load(filename, paths, **kwds)
    else:
        data = anyconfig.load(filename)
    if data is None:
        raise ValueError(f'no data from {filename}')
    if dpath:
        return select_path(data, dpath)
    return data
コード例 #11
0
ファイル: app.py プロジェクト: wearep3r/backplane
    def getAppURLs(self):
        app_config = anyconfig.load(
            os.path.join(self.destination, self.compose_file))

        protocol = "https" if self.config.https else "http"

        app_urls = []

        for service in app_config["services"]:
            service_name = service

            service_config = app_config["services"][service]

            if "labels" in service_config:

                for label in service_config["labels"]:
                    key, value = label.split("=")

                    if key == "backplane.enabled":
                        if value == "true":
                            if self.config.verbose > 0:
                                typer.secho(
                                    f"backplane enabled for service {service_name}",
                                    err=False,
                                    fg=typer.colors.BRIGHT_BLACK,
                                )
                            app_urls.append(
                                f"{protocol}://{service_name}.{self.config.domain}"
                            )

        return app_urls
コード例 #12
0
ファイル: cli.py プロジェクト: rji-futures-lab/Chatter
def load_config(config_dir=DEFAULT_CONFIG_DIRECTORY, config_override_file=None):
    try:
        config_files = [os.path.join(config_dir, DEFAULT_CONFIG_FILE)]
        if config_override_file is not None:
            config_files.append(os.path.join(config_dir, config_override_file))
        fconfig = anyconfig.load(config_files, ac_parser="yaml")
        db_settings = fconfig['db']
        # Set the DB configuration
        config.db_name = db_settings['name']
        config.db_user = db_settings['user']
        config.db_password = db_settings['password']
        config.db_min_conn = db_settings['min_conn']
        config.db_max_conn = db_settings['max_conn']
        config.db_port = db_settings['port']
        config.db_host = db_settings['host']
        # Set the Twitter configuration
        twitter_settings = fconfig['twitter']
        config.twitter_screen_name = twitter_settings['screen_name']
        config.twitter_consumer_key = twitter_settings['consumer_key']
        config.twitter_consumer_secret = twitter_settings['consumer_secret']
        config.twitter_access_token_key = twitter_settings['access_token_key']
        config.twitter_access_token_secret = twitter_settings['access_token_secret']
        # Set the Calais configuration information
        calais_settings = fconfig['calais']
        config.calais_api_token = calais_settings['api_token']
        # Set the chatter app configurations
        if fconfig.get('domains_to_ignore', None) is not None:
            config.domains_to_ignore = fconfig['domains_to_ignore']
    except Exception as e:
        print('Unable to load configuration file make sure your config.yaml exists and is accessible.')
        print(e)
        exit(1)
コード例 #13
0
ファイル: conf.py プロジェクト: robotice/robotice
    def actuators(self):
        """return actuators for all systems, with added `system_name` variable"""
        
        actuators = []

        systems = anyconfig.load([self.systems.config_path, self.devices.config_path], merge=anyconfig.MS_DICTS)

        for system_name, system in self.systems.list().iteritems():
            for uuid, actuator in system.get('actuators').iteritems():

                actuator["id"] = uuid
                actuator['system_name'] = system_name
                actuator['system_plan'] = system.get('plan')

                plan = self.__get_plan(actuator)
                if not plan:
                    LOG.error("missing plan for %s object: %s" % (uuid,actuator))
                    continue
                actuator["plan_full"] = plan
                actuator["plan_name"] = plan["name"]
                actuators.append(actuator)

        LOG.debug(actuators)

        return actuators
コード例 #14
0
    def test_10_render_to(self):
        ctx = A.load(_CONFFILE_0)
        tmpl = _TMPL_0
        output = os.path.join(self.workdir, "tmpl.out")

        TT.render_to(tmpl, ctx, output, self.tpaths)
        self.assertTrue(os.path.exists(output))
コード例 #15
0
ファイル: whiriho.py プロジェクト: rmedaer/whiriho
    def load(self):
        """
        Load Whiriho catalog.
        """
        try:
            # Open and parse catalog (in forced format or by analyzing file extension)
            data = anyconfig.load(self.path, ac_parser=self.forced_format)

            # Validate generic catalog version. We only accept version 1.x.x
            jsonschema.validate(data, __whiriho_catalog__)

            # Analyze catalog version.
            self.version = Whiriho.parse_version(data['version'])

            # Parse catalog in version 1
            if self.version.major == 1:
                jsonschema.validate(data, __whiriho_catalog_v1__)
                self.catalog = data['catalog']
            else:
                raise CatalogVersionException(
                    'Whiriho (%s) cannot use catalog version %s' %
                    (__version__, self.version))
        except (jsonschema.ValidationError,
                anyconfig.UnknownFileTypeError) as error:
            raise CatalogFormatException('Invalid catalog format: %s' %
                                         error.message)
        except jsonschema.SchemaError:
            raise AssertionError('Internal library error; invalid schema')
        except IOError:
            raise CatalogNotFoundException(
                'Failed to load configuration catalog')
コード例 #16
0
def get_news_dict(ts=None):
        """Returns a dict containing list of editorials after timestamp ts. By
        default, the difference is mentioned as 'default_offset' in data.yml."""

        # Getting url of the api to call from data.yml file
        config = anyconfig.load('data.yml')
        if config is None or 'baseurl' not in config or 'default_offset' not in config:
                print "Error parsing yaml"
                return None

        baseurl = config['baseurl']
        listurl = baseurl + '/api/list'

        # Getting timestamp of default offset as mentioned in data.yml
        if ts is None:
                doff = config['default_offset']
                now = datetime.now()
                prev = now - timedelta(doff)
                ts = (prev - datetime(1970, 1, 1)).total_seconds()

        # Adding the timestamp to payload
        payload = {}
        payload['timestamp'] = ts

        # Sending the request
        resp = requests.post(listurl, data=payload)

        # Analysing the response
        if resp.status_code != 200:
                print "Error received : " + str(resp.status_code)
                return None
        else:
                cntnt = json.loads(resp.content)
                return cntnt
コード例 #17
0
ファイル: train.py プロジェクト: JessicaAuditore/DBNet
def main():
    import sys
    import pathlib

    __dir__ = pathlib.Path(os.path.abspath(__file__))
    sys.path.append(str(__dir__))
    sys.path.append(str(__dir__.parent.parent))

    from models import build_model, build_loss
    from data_loader import get_dataloader
    from utils import Trainer
    from utils import get_post_processing
    from utils import get_metric

    config = anyconfig.load(open('config.yaml', 'rb'))
    train_loader = get_dataloader(config['dataset']['train'])
    validate_loader = get_dataloader(config['dataset']['validate'])
    criterion = build_loss(config['loss']).cuda()
    model = build_model(config['arch'])
    post_p = get_post_processing(config['post_processing'])
    metric = get_metric(config['metric'])

    trainer = Trainer(config=config,
                      model=model,
                      criterion=criterion,
                      train_loader=train_loader,
                      post_process=post_p,
                      metric_cls=metric,
                      validate_loader=validate_loader)
    trainer.train()
コード例 #18
0
ファイル: worker.py プロジェクト: eiwill/backend
def load_config(options):
    conf = anyconfig.load(options.config_file, "json")
    for i, value in vars(options).iteritems():
        if value is not None and i in conf:
            conf[i] = value

    return conf
コード例 #19
0
def main(argv):
    args = parser.parse_args(argv)
    employee_timelogs = []
    for timelogs_file in args.files:
        print 'processing %s' % timelogs_file.name
        employee_timelogs.append(Timelogs(timelogs_file))
    for t in employee_timelogs:
        print '############# START #############'
        t.pretty_print()
        print '############## END ##############'
    print '############ SUMMARRY #############'
    for t in employee_timelogs:
        t.print_summary()
    print '############ END SUMMARRY #############'
    if args.subcommand == 'freshbooks':
        home = os.path.expanduser('~')
        config_path = os.path.join(home, '.timelogparser.json')
        freshbooks_config = anyconfig.load([config_path], merge=anyconfig.MS_DICTS_AND_LISTS)
        freshbooks_args = {'freshbooks': {}}
        if args.endpoint:
            freshbooks_args['freshbooks'].update({'endpoint': args.endpoint})
        if args.token:
            freshbooks_args['freshbooks'].update({'token': args.token})
        freshbooks_config.update(freshbooks_args, anyconfig.MS_DICTS_AND_LISTS)
        if raw_input("send to freshbooks? ").lower().startswith('y'):
            freshbooks_client = api.TokenClient(freshbooks_config['freshbooks']['endpoint'], 
                freshbooks_config['freshbooks']['token'], 
                user_agent='github/radeinla/timelogparser')
            send_to_freshbooks(employee_timelogs, args.client_id, freshbooks_client)
コード例 #20
0
ファイル: config.py プロジェクト: wearep3r/backplane
    def write(self, custom_config: dict = None):
        # Note: this is only dealing with user config
        if not os.path.exists(self.config_path):
            # Create an empty config
            with open(self.config_path, "a"):
                os.utime(self.config_path, None)
        try:
            if not custom_config:
                backplane_config = anyconfig.loads(
                    json.dumps(self.toDict()), ac_parser="json"
                )
            else:
                # Only write user config, not the whole thing
                user_config = anyconfig.load([str(self.config_path)])
                anyconfig.merge(user_config, self.toDict(custom_config))
                backplane_config = user_config
            # anyconfig.merge(backplane_config, config)
            # if os.path.exists(config_path):

            # Open ~/.backplane/contexts/default/backplane.yml
            # Save config as yml

            with open(self.config_path, "w+") as writer:
                writer.write(anyconfig.dumps(backplane_config, ac_parser="yaml"))

            return backplane_config
        except OSError as e:
            raise ConfigNotFound(e)
コード例 #21
0
 def __init__(self):
     currentDir = os.path.dirname(os.path.realpath(__file__))
     configFile = currentDir + "/../" + self.CONFIG_FILE
     conf = anyconfig.load(configFile)
     bconf = bunch.bunchify(conf)
     self.ttsWatson = TtsWatson(bconf.user, bconf.password, bconf.voice,
                                bconf.url, bconf.chunk)
コード例 #22
0
ファイル: eval_net.py プロジェクト: zhangxiao339/MASTER-TF
    def checkpoint_to_saved_model(cls, ckpt_dir: str, config_file: str,
                                  output_path: str):
        cfg = anyconfig.load(config_file)
        config = EasyDict(cfg)

        model = MasterModel(
            config.model, dataset_utils.LabelTransformer.nclass,
            (config.dataset.train.width, config.dataset.train.height))

        checkpoint = tf.train.Checkpoint(model=model)
        status = checkpoint.restore(ckpt_dir)
        status.expect_partial()

        model([
            tf.random.normal([1, 48, 160, 1], dtype=tf.float32, name='image'),
            tf.constant(np.ones([1, 52]), dtype=tf.int32, name='transcript')
        ])
        signatures = {
            'decode':
            model.decode.get_concrete_function(
                tf.TensorSpec([None, 48, 160, 1],
                              dtype=tf.float32,
                              name='image'))
        }
        tf.saved_model.save(model, output_path, signatures=signatures)
        print('Model is saved at {}'.format(output_path))
コード例 #23
0
ファイル: config.py プロジェクト: yavin5/pyutrack
 def __load(self):
     if not os.path.isfile(self.__path):
         return
     self.__config = anyconfig.load(
         self.__path,
         ac_parser=not os.path.splitext(self.__path)[1]
         and 'ini').get('pyutrack', {})
コード例 #24
0
def load(path=None, with_defaults=False, validate=False):
    """
    Load the configuration.

    :param str path: configuration file path. If set to `None`, it makes the configuration file optional, meaning
        that either only the defaults will be loaded or that the configuration will be empty. Otherwise the
        loading will fail if the file is not found.
    :param bool with_defaults: if `True`, loads the default values when they are not specified in the configuration file
    :param bool validate: if `True`, validates the configuration. If an error is detected, a `SyntaxError`
        will be raised. The error message should indicate which part of the configuration file was invalid.
    :returns: (dict) A dictionary representing the configuration.
    """
    # Prepare the configuration dictionary, with the default values if requested.
    conf = CONFIGURATION_DEFAULTS if with_defaults else {}

    # Load the configuration file if specified.
    conf_from_file = {} if path is None else anyconfig.load(path)

    # Merge the configuration into the dictionary containing the defaults.
    # If `with_defaults` is False, this step simply loads the configuration file.
    anyconfig.merge(conf, conf_from_file)

    # Validate the configuration.
    if validate:
        (rc, err) = anyconfig.validate(conf, CONFIGURATION_SCHEMA)
        if not rc:
            raise SyntaxError(err)

    return conf
コード例 #25
0
ファイル: alerter.py プロジェクト: ndd314/chargers2
 def __init__(self):
     logging.basicConfig()
     self.logger = logging.getLogger()
     self.logger.setLevel(logging.INFO)
     self.garage_data = anyconfig.load("garage_data.json")['garage_data']
     self.sg = sendgrid.SendGridClient(SENDGRID_USERNAME, SENDGRID_PASSWORD)
     self.keen_client = None
コード例 #26
0
ファイル: templates.py プロジェクト: ssato/miniascape
    def test_10_render_to(self):
        ctx = A.load(_CONFFILE_0)
        tmpl = _TMPL_0
        output = os.path.join(self.workdir, "tmpl.out")

        TT.render_to(tmpl, ctx, output, self.tpaths)
        self.assertTrue(os.path.exists(output))
コード例 #27
0
    def _load_config_file(config_file: Path) -> Dict[str, Any]:
        """Load an individual config file using `anyconfig` as a backend.

        Args:
            config_file: Path to a config file to process.

        Raises:
            BadConfigException: If configuration is poorly formatted and
                cannot be loaded.

        Returns:
            Parsed configuration.
        """
        # for performance reasons
        import anyconfig  # pylint: disable=import-outside-toplevel

        try:
            # Default to UTF-8, which is Python 3 default encoding, to decode the file
            with open(config_file, encoding="utf8") as yml:
                return {
                    k: v
                    for k, v in anyconfig.load(yml).items()
                    if not k.startswith("_")
                }
        except AttributeError as exc:
            raise BadConfigException(
                f"Couldn't load config file: {config_file}"
            ) from exc
コード例 #28
0
ファイル: __main__.py プロジェクト: HomeHabbit/tts-watson
def main():
    requests.packages.urllib3.disable_warnings()
    defaultConfig = {
        'url': 'https://stream.watsonplatform.net/text-to-speech/api',
        'user': '******',
        'password': '******',
        'voice': 'en-US_AllisonVoice',
        'chunk': 2048
    }
    home = os.path.expanduser("~")
    defaultConfigFile = home + '/.config-tts-watson.yml'
    parser = argparse.ArgumentParser(
        description='Text to speech using watson')

    parser.add_argument('-f', action='store', dest='configFile', default=defaultConfigFile,
                        help='config file',
                        required=False)
    parser.add_argument('text_to_transform', action='store', nargs='+')
    args = parser.parse_args()
    conf = anyconfig.container(defaultConfig)
    if not os.path.isfile(args.configFile):
        print "Config file '" + args.configFile + "' doesn't exist."
        print "Creating it ..."
        user = raw_input("Watson user: "******"Watson password: "******" ".join(args.text_to_transform))
コード例 #29
0
ファイル: run.py プロジェクト: kpj/project_manager
def main(config_path: str, dry: bool):
    config = load_config(config_path)

    for entry in tqdm(
        os.scandir(config['working_dir']),
        total=len(os.listdir(config['working_dir']))
    ):
        if not entry.name.startswith(f'run{SECTION_SEPARATOR}'):
            continue

        # switch to correct directory
        print(entry.name)
        wd = os.getcwd()
        os.chdir(entry.path)

        # load config
        conf_name = (TEMP_CONFIG_NAME
                     if config['base_config'] is None
                     else os.path.basename(config['base_config']))
        cur_config = anyconfig.load(conf_name)

        # execute commands
        for cmd in config['exec_command']:
            cmd_mod = cmd.format(**cur_config)

            print(f' > {cmd_mod}')
            if not dry:
                os.system(cmd_mod)

        os.chdir(wd)
コード例 #30
0
    def test_10_get_or_upload_networks(self):
        for fpath in self.net_files:
            fname = os.path.basename(fpath)
            headers = {"content-type": "application/json"}

            content = open(fpath).read()
            opath = nof.utils.uploaded_filepath(fname,
                                                TT.FT_NETWORKS,
                                                content=content)
            nof.utils.ensure_dir_exists(opath)

            upath = os.path.join(TT.API_PREFIX, fname)
            resp = self.client.post(upath, data=content, headers=headers)

            self.assertStatus(resp, 201, resp.data)

            self.assertTrue(os.path.exists(opath))

            odata = anyconfig.load(opath)
            self.assertTrue(odata.get("nodes", False))
            self.assertTrue(odata.get("links", False))

            fname = os.path.basename(opath)  # Updated filename
            upath = os.path.join(TT.API_PREFIX, fname)
            resp = self.client.get(upath)

            self.assert200(resp,
                           _err_msg(resp, "path: " + upath, "file: " + opath))
            self.assertEqual(resp.data, content.encode("utf-8"))
コード例 #31
0
    def __init__(self):
        self.webcam = self.videocapture()
        self.ip_url = "http://192.168.43.67:8080/shot.jpg"
        self.height_window = 680
        self.width_window = 1540
        self.window = self.create_window()
        self.canvas = self.create_canvas()
        self.button = self.create_button()
        self.photo = None
        self.count = 0
        self.frame_save = None
        self.yolomodel = Yolo_opencv()
        self.segmentation_image = None
        self.segmentation = SegmentCharacter()
        cfg = anyconfig.load("config_Cnn.yaml")
        cfg = munch.munchify(cfg)
        self.recognition = ClassifyService(cfg)
        self.bboxes_yolo = None
        self.image_result_yolo = None
        self.lp_recognition = None
        self.tesseract = TesseractRecognition()
        #Option
        self.type_camera = "IP"  #default "IP"
        self.modelRecognition = "Segmentation Recognition"  #default "Segmentation Recognition"
        #Database
        self.database = MySQL_Database()

        # Label Tkinter
        self.label_lp = None
コード例 #32
0
ファイル: config.py プロジェクト: olivierh59500/fibratus
 def __init__(self, config_path=None):
     path = os.getenv('FIBRATUS_CONFIG_PATH', __DEFAULT_CONFIG_PATH__)
     path = config_path or path
     try:
         self._yaml = anyconfig.load(path, ignore_missing=False)
     except FileNotFoundError:
         panic('ERROR - %s configuration file does not exist' % path)
コード例 #33
0
ファイル: templates.py プロジェクト: orimanabu/miniascape
    def test_10_renderto_sync(self):
        ctx = A.load(_CONFFILE_0)
        tmpl = _TMPL_0
        output = os.path.join(self.workdir, "tmpl.out")

        TT.renderto(self.tpaths, ctx, tmpl, output, ask=True, async=False)
        self.assertTrue(os.path.exists(output))
コード例 #34
0
    def parse(self, config_file=None, specs=None, default_file=None):
        """Read a config_file, check the validity with a JSON Schema as specs
        and get default values from default_file if asked.

        All parameters are optionnal.

        If there is no config_file defined, read the venv base
        dir and try to get config/app.yml.

        If no specs, don't validate anything.

        If no default_file, don't merge with default values."""

        self._config_exists(config_file)
        self._specs_exists(specs)

        self.loaded_config = anyconfig.load(self.config_file, ac_parser='yaml')

        if default_file is not None:
            self._merge_default(default_file)

        if self.specs is None:
            return self.loaded_config

        self._validate()

        return self.loaded_config
コード例 #35
0
    def get_config(cls, domain=None):
        conf_path = os.path.abspath(
            os.path.join(cls.get_current_project(), cls.config_path))

        if not os.path.exists(conf_path):
            print "config does not exists in {0}".format(conf_path)

        try:
            print conf_path
            conf = anyconfig.load(conf_path, "toml")

            if domain is not None:
                for k in domain.split("."):
                    conf = conf[k]

            return conf

        except Exception as e:
            import traceback
            print traceback.format_exc()

            if "Reserved escape sequence used" in e:
                print u"不正な文字(おそらくパス名にバックスラッシュ)が使用されています".encode('cp932')
                print conf_path

            return None
コード例 #36
0
def _load_file(path):
    if anyconfig:
        # Note: anyconfig v0.11.0 parses ac_template=False as positive (fixed in v0.11.1).
        # https://github.com/ssato/python-anyconfig/pull/126
        return anyconfig.load(path, ac_template=False)
    else:
        with open(path, "r") as reader:
            return json.load(reader)
コード例 #37
0
    def __init__(self, config_file=None):
        """Construct an instance of the Config object."""
        config_list = [os.path.join(sys.path[0], "config_default.yml")]

        if config_file:
            config_list.append(config_file)

        self.config = anyconfig.load(config_list)
コード例 #38
0
def test_dataset():
    config = anyconfig.load(
        '/home/luning/dev/projects/master-tf/configs/master.yaml')
    config = easydict.EasyDict(config)
    train_ds, eval_ds = get_dataset(config)
    #ds = dataset.LMDBDataset("/home/luning/dev/data/SynthText800k/synth_lmdb", 100, 48)
    for index, v in enumerate(eval_ds):
        print(index)
コード例 #39
0
def load(path: Path, ftype: typing.Optional[str] = None) -> FileContentType:
    """
    :param path: The path to target object
    :param filetype: Expected file type, e.g. yaml and json

    :return: Loaded content as str or an (maybe mapping) object
    """
    return anyconfig.load(path, ac_parser=ftype)
コード例 #40
0
    def _merge_default(self, default_file: str) -> None:
        if not os.path.isfile(default_file):
            raise IOError("Your default ({}) does not exist".format(default_file))

        default_config = anyconfig.load(default_file)
        anyconfig.merge(default_config, self.loaded_config)

        self.loaded_config = default_config
コード例 #41
0
ファイル: config.py プロジェクト: davidmcclure/hathi-mpi
    def read(self):

        """
        Load the configuration files, set globals.
        """

        # Parse the configuration.
        self.config = anyconfig.load(self.paths, ignore_missing=True)
コード例 #42
0
ファイル: web.py プロジェクト: robbwagoner/zookeeper_monitor
    def load_config_from_file(self, config_file, force_format=None):
        """ Load config from file

        Args:
            config_file: Config's filename to be loaded
            f: Force config format ex. yaml, json
        """
        data = anyconfig.load(config_file, force_format)
        self.set_cluster(data)
コード例 #43
0
    def __init__(self, paths):
        """Initialize the configuration object.

        Args:
            paths (list): YAML paths, from most to least specific.
        """
        config = anyconfig.load(paths, ignore_missing=True)

        return super().__init__(config)
コード例 #44
0
ファイル: templates.py プロジェクト: orimanabu/miniascape
    def test_12_renderto_async(self):
        ctx = A.load(_CONFFILE_0)
        tmpl = _TMPL_0
        output = os.path.join(self.workdir, "tmpl.out")

        job = TT.renderto(self.tpaths, ctx, tmpl, output, ask=False,
                          async=True)
        TT.finish_renderto_procs([job])
        self.assertTrue(os.path.exists(output))
コード例 #45
0
 def _load_helper(self, **kwargs):
     try:
         anyconfig.api.load_plugins()
         return anyconfig.load(self.conf_path, **kwargs)
     except anyconfig.UnknownFileTypeError:
         for psr in anyconfig.api.Parsers().list():
             print("%r: type=%r, exts=%r" % (psr, psr.type(),
                                             psr.extensions()))
         raise
コード例 #46
0
ファイル: config.py プロジェクト: samzhang111/osp
    def read(self):

        """
        Load the configuration files, set connections.
        """

        self.config = anyconfig.load(self.paths, ignore_missing=True)
        self.es = self.get_es()
        self.rq = self.get_rq()
コード例 #47
0
ファイル: config.py プロジェクト: rabbitstack/fibratus
 def load(self, validate=True):
     schema_file = os.path.join(sys._MEIPASS, 'schema.yml') \
         if hasattr(sys, '_MEIPASS') else self._default_schema_path
     try:
         self._yaml = anyconfig.load(self.path, ignore_missing=False)
     except FileNotFoundError:
         panic('ERROR - %s configuration file does not exist' % self.path)
     if validate:
         validator = Core(source_file=self.path, schema_files=[schema_file])
         validator.validate(raise_exception=True)
コード例 #48
0
ファイル: runlevel.py プロジェクト: brennv/sos-analyzer
    def test_40_run(self):
        for sc in self.scanners:
            sc.run()

            # pylint: disable=maybe-no-member
            outfile = sc._mk_output_path(sc.inputs)
            # print >> open("/tmp/t.log", 'a'), "outfile=" + outfile
            self.assertTrue(os.path.exists(outfile))

            x = anyconfig.load(outfile)
            self.assertTrue(x.get("data", None), str(x))
コード例 #49
0
    def load_guest_confs(self, name, group=None):
        """
        :param name: Guest's name, e.g. satellite-1
        :param group: Guest's group, e.g. satellite
        """
        confs = self.list_guest_confs(name, group)

        logging.info("Loading guest configs: %s", name)
        c = anyconfig.load(confs, ac_template=True)

        return _add_special_confs(_guest_add_missings(c))
コード例 #50
0
ファイル: __init__.py プロジェクト: alisaifee/sifr
 def convert(self, value, param, ctx):
     fp = super(AnyConfigType, self).convert(value, param, ctx)
     try:
         config = anyconfig.load(fp.name)
         if not config:
             raise ValueError
         return config
     except ValueError:
         self.fail(
             'Could not load configuration from file: %s.'
             'It must be one of yaml/ini/json' % (fp.name)
         )
コード例 #51
0
ファイル: config.py プロジェクト: jiangzhw/OpenTAXII
    def __init__(self, optional_env_var=CONFIG_ENV_VAR):

        config_paths = [DEFAULT_CONFIG]

        env_var_path = os.environ.get(optional_env_var)
        if env_var_path:
            config_paths.append(env_var_path)

        options = anyconfig.load(config_paths, forced_type='yaml',
                ignore_missing=False, merge=anyconfig.MS_REPLACE)

        self.update(options)
コード例 #52
0
ファイル: site.py プロジェクト: orimanabu/miniascape
    def test_10_gen_site_conf_files(self):
        conf = anyconfig.load(CTXS)
        tmpldirs = [TMPLDIR]

        confdir = TT.gen_site_conf_files(conf, tmpldirs, self.workdir)

        dirs = ["common", "guests.d", "host.d", "networks.d"]
        for d in dirs:
            d = os.path.join(self.workdir, "default", d)
            self.assertTrue(os.path.exists(d), "dir=" + d)

        self.assertEquals(confdir, os.path.join(self.workdir, "default"))
コード例 #53
0
ファイル: config.py プロジェクト: orimanabu/miniascape
    def load_guest_confs(self, name, group=None):
        """
        :param name: Guest's name, e.g. satellite-1
        :param group: Guest's group, e.g. satellite
        """
        confs = self.list_guest_confs(name, group)

        logging.info("Loading guest config files: " + name)
        logging.debug("Configs: " + str(confs))
        c = anyconfig.load(confs)

        return _add_special_confs(_guest_add_missings(c))
コード例 #54
0
ファイル: cli.py プロジェクト: brennv/sos-analyzer
def main(argv=sys.argv):
    p = option_parser()
    (options, args) = p.parse_args(argv[1:])

    sos_analyzer.utils.set_loglevel(options.loglevel)

    if not args:
        p.print_usage()
        return -1

    conf = anyconfig.load(options.conf) if options.conf else None

    if options.workdir:
        LOGGER.info("Try using working dir: %s", options.workdir)
        sos_analyzer.utils.setup_workdir(options.workdir)
    else:
        options.workdir = sos_analyzer.utils.setup_workdir()
        LOGGER.info("Created working dir: %s", options.workdir)

    tarfile = args[0]
    datadir = os.path.join(options.workdir, DATA_SUBDIR)

    if not os.path.exists(datadir):
        LOGGER.info("Create datadir: %s", datadir)
        os.makedirs(datadir)

    d = sos_analyzer.utils.find_dir_has_target(datadir, "sos_commands")
    if d:
        LOGGER.info("sosreport archive looks already extracted in %s", d)
        datadir = d
    else:
        LOGGER.info("Extract sosreport archive %s to %s", tarfile, datadir)
        sos_analyzer.archive.extract_archive(tarfile, datadir)

        d = sos_analyzer.utils.find_dir_has_target(datadir, "sos_commands")
        if d:
            LOGGER.info("Set datadir to %s", d)
            datadir = d
        else:
            LOGGER.error("No sosreport data found under %s", d)
            return -1

    sos_analyzer.runner.run_scanners(options.workdir, datadir, conf)

    if options.analyze:
        sos_analyzer.runner.run_analyzers(options.workdir, datadir, conf)
        sos_analyzer.runner.dump_collected_results(options.workdir)

        if options.report:
            sos_analyzer.runner.run_report_generators(options.workdir,
                                                      options.conf)

    return 0
コード例 #55
0
def main(argv=sys.argv):
    if len(argv) < 5:
        print("Usage: %s TEMPLATE_FILE CONTEXT_FILE OUTPUT_FILE TPATHS" % argv[0])
        sys.exit(-1)

    (template, context_f, output, paths) = argv[1:5]
    tpaths = paths.split(':')
    context = anyconfig.load(context_f)

    anytemplate.render_to(template, context, output, at_paths=tpaths,
                          at_engine="jinja2", at_ask_missing=True,
                          extensions=_JINJA2_EXTS)
コード例 #56
0
def main():
    defaultConfig = {
        'url': 'https://gateway.watsonplatform.net/dialog/api',
        'user': '******',
        'password': '******',
    }
    home = os.path.expanduser("~")
    defaultConfigFile = home + '/.config-dialog-watson.yml'
    parser = argparse.ArgumentParser(
        description='Text to speech using watson')

    parser.add_argument('-f', action='store', dest='configFile', default=defaultConfigFile,
                        help='config file',
                        required=False)
    parser.add_argument('dialog_file', action='store', nargs=1)
    parser.add_argument('-n', '--name', dest='dialog_name', action='store', help='Dialog name', required=True)
    parser.add_argument('--clean', dest='clean', action='store_true')
    args = parser.parse_args()
    dialog_file = "".join(args.dialog_file)
    conf = anyconfig.container(defaultConfig)
    if not os.path.isfile(args.configFile):
        print "Config file '" + args.configFile + "' doesn't exist."
        print "Creating it ..."
        user = raw_input("Watson user: "******"Watson password: "******"".join(args.dialog_name), bconf.url,
                          os.path.dirname(dialog_file) + "/dialog_id_file.txt")
    if args.clean:
        watsonClient.clean_dialogs()

    resp = watsonClient.start_dialog()
    print ''
    print bcolors.WARNING + "Watson: " + bcolors.OKBLUE + "\n".join(resp.response) + bcolors.ENDC
    while True:
        userResponse = raw_input(bcolors.WARNING + "You: " + bcolors.OKGREEN)
        resp = watsonClient.converse(userResponse)
        print bcolors.WARNING + "Watson: " + bcolors.OKBLUE + "\n".join(resp.response) + bcolors.ENDC
        if userResponse == "bye":
            break
    print ""
    print "Your profile:"
    for name, value in watsonClient.get_profile().get_data().iteritems():
        print "\t" + name + ": " + value
    if __name__ == "__main__":
        main()
コード例 #57
0
ファイル: manifest.py プロジェクト: invenia/shepherd
    def load(self, filename):
        """
        Handles the actual loading and preporcessing of files.

        Args:
            filename (str): the file to load.
        Returns:
            collection: returns load collection and all recusively loaded ones.
        """
        try:
            realname = os.path.realpath(filename)
            working_path = os.path.dirname(realname)

            with working_directory(working_path):
                data = anyconfig.load(realname, safe=True)

                assert isinstance(data, dict)

                if 'includes' in data:
                    include_data = {}

                    # Iterate through the includes in order merging
                    # the dictionaries.  NOTE: Ordering matters here.
                    for include_file in data['includes']:
                        # Dict entries in new include file can override entries
                        # already in include_data.
                        sub = self.load(include_file)

                        if sub:
                            if include_data:
                                include_data.update(sub)
                            else:
                                include_data = sub

                    # Finally, merge the include data with our data
                    # our data will take priority in the merge if
                    # duplicate keys are found.
                    if include_data:
                        include_data.update(data)
                        data = include_data

                return data
        except ValueError as exc:
            # If we get a ValueError while building up
            # the dict, rethrow the error but supply the
            # filename it failed on.
            raise ValueError(
                '{} file {}'.format(
                    exc.message,
                    os.path.realpath(filename)
                )
            )
コード例 #58
0
ファイル: mod.py プロジェクト: ssato/python-anyconfig
    def test_10_dump_and_load(self):
        obj = dict(name="a", a=1, b=dict(b=[1, 2], c="C"))
        obj_path = os.path.join(self.workdir, "a.json")

        TT.dump(obj, obj_path)
        self.assertTrue(os.path.exists(obj_path))

        obj1 = TT.load(obj_path)

        self.assertEqual(obj1["name"], obj["name"])
        self.assertEqual(obj1["a"], obj["a"])
        self.assertEqual(obj1["b"]["b"], obj["b"]["b"])
        self.assertEqual(obj1["b"]["c"], obj["b"]["c"])
コード例 #59
0
ファイル: config.py プロジェクト: invenia/shepherd
    def make_from_file(cls, filename, name=""):
        """
        Loads the settings dict from a file and passes it to Config.make.

        Args:
            filename (str): name of the file to load
            name (str, optional): the name of the config

        Returns:
            Config: the created config obj
        """
        settings = anyconfig.load(filename, safe=True)
        return cls.make(settings=settings, name=name)
コード例 #60
0
ファイル: templates.py プロジェクト: ssato/miniascape
    def test_30_compile_conf_templates(self):
        conf = A.load(_CONFFILE_0)
        tmpldirs = self.tpaths
        templates_key = "ddd_templates"

        TT.compile_conf_templates(conf, tmpldirs, self.workdir, templates_key)

        # see miniascape/tests/00_sample.yml:ddd_templates.*.dst
        self.assertTrue(os.path.exists(os.path.join(self.workdir,
                                                    "a/b/c/00_sample.out")))
        self.assertTrue(os.path.exists(os.path.join(self.workdir,
                                                    "00_sample.tmpl")))
        self.assertFalse(os.path.exists(os.path.join(self.workdir,
                                                     "dummy_out")))