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 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)
# -*- coding: utf-8 -*- import _midgard as midgard import dbus.mainloop.glib import gobject import configuration import cache_midgard import sys if len(sys.argv) != 4: print "Usage: python midcom.py configuration sitegroup host" sys.exit() cnc = midgard.connection() cnc.open(sys.argv[1]) if cnc.set_sitegroup(sys.argv[2]) == False: print ("Sitegroup %s not found" % (sys.argv[2])) sys.exit() qb = midgard.query_builder('midgard_host') qb.add_constraint('name', '=', sys.argv[3]) res = qb.execute() if len(res) == 0: print ("Host %s not found" % (sys.argv[3])) sys.exit() host = res[0] # Testing cache cache = cache_midgard.cache_midgard(cnc, host) cache.delete_all('test') cache.delete('test_domain', 'test')
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')
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):