Example #1
0
class sqlite3db(Singleton):
    def __init__(self):
        """
        Constructor
        """
        # create the 'connection'
        self.__logger = LoggerManager().getLogger("sqldb")
        self.connect()

    def connect(self):
        self.connection = sqlite3.connect(DBFILE)
        self.connection.isolation_level = None
        self.connection.row_factory = self.dict_factory
        self.connection.text_factory = str
        self.have_to_commit = False
        self.cursor = self.connection.cursor()
        self.cursor.row_factory = self.dict_factory
        if not self.check_version():
            self.__logger.debug("No se encontro la version de la base de datos.")
            self.__logger.debug(self.get_db_version())
        self.iface.db = self
        return True

    def check_version(self):
        try:
            version = self.get_registry("/core/dbversion")
            version = tuple(map(int, version.split(".")))
        except:
            version = (0, 0, 0)
        for i in DBVERSIONS:
            if version >= i:
                continue
            self.update_version(map(str, i))
        return True

    def update_version(self, version):
        ver = "_".join(version)
        update_func = getattr(self, "_update_%s" % ver, None)
        if update_func:
            update_func()

    def _update_0_1_0(self):
        """
        Update database to 0.1.0
        """
        sentences = (
            "CREATE TABLE IF NOT EXISTS registry (id INTEGER PRIMARY KEY, desc VARCHAR(255) NOT NULL, value VARCHAR(255) NOT NULL)",
        )
        self.__sentence_executer(sentences)
        self.set_registry("/core/dbversion", (0, 1, 0))
        self.set_registry("/webservice/host", "localhost")
        self.set_registry("/webservice/host", "8080")

    def __sentence_executer(self, sentences):
        for strSQL in sentences:
            try:
                self.execute(strSQL)
                self.commit()
            except Exception, e:
                print e
class main():
    '''
    This class is the manager for the plugins. Will load them and
    launch them if they are enabled
    '''
    def __init__(self):
        self.logger = LoggerManager().getLogger('main')
        self.plugins = {}
        self.load_plugins()

    def load_plugins(self):
        '''
        Search for the files and then use the __importByName to load them
        '''
        files = os.listdir(PLUGINSDIR)
        filteredf = [k for k in files \
                    if os.path.isdir(os.path.join(PLUGINSDIR, k)) and \
                    k not in ('.svn',)]
        for pluginname in filteredf:
            plugin = self.__importByName('libw32s.Plugins.%s'%pluginname,
                                         pluginname)
            if not plugin:
                continue
            try:
                func = getattr(plugin,'main', False)
                if func:
                    instance = func()
                    self.plugins[instance.name] = instance
            except Exception, e:
                self.logger.exception(e)
Example #3
0
 def __init__(self):
     """
     Constructor
     """
     # create the 'connection'
     self.__logger = LoggerManager().getLogger("sqldb")
     self.connect()
 def __init__(self):
     self.logger = LoggerManager().getLogger('main')
     self.plugins = {}
     self.load_plugins()