def prepare_midgard(self): #self.status.set_text("Initializing Midgard connection...") # Preparing configuration for using Midgard # the SQLite database file will be placed into ~/.midgard2/data/adventuretablet.db configuration = midgard.config() configuration.dbtype = 'SQLite' configuration.database = 'adventuretablet' # Open a Midgard repository connection with our config connection = midgard.connection() if (connection.open_config(configuration) is False): print "failed to open midgard connection" self.emit('storage-ready', False) if (midgard.storage.class_storage_exists('ttoa_user') is False): # We only need to do these on the first run: prepare database tables #self.status.set_text("Building Midgard database tables on this first run") midgard.storage.create_base_storage() midgard.storage.create_class_storage('ttoa_user') midgard.storage.create_class_storage('ttoa_log') midgard.storage.create_class_storage('ttoa_mission') midgard.storage.create_class_storage('midgard_parameter') self.emit('storage-ready', True) # Return false so the timeout is removed return False
def connect(self, name): config = midgard.config() opened = config.read_file('midgard', True); if opened == False: raise SystemError("Failed to open default configuration file") # try to connect self.open_config(config);
def open_connection(self): config_name = 'my_midgardtest_db' configuration = midgard.config() configuration.dbtype = 'SQLite' configuration.database = 'my_midgardtest_db' configuration.blobdir = os.path.join(os.path.expanduser("~"), "midgardblobs"); configuration.loglevel = 'message' connection = midgard.connection() connection.open_config(configuration)
import _midgard as midgard import os config_name = 'my_midgardtest_db' configuration = midgard.config() configuration.dbtype = 'SQLite' configuration.database = 'my_midgardtest_db' configuration.blobdir = os.path.join(os.path.expanduser("~"), "midgardblobs"); configuration.loglevel = 'message' connection = midgard.connection() connection.open_config(configuration) midgard.storage.create_base_storage() midgard.storage.create_class_storage('midgard_page')
import _midgard as midgard import sys class my_config(midgard.config): def __init__(self): midgard.config.__init__(self) # new config instance config = midgard.config(); # list configuration files cfgs = config.list_files(True) if len(cfgs) == 0: raise SysteError("No midgard configuration found") # read default configuration try: opened = config.read_file('midgard', True); except SystemError, msg: print msg sys.exit(1) print "Created configuration " # try to connect cnc = midgard.connection() connected = cnc.open_config(config); #if connected == False: # raise SystemError("Failed to connect using default configuration object")
from PyQt4.QtCore import * from PyKDE4.kdecore import * from PyKDE4 import plasmascript import _midgard as midgard mgd_conn = midgard.connection() mgd_conf = midgard.config() _available_schemas = [] class PyMidgardEngine(plasmascript.DataEngine): def __init__(self,parent,args=None): plasmascript.DataEngine.__init__(self,parent) init_midgard() def init(self): self.setMinimumPollingInterval(333) def sources(self): sources = get_available_schemas() return sources def sourceRequestEvent(self, name): return self.updateSourceEvent(name) def updateSourceEvent(self, source): self.setData(source, "Name", QVariant("Default Schema")) return True def CreateDataEngine(parent):