Example #1
0
def main(filename):
    """ Main loop."""
    init_logging()
    init_db()
    db_instance = DatabaseHandler.get_connection()
    data = JsonPkgTree(db_instance, filename)
    data.dump()
Example #2
0
 def __init__(self):
     self.logger = get_logger(__name__)
     self.conn = DatabaseHandler.get_connection()
     self.module_store = ModulesStore()
     self.package_store = PackageStore()
     self.update_store = UpdateStore()
     self.content_set_to_db_id = self._prepare_content_set_map()
Example #3
0
def main():
    """ Main loop."""
    init_logging()
    init_db()
    db_instance = DatabaseHandler.get_connection()
    timestamp = format_datetime(now())

    data = SqliteDump(db_instance, DUMP)
    data.dump(timestamp)
Example #4
0
    def process(self):
        """Processes the dbchange get request. """
        init_db()
        self.db_instance = DatabaseHandler.get_connection()
        result = {}

        with self.db_instance.cursor() as crs:
            crs.execute("select pkgtree_change from dbchange")
            timestamp = crs.fetchone()

        result["pkgtree_change"] = str(timestamp[0])
        return result
Example #5
0
    def __init__(self):
        self.logger = get_logger(__name__)
        self.conn = DatabaseHandler.get_connection()
        self.cpe_label_to_id = {}
        self.cpe_label_to_name = {}

        cur = self.conn.cursor()
        cur.execute("select id, label, name from cpe")
        for cpe_id, label, name in cur.fetchall():
            self.cpe_label_to_id[label] = cpe_id
            self.cpe_label_to_name[label] = name
        cur.close()
Example #6
0
    def upgrade(self):
        """perform database upgrade"""
        conn = DatabaseHandler.get_connection()
        try:
            self._get_db_lock(conn)

            db_version = self._get_current_db_version(conn)

            if db_version == self.version_max:
                LOGGER.info('Database is up to date at version: %d', db_version)
                return
            if db_version > self.version_max:
                msg = 'Database version %d is greater than upgrade version %d' % (db_version, self.version_max)
                LOGGER.warning(msg)
                return

            LOGGER.info('Database requires upgrade from version %d to %d', db_version, self.version_max)
            upgrades_to_apply = self._get_upgrades_to_apply(db_version, self.version_max)
            for upgrade in upgrades_to_apply:
                self._apply_upgrade(upgrade['ver'], upgrade['script'], conn)
        finally:
            self._release_db_lock(conn)
Example #7
0
    def init_schema(self):
        """Initialize database schema."""
        cfg = Config()
        conn = DatabaseHandler.get_connection()
        if self._is_initialized(conn):
            LOGGER.info("DB schema is already initialized.")
            return

        try:
            self._get_db_lock(conn)
            LOGGER.info("Empty database, initializing...")
            with conn.cursor() as cur:
                with open(USER_CREATE_SQL_PATH, "r", encoding='utf8') as f_user, \
                        open(DB_CREATE_SQL_PATH, "r", encoding='utf8') as f_db:
                    cur.execute(f_user.read())
                    cur.execute(f_db.read())
                    cur.execute(f"ALTER USER vmaas_writer WITH PASSWORD '{cfg.postgresql_writer_password}'")
                    cur.execute(f"ALTER USER vmaas_reader WITH PASSWORD '{cfg.postgresql_reader_password}'")

            conn.commit()
        finally:
            self._release_db_lock(conn)
Example #8
0
 def __init__(self):
     self.logger = get_logger(__name__)
     self.conn = DatabaseHandler.get_connection()