Example #1
0
    def __init__(self, config=None):
        # Default config dictionary
        self._configuration = {
            "user": "******",
            "resource_paths": ["~/pyiron/resources"],
            "project_paths": ["~/pyiron/projects"],
            "sql_connection_string": None,
            "sql_table_name": "jobs_pyiron",
            "sql_view_connection_string": None,
            "sql_view_table_name": None,
            "sql_view_user": None,
            "sql_view_user_key": None,
            "sql_file": None,
            "sql_host": None,
            "sql_type": "SQLite",
            "sql_user_key": None,
            "sql_database": None,
            "project_check_enabled": True,
            "disable_database": False,
        }
        environment = os.environ
        if "PYIRONCONFIG" in environment.keys():
            config_file = environment["PYIRONCONFIG"]
        else:
            config_file = os.path.expanduser(os.path.join("~", ".pyiron"))
        if os.path.isfile(config_file):
            self._config_parse_file(config_file)
        elif any(["PYIRON" in e for e in environment.keys()]):
            self._configuration = self.get_config_from_environment(
                environment=environment, config=self._configuration)
        else:
            print("Fall back to default configuration: "
                  "{'resource_paths': ['~/pyiron/resources'], "
                  "'project_paths': ['~/pyiron/projects']}")

        # Take dictionary as primary source - overwrite everything
        self._read_external_config(config=config)

        self._configuration["project_paths"] = [
            convert_path(path) + "/" if path[-1] != "/" else convert_path(path)
            for path in self._configuration["project_paths"]
        ]
        self._configuration["resource_paths"] = [
            convert_path(path)
            for path in self._configuration["resource_paths"]
        ]

        # Build the SQLalchemy connection strings
        if not self.database_is_disabled:
            self._configuration = self.convert_database_config(
                config=self._configuration)
        self._database = None
        self._use_local_database = False
        self._queue_adapter = None
        self._queue_adapter = self._init_queue_adapter(
            resource_path_lst=self._configuration["resource_paths"])
        self.logger = setup_logger()
        self._publication_lst = {}
        self.publication_add(self.publication)
Example #2
0
    def __init__(self, config=None):
        # Default config dictionary
        self._configuration = {
            'user': '******',
            'resource_paths': ['~/pyiron/resources'],
            'project_paths': ['~/pyiron/projects'],
            'sql_connection_string': None,
            'sql_table_name': 'jobs_pyiron',
            'sql_view_connection_string': None,
            'sql_view_table_name': None,
            'sql_view_user': None,
            'sql_view_user_key': None,
            'sql_file': None,
            'sql_host': None,
            'sql_type': 'SQLite',
            'sql_user_key': None,
            'sql_database': None
        }
        environment_keys = os.environ.keys()
        if 'PYIRONCONFIG' in environment_keys:
            config_file = environment_keys['PYIRONCONFIG']
        else:
            config_file = os.path.expanduser(os.path.join("~", ".pyiron"))
        if os.path.isfile(config_file):
            self._config_parse_file(config_file)
        elif not any([
                env in environment_keys for env in
            ['TRAVIS', 'APPVEYOR', 'CIRCLECI', 'CONDA_BUILD', 'GITLAB_CI']
        ]):
            user_input = None
            while user_input not in ['yes', 'no']:
                user_input = input(
                    'It appears that pyiron is not yet configured, do you want to create a default start configuration (recommended: yes). [yes/no]:'
                )
            if user_input.lower() == 'yes' or user_input.lower() == 'y':
                install_pyiron(
                    config_file_name=config_file,
                    zip_file="resources.zip",
                    resource_directory="~/pyiron/resources",
                    giturl_for_zip_file=
                    "https://github.com/pyiron/pyiron-resources/archive/master.zip",
                    git_folder_name="pyiron-resources-master")
            else:
                raise ValueError('pyiron was not installed!')
            self._config_parse_file(config_file)

        # Take dictionary as primary source - overwrite everything
        if isinstance(config, dict):
            for key, value in config.items():
                if key not in ['resource_paths', 'project_paths'
                               ] or isinstance(value, list):
                    self._configuration[key] = value
                elif isinstance(value, str):
                    self._configuration[key] = [value]
                else:
                    TypeError(
                        'Config dictionary parameter type not recognized ',
                        key, value)

        self._configuration['project_paths'] = [
            convert_path(path) + '/' if path[-1] != '/' else convert_path(path)
            for path in self._configuration['project_paths']
        ]
        self._configuration['resource_paths'] = [
            convert_path(path)
            for path in self._configuration['resource_paths']
        ]

        # Build the SQLalchemy connection strings
        if self._configuration['sql_type'] == 'Postgres':
            self._configuration['sql_connection_string'] = 'postgresql://' + self._configuration['user'] + ':' \
                                                           + self._configuration['sql_user_key'] + '@' \
                                                           + self._configuration['sql_host'] \
                                                           + '/' + self._configuration['sql_database']
            if self._configuration['sql_view_user'] is not None:
                self._configuration['sql_view_connection_string'] = 'postgresql://' + \
                                                                    self._configuration['sql_view_user'] + ':' + \
                                                                    self._configuration['sql_view_user_key'] + '@' + \
                                                                    self._configuration['sql_host'] + '/' + \
                                                                    self._configuration['sql_database']
        elif self._configuration['sql_type'] == 'MySQL':
            self._configuration['sql_connection_string'] = 'mysql+pymysql://' + self._configuration['user'] + ':' \
                                                           + self._configuration['sql_user_key'] + '@' \
                                                           + self._configuration['sql_host'] \
                                                           + '/' + self._configuration['sql_database']
        else:
            # SQLite is raising ugly error messages when the database directory does not exist.
            if self._configuration['sql_file'] is None:
                self._configuration['sql_file'] = '/'.join(
                    [self._configuration['resource_paths'][0], 'sqlite.db'])
            if os.path.dirname(self._configuration['sql_file']) != '' and \
                    not os.path.exists(os.path.dirname(self._configuration['sql_file'])):
                os.makedirs(os.path.dirname(self._configuration['sql_file']))
            self._configuration['sql_connection_string'] = 'sqlite:///' + \
                                                           self._configuration['sql_file'].replace('\\', '/')

        self._database = None
        self._use_local_database = False
        self.logger = setup_logger()
Example #3
0
    def __init__(self, config=None):
        # Default config dictionary
        self._configuration = {
            "user": "******",
            "resource_paths": ["~/pyiron/resources"],
            "project_paths": ["~/pyiron/projects"],
            "sql_connection_string": None,
            "sql_table_name": "jobs_pyiron",
            "sql_view_connection_string": None,
            "sql_view_table_name": None,
            "sql_view_user": None,
            "sql_view_user_key": None,
            "sql_file": None,
            "sql_host": None,
            "sql_type": "SQLite",
            "sql_user_key": None,
            "sql_database": None,
        }
        environment_keys = os.environ.keys()
        if "PYIRONCONFIG" in environment_keys:
            config_file = environment_keys["PYIRONCONFIG"]
        else:
            config_file = os.path.expanduser(os.path.join("~", ".pyiron"))
        if os.path.isfile(config_file):
            self._config_parse_file(config_file)
        elif not any(
            [
                env in environment_keys
                for env in [
                    "TRAVIS",
                    "APPVEYOR",
                    "CIRCLECI",
                    "CONDA_BUILD",
                    "GITLAB_CI",
                ]
            ]
        ):
            user_input = None
            while user_input not in ["yes", "no"]:
                user_input = input(
                    "It appears that pyiron is not yet configured, do you want to create a default start configuration (recommended: yes). [yes/no]:"
                )
            if user_input.lower() == "yes" or user_input.lower() == "y":
                install_pyiron(
                    config_file_name=config_file,
                    zip_file="resources.zip",
                    resource_directory="~/pyiron/resources",
                    giturl_for_zip_file="https://github.com/pyiron/pyiron-resources/archive/master.zip",
                    git_folder_name="pyiron-resources-master",
                )
            else:
                raise ValueError("pyiron was not installed!")
            self._config_parse_file(config_file)

        # Take dictionary as primary source - overwrite everything
        if isinstance(config, dict):
            for key, value in config.items():
                if key not in ["resource_paths", "project_paths"] or isinstance(
                    value, list
                ):
                    self._configuration[key] = value
                elif isinstance(value, str):
                    self._configuration[key] = [value]
                else:
                    TypeError(
                        "Config dictionary parameter type not recognized ", key, value
                    )

        self._configuration["project_paths"] = [
            convert_path(path) + "/" if path[-1] != "/" else convert_path(path)
            for path in self._configuration["project_paths"]
        ]
        self._configuration["resource_paths"] = [
            convert_path(path) for path in self._configuration["resource_paths"]
        ]

        # Build the SQLalchemy connection strings
        if self._configuration["sql_type"] == "Postgres":
            self._configuration["sql_connection_string"] = (
                "postgresql://"
                + self._configuration["user"]
                + ":"
                + self._configuration["sql_user_key"]
                + "@"
                + self._configuration["sql_host"]
                + "/"
                + self._configuration["sql_database"]
            )
            if self._configuration["sql_view_user"] is not None:
                self._configuration["sql_view_connection_string"] = (
                    "postgresql://"
                    + self._configuration["sql_view_user"]
                    + ":"
                    + self._configuration["sql_view_user_key"]
                    + "@"
                    + self._configuration["sql_host"]
                    + "/"
                    + self._configuration["sql_database"]
                )
        elif self._configuration["sql_type"] == "MySQL":
            self._configuration["sql_connection_string"] = (
                "mysql+pymysql://"
                + self._configuration["user"]
                + ":"
                + self._configuration["sql_user_key"]
                + "@"
                + self._configuration["sql_host"]
                + "/"
                + self._configuration["sql_database"]
            )
        else:
            # SQLite is raising ugly error messages when the database directory does not exist.
            if self._configuration["sql_file"] is None:
                self._configuration["sql_file"] = "/".join(
                    [self._configuration["resource_paths"][0], "sqlite.db"]
                )
            if os.path.dirname(
                self._configuration["sql_file"]
            ) != "" and not os.path.exists(
                os.path.dirname(self._configuration["sql_file"])
            ):
                os.makedirs(os.path.dirname(self._configuration["sql_file"]))
            self._configuration[
                "sql_connection_string"
            ] = "sqlite:///" + self._configuration["sql_file"].replace("\\", "/")

        self._database = None
        self._use_local_database = False
        self._queue_adapter = None
        self._queue_adapter = self._init_queue_adapter(
            resource_path_lst=self._configuration["resource_paths"]
        )
        self.logger = setup_logger()
        self._publication_lst = {}
        self.publication_add(self.publication)