Beispiel #1
0
    def _init_database(self):
        """Connect to database and set up database if this is the first
        start of the application."""
        self.logger.info('Connecting to global database file...')

        data_file = save_data_file(self._DATA_FILE)
        engine = create_engine('sqlite:///' + data_file)
        SQLSession.configure(bind=engine)

        if not os.path.exists(data_file):
            self.logger.info('Initializing database for first start...')

            SQLBase.metadata.create_all(engine)

            pool = Pool(name=_('My Computer'), host='localhost', is_local=True)

            docs_dir = os.environ.get('XDG_DOCUMENTS_DIR',
                                      os.path.expanduser('~'))
            Category(name=_('Documents'), directory=docs_dir, pool=pool)

            videos_dir = os.environ.get('XDG_VIDEOS_DIR',
                                        os.path.expanduser('~'))
            Category(name=_('Videos'), directory=videos_dir, pool=pool)

            music_dir = os.environ.get('XDG_MUSIC_DIR',
                                       os.path.expanduser('~'))
            Category(name=_('Music'), directory=music_dir, pool=pool)

            self.logger.info('Database initialized.')

        # Auto commit to database
        GLib.timeout_add_seconds(self._SYNC_INTERVAL, SQLSession.commit)

        self.logger.info('Global database file connected.')
Beispiel #2
0
    def _init_database(self):
        """Connect to database and set up database if this is the first
        start of the application."""
        self.logger.info('Connecting to global database file...')

        data_file = save_data_file(self._DATA_FILE)
        engine = create_engine('sqlite:///' + data_file)
        SQLSession.configure(bind=engine)

        if not os.path.exists(data_file):
            self.logger.info('Initializing database for first start...')

            SQLBase.metadata.create_all(engine)

            pool = Pool(name=_('My Computer'), host='localhost', is_local=True)

            docs_dir = os.environ.get('XDG_DOCUMENTS_DIR', os.path.expanduser('~'))
            Category(name=_('Documents'), directory=docs_dir, pool=pool)

            videos_dir = os.environ.get('XDG_VIDEOS_DIR', os.path.expanduser('~'))
            Category(name=_('Videos'), directory=videos_dir, pool=pool)

            music_dir = os.environ.get('XDG_MUSIC_DIR', os.path.expanduser('~'))
            Category(name=_('Music'), directory=music_dir, pool=pool)

            self.logger.info('Database initialized.')

        # Auto commit to database
        GLib.timeout_add_seconds(self._SYNC_INTERVAL, SQLSession.commit)

        self.logger.info('Global database file connected.')