Esempio n. 1
0
    def _proceed(self, event):
        # Close the properties tab explicitly, otherwise if the closing is
        # aborted, the choice controls should be reset to the current
        # configuration, if the tab is still open, which is not necessarily
        # true because the closing of the properties tab would race e.g. with
        # the dialogs to save the database
        self.propmanager.close(self.filename)

        if databases.close_database(self.filename):
            shutil.copy2(self.filename, self.backup.GetPath())

            if self.value == 0:
                dbdeps.Database(self.filename).add((self.ext, ))
            elif self.value == 1:
                dbdeps.Database(self.filename).remove((self.ext, ))
            else:
                dbdeps.Database(self.filename).remove((self.ext, ),
                                                      ignored=True)

            # Use CallAfter or segfaults may happen
            wx.CallAfter(databases.open_database,
                         self.filename,
                         open_properties=True)
            # Note that no other operation should be done on the database
            #  directly here, because opening the database may fail e.g.
            #  because of the compatibility checks
        else:
            self.propmanager.open(self.filename)

        # Always close the dialog because the property settings have been
        # reset by closing and reopening the property tab
        self._close()
Esempio n. 2
0
    def _update(self, event):
        filename = self.updater.get_filename()
        shutil.copy2(filename, self.backup.GetPath())
        dbdeps.Database(filename).upgrade(self.deplist)
        self._close()

        # Use CallAfter or segfaults may happen e.g. if re-opening after
        # changing the dependencies in the properties tab
        wx.CallAfter(databases.open_database,
                     filename,
                     open_properties=self.open_properties)
Esempio n. 3
0
    def create(filename):
        if filename in dbs:
            raise exceptions.DatabaseAlreadyOpenError()
        else:
            try:
                db = open(filename, 'w')
            except IOError as e:
                if e.errno in (errno.EACCES, errno.ENOENT):
                    # errno.ENOENT happens when trying to to do a save as in
                    # a non-authorized folder
                    raise exceptions.AccessDeniedError()
                raise
            else:
                db.close()

                conn = FileDB(filename)
                cursor = conn.cursor()

                cursor.execute(queries.properties_create)

                limit = coreaux_api.get_configuration()('History').get_int(
                    'default_soft_limit')
                cursor.execute(queries.properties_insert_init, (limit, ))

                cursor.execute(queries.compatibility_create)
                # Only store major versions, as they are supposed to keep
                # backward compatibility
                # None must be used for core, because it must be safe in case
                # an extension is called 'core' for some reason
                cursor.execute(queries.compatibility_insert, (
                    None,
                    int(float(outspline.info.core.version)),
                ))

                cursor.execute(queries.items_create)
                cursor.execute(queries.history_create)

                conn.save_and_disconnect()

                extensions = coreaux_api.get_enabled_installed_addons(
                )['Extensions']
                dbdeps.Database(filename).add([
                    ext for ext in extensions
                    if coreaux_api.import_extension_info(ext).affects_database
                ])

                return filename
Esempio n. 4
0
    def open(cls, filename, check_new_extensions=True):
        global dbs
        if filename in dbs:
            raise exceptions.DatabaseAlreadyOpenError()
        elif not os.access(filename, os.W_OK):
            raise exceptions.DatabaseNotAccessibleError()
        else:
            can_open, dependencies = dbdeps.Database(filename).is_compatible(
                check_new_extensions)

            if can_open:
                dbs[filename] = cls(filename)

                open_database_dirty_event.signal(filename=filename,
                                                 dependencies=dependencies)

                # Reset modified state after instantiating the class, since
                # this signals an event whose handlers might require the object
                # to be already created
                dbs[filename].dbhistory.reset_modified_state()

                open_database_event.signal(filename=filename)
                return True