Ejemplo n.º 1
0
 def create_database(self):
     from LibScan.mysql_ampache import database_tables, database_constraints, database_creator, catalog_creator, catalog_local_creator
     self.db.autocommit(True)
     cursor = self.db.cursor()
     print "Creating the database"
     cursor.execute(database_creator % self.database)
     cursor.execute("USE `{}`".format(self.database))
     print "Creating the tables"
     for table, creator in database_tables.iteritems():
         print "Creating table {}".format(table)
         cursor.execute(creator)
     print "Tables created"
     print "Creating constraints"
     for table, creator in database_constraints.iteritems():
         print "Creating constraint {}".format(table)
         cursor.execute(creator)
     print "Constraints created"
     print "Creating catalog entry"
     now = int(time())
     cursor.execute(catalog_creator, (self.catalog_name, now, now, now))
     new_cat_id = cursor.lastrowid
     print "Created catalog entry, creating local entry"
     cursor.execute(catalog_local_creator, (self.catalog_dir, new_cat_id))
     print "Created local entry"
     print "Reconnecting to the new database"
     self.db_connect()
Ejemplo n.º 2
0
 def on_upgrade_dialog_yes_button_clicked(self, *args):
     from LibScan.mysql_ampache import database_tables, database_constraints, database_creator, catalog_creator, catalog_local_creator
     self.db.autocommit(True)
     cursor = self.db.cursor()
     print "Updating the database"
     #cursor.execute("USE `{}`".format(self.database))
     print "Creating the tables"
     for table, creator in database_tables.iteritems():
         print "Creating table {}".format(table)
         try:
             cursor.execute(creator)
         except:
             print "Table {} already in database".format(table)
     print "Tables created"
     print "Creating constraints"
     for table, creator in database_constraints.iteritems():
         print "Creating constraint {}".format(table)
         try:
             cursor.execute(creator)
         except:
             print "Constraint {} already in database".format(table)
     print "Constraints created"
     self.db_connect()
     self.gobject['upgrade_dialog'].hide()