Esempio n. 1
0
    def connect(self, path=None):
        """ Tries to connect to a database file

        Args:
            path (string, optional): Path of the databse file.
                Defaults to default database path.

        Raises:
            DatabaseConnectionError: Raised if connecting to database
                file does not succeed.
        """
        db_path = Path(config.get_value('db_path')).expanduser()
        db_name = config.get_value('db_name')

        full_path = path or (db_path / db_name)

        try:
            db_path.mkdir(parents=True, exist_ok=True)
            self.connection = sqlite3.connect(str(full_path))
            self.cursor = self.connection.cursor()

            with open('src/db/init_db.sql') as init_db:
                init_db_src = init_db.read()

            self.cursor.executescript(init_db_src)
        except OperationalError as err:
            raise DatabaseConnectionError(
                f'''{literals['database_connection_failed']}: {full_path}'''
            ) from err
Esempio n. 2
0
    def create_project(self, name, path, template_name=None):
        """ Creates a new project and saves it to database and file system

        Args:
            name (string): string that represents name of the project
            path (string): string that represents path of the project
        """

        if not name:
            raise InvalidValueError('Invalid name')
        if not path:
            raise InvalidValueError('Invalid path')

        if project_store.exists(name):
            raise ProjectExistsError
        project = Project(name, path)

        project_store.create(project)
        root = self.add_resource(
            config.get_value('root_filename'), '.', 'tex', project.project_id,
            Path(project.path).expanduser() / project.name, True)
        self.add_resource('projectrc.json', '.', 'config', project.project_id,
                          Path(project.path).expanduser() / 'projectrc.json')
        project_store.set_root_file(config.get_value('root_filename'),
                                    project.project_id)

        if template_name:
            templates = template_controller.get_templates()
            template = list(
                filter(lambda t: t.name == template_name, templates))[0]

            source = template_controller.get_source(template.template_id)
            self.write_resource(root.resource_id, project.project_id, source)

        return project
Esempio n. 3
0
    def get_default_path(self):
        """ Returns default path where templates shall be saved

            Returns:
                string: Default path
        """
        return config.get_value('default_template_path')
Esempio n. 4
0
    def get_default_path(self):
        """ Returns default project path to ui

        Returns:
            string: Default path
        """
        return config.get_value('default_project_path')
Esempio n. 5
0
    def test_values_are_saved(self):
        config.open_config()
        config.set_value('accent_color', 'blue')
        config.save_config()
        config.config_values = None
        config.open_config()

        self.assertEqual(config.get_value('accent_color'), 'blue')
Esempio n. 6
0
 def load_settings(self):
     """ Creates entries for each key-value pair in configuration.
     """
     self.load_setting('dbPath', 'text', config.get_value('db_path'))
     self.load_setting('dbName', 'text', config.get_value('db_name'))
     self.load_setting('projectLocation', 'text',
                       config.get_value('default_project_path'))
     self.load_setting('templateLocation', 'text',
                       config.get_value('default_template_path'))
     self.load_setting('rootFilename', 'text',
                       config.get_value('root_filename'))
     self.load_setting('accentColor', 'text',
                       config.get_value('accent_color'))
     self.load_setting('editorFont', 'text',
                       config.get_value('editor_font'))
Esempio n. 7
0
    def __init__(self, engine):
        super().__init__(engine)

        accent = config.get_value('accent_color')
        self.root.set_accent(accent)