Exemple #1
0
    def load_server_configuration(self):

        config_spec = os.path.join(resource_dir, "server_config_check.cfg")

        data_dir = os.path.join(
            shell.SHGetFolderPath(0, shellcon.CSIDL_COMMON_APPDATA, 0, 0),
            codename)
        config_file = os.path.join(data_dir, 'server.cfg')

        if not os.path.exists(os.path.join(data_dir)):
            os.mkdir(data_dir)

        if not os.path.exists(os.path.join(config_file)):
            self.base_configuration = configobj.ConfigObj(encoding='utf-8')

            self.base_configuration['Database'] = {}
            self.base_configuration['Database'][
                'url'] = 'postgresql://*****:*****@{}:5432/horsedb'.format(
                    guess_server_public_ip())
            self.base_configuration['Database'][
                'admin_url'] = 'postgresql://*****:*****@localhost:5432/horsedb'
            self.base_configuration.filename = config_file
            self.base_configuration.write()

        self.load(config_file, config_spec)
Exemple #2
0
def make_empty_configuration_file(dest_path, spec_path):
    cfg = configobj.ConfigObj(create_empty=True,
                              configspec=spec_path,
                              default_encoding='utf-8')

    # Make sure the default values are copied
    cfg.validate(validate.Validator(), copy=True)

    mainlog.info("Writing configuration file {}".format(dest_path))
    with open(dest_path, mode="wb") as out_file:
        cfg.write(out_file)
Exemple #3
0
    def load(self, config_path, config_spec):
        self._config_file = config_path
        self._config_spec = config_spec

        config_path = os.path.normpath(os.path.join(os.getcwd(), config_path))

        mainlog.info("Reading configuration file -> {}".format(config_path))
        mainlog.debug(
            "Reading configuration spec file -> {}".format(config_spec))

        if not os.path.exists(config_path):
            mainlog.error(
                "Configuration file not found at {}".format(config_path))
            raise Exception(
                "Configuration file not found at {}".format(config_path))

        try:
            self.base_configuration = configobj.ConfigObj(
                infile=config_path, configspec=config_spec, encoding='utf-8')
        except UnicodeDecodeError:
            mainlog.warn(
                "The encoding of the config file is not UTF-8. I'll try {}".
                format(locale.getpreferredencoding()))
            self.base_configuration = configobj.ConfigObj(
                infile=config_path,
                configspec=config_spec,
                encoding=locale.getpreferredencoding())

        self.base_configuration.validate(validate.Validator())

        if 'Programs' not in self.base_configuration or 'pdf_viewer' not in self.base_configuration[
                'Programs'] or not self.base_configuration['Programs'][
                    'pdf_viewer'] or not os.path.exists(
                        self.base_configuration['Programs']['pdf_viewer']):

            if platform.system() == 'Linux':
                self.base_configuration['Programs']['pdf_viewer'] = 'xpdf'
            else:
                self.base_configuration['Programs'][
                    'pdf_viewer'] = os.path.join(resource_dir,
                                                 'SumatraPDF.exe')
Exemple #4
0
 def load_from_spec(self, config_path, config_spec):
     self._config_file = config_path
     self._config_spec = config_spec
     self.base_configuration = configobj.ConfigObj(configspec=config_spec,
                                                   encoding='utf-8')
Exemple #5
0
 def load_backup(self, config_path, config_spec):
     self.backup_configuration = configobj.ConfigObj(infile=config_path,
                                                     configspec=config_spec,
                                                     encoding='utf-8')