Exemplo n.º 1
0
def packages(update=False, filterUpdates=False):
    if update:
        update_db()
    else:
        needupdate = False
        with ops.db.Database() as db:
            c = db.cursor()
            c.execute('SELECT name FROM applications')
            if (c.rowcount < 1):
                needupdate = True
        if needupdate:
            update_db()
    apps = []
    with ops.db.Database() as db:
        c = db.cursor()
        if filterUpdates:
            c.execute(
                'SELECT name, version, description, install_date FROM applications WHERE name NOT LIKE "%update%" AND name NOT LIKE "%hotfix%" ORDER BY name ASC'
            )
        else:
            c.execute(
                'SELECT name, version, description, install_date FROM applications ORDER BY name ASC'
            )
        for i in c:
            apps += [{
                'name': i[0],
                'version': i[1],
                'description': i[2],
                'install_date': i[3]
            }]
    return apps
Exemplo n.º 2
0
def WriteMetaData(psps):
    if (not (type(psps) == list)):
        psps = [psps]
    with ops.db.get_tdb() as db:
        c = db.cursor()
        try:
            c.execute('DELETE FROM {0}'.format(DB_PSP_TABLE_NAME))
            c.execute('DELETE FROM {0}'.format(DB_PSP_ATTRIBUTES_TABLE_NAME))
        except:
            psplog.error('Error deleting PSP data from database.',
                         exc_info=True)
            return False
    for psp in psps:
        datatowrite = psp.GetAttributesToSave()
        datatowrite.update(psp.GetConfigAttributes())
        for attr in datatowrite.keys()[:]:
            if (datatowrite[attr] is None):
                del datatowrite[attr]
        cols = []
        vals = []
        for attr in _dbinfoToPSPMap.keys():
            if (attr in datatowrite.keys()):
                cols.append(u"'{0}'".format(attr))
                vals.append(u"'{0}'".format(
                    unicode(datatowrite.pop(_dbinfoToPSPMap[attr]))))
        sqlCmd = u'INSERT OR REPLACE INTO {0} ({1}) VALUES ({2})'.format(
            DB_PSP_TABLE_NAME, ','.join(cols), ','.join(vals)).encode('UTF-8')
        with ops.db.get_tdb() as db:
            c = db.cursor()
            try:
                c.execute(sqlCmd)
            except:
                psplog.error('Error writing PSP data to database!',
                             exc_info=True)
                return False
            pspid = c.lastrowid
        cols = []
        vals = []
        config = psp.GetConfigAttributes().keys()
        with ops.db.get_tdb() as db:
            c = db.cursor()
            for attr in datatowrite.keys():
                sqlCmd = "INSERT OR REPLACE INTO {0} (pspid,\n                                                        attribName,\n                                                        attribValue,\n                                                        config,\n                                                        displayas)\n                            VALUES ({1},\n                                    '{2}',\n                                    '{3}',\n                                    {4},\n                                    '{5}')".format(
                    DB_PSP_ATTRIBUTES_TABLE_NAME, pspid, attr,
                    datatowrite[attr], int((attr in config)),
                    psp.GetAttributeDisplay(attr))
                try:
                    c.execute(sqlCmd)
                except:
                    psplog.error('Error writing PSP data to database!',
                                 exc_info=True)
                    return False
    return True
Exemplo n.º 3
0
def GetPreviousConfig(vendor=None):
    prevPSPs = []
    with ops.db.get_tdb() as db:
        c = db.cursor()
        __createPSPTable(c)
        if (vendor is not None):
            c.execute('SELECT _ROWID_ as pspid,* FROM PSPs WHERE vendor LIKE ?', (vendor,))
        else:
            c.execute('SELECT _ROWID_ as pspid,* FROM PSPs')
        info = c.fetchall()
        pspcols = c.description
        c.execute('SELECT * FROM PSPAttributes')
        attribs = c.fetchall()
        psplog.debug('info: {0}'.format(info))
        psplog.debug('attribs: {0}'.format(attribs))
    pspdata = []
    for row in info:
        pspattribs = []
        for (ndx, col) in enumerate(pspcols):
            if (col[0] == 'pspid'):
                continue
            if (row[ndx] is not None):
                tmp = row[ndx].decode('utf-8')
            else:
                tmp = None
            pspattribs.append(PSPAttribute(_dbinfoToPSPMap.get(col[0], col[0]), tmp, config=False))
        for row in filter((lambda x: (str(x[0]) == str(row[0]))), attribs):
            pspattribs.append(PSPAttribute(_dbinfoToPSPMap.get(row[1].decode('utf-8'), row[1].decode('utf-8')), row[2].decode('utf-8'), config=(row[3] == 1), displayas=row[4].decode('utf-8')))
        pspdata.append(pspattribs)
    for attribdata in pspdata:
        prevPSPs.append(PSP(attribdata))
    return prevPSPs
Exemplo n.º 4
0
def update_db():
    apps = get()
    with ops.db.Database() as db:
        c = db.cursor()
        c.execute('DELETE FROM applications')
        for i in apps:
            c.execute('INSERT OR IGNORE INTO applications (name, version, description, install_date) VALUES (?, ?, ?, ?)', (i['name'], i['version'], i['description'], i['install_date']))
    return apps
Exemplo n.º 5
0
def WriteMetaData(psps):
    if (not (type(psps) == list)):
        psps = [psps]
    with ops.db.get_tdb() as db:
        c = db.cursor()
        try:
            c.execute('DELETE FROM {0}'.format(DB_PSP_TABLE_NAME))
            c.execute('DELETE FROM {0}'.format(DB_PSP_ATTRIBUTES_TABLE_NAME))
        except:
            psplog.error('Error deleting PSP data from database.', exc_info=True)
            return False
    for psp in psps:
        datatowrite = psp.GetAttributesToSave()
        datatowrite.update(psp.GetConfigAttributes())
        for attr in datatowrite.keys()[:]:
            if (datatowrite[attr] is None):
                del datatowrite[attr]
        cols = []
        vals = []
        for attr in _dbinfoToPSPMap.keys():
            if (attr in datatowrite.keys()):
                cols.append(u"'{0}'".format(attr))
                vals.append(u"'{0}'".format(unicode(datatowrite.pop(_dbinfoToPSPMap[attr]))))
        sqlCmd = u'INSERT OR REPLACE INTO {0} ({1}) VALUES ({2})'.format(DB_PSP_TABLE_NAME, ','.join(cols), ','.join(vals)).encode('UTF-8')
        with ops.db.get_tdb() as db:
            c = db.cursor()
            try:
                c.execute(sqlCmd)
            except:
                psplog.error('Error writing PSP data to database!', exc_info=True)
                return False
            pspid = c.lastrowid
        cols = []
        vals = []
        config = psp.GetConfigAttributes().keys()
        with ops.db.get_tdb() as db:
            c = db.cursor()
            for attr in datatowrite.keys():
                sqlCmd = "INSERT OR REPLACE INTO {0} (pspid,\n                                                        attribName,\n                                                        attribValue,\n                                                        config,\n                                                        displayas)\n                            VALUES ({1},\n                                    '{2}',\n                                    '{3}',\n                                    {4},\n                                    '{5}')".format(DB_PSP_ATTRIBUTES_TABLE_NAME, pspid, attr, datatowrite[attr], int((attr in config)), psp.GetAttributeDisplay(attr))
                try:
                    c.execute(sqlCmd)
                except:
                    psplog.error('Error writing PSP data to database!', exc_info=True)
                    return False
    return True
Exemplo n.º 6
0
def packages(update=False, filterUpdates=False):
    if update:
        update_db()
    else:
        needupdate = False
        with ops.db.Database() as db:
            c = db.cursor()
            c.execute('SELECT name FROM applications')
            if (c.rowcount < 1):
                needupdate = True
        if needupdate:
            update_db()
    apps = []
    with ops.db.Database() as db:
        c = db.cursor()
        if filterUpdates:
            c.execute('SELECT name, version, description, install_date FROM applications WHERE name NOT LIKE "%update%" AND name NOT LIKE "%hotfix%" ORDER BY name ASC')
        else:
            c.execute('SELECT name, version, description, install_date FROM applications ORDER BY name ASC')
        for i in c:
            apps += [{'name': i[0], 'version': i[1], 'description': i[2], 'install_date': i[3]}]
    return apps
Exemplo n.º 7
0
def query_driver_database(name=None, comment=None, drv_type=None, hash=None, size=None, date_added=None):
    if ((name is None) and (comment is None) and (drv_type is None) and (hash is None) and (size is None) and (date_added is None)):
        return []
    item_list = []
    query_list = []
    querystring = 'SELECT * FROM drivers WHERE'
    if (name is not None):
        if (type(name) == type([])):
            item_list.append((('(' + ' OR '.join((len(name) * ['name=?']))) + ')'))
            for item in name:
                query_list.append(item.lower())
        else:
            item_list.append('name=?')
            query_list.append(name.lower())
    if (comment is not None):
        if (type(comment) == type([])):
            item_list.append((('(' + ' OR '.join((len(comment) * ['comment=?']))) + ')'))
            for item in comment:
                query_list.append(item.lower())
        else:
            item_list.append('comment=?')
            query_list.append(comment)
    if (drv_type is not None):
        if (type(drv_type) == type([])):
            item_list.append((('(' + ' OR '.join((len(drv_type) * ['type=?']))) + ')'))
            for item in drv_type:
                query_list.append(item.lower())
        else:
            item_list.append('type=?')
            query_list.append(drv_type)
    if (hash is not None):
        if (type(hash) == type([])):
            item_list.append((('(' + ' OR '.join((len(hash) * ['hash=?']))) + ')'))
            for item in hash:
                query_list.append(item.lower())
        else:
            item_list.append('hash=?')
            query_list.append(hash.lower())
    if (size is not None):
        if (type(size) == type([])):
            item_list.append((('(' + ' OR '.join((len(size) * ['size=?']))) + ')'))
            for item in size:
                query_list.append(item.lower())
        else:
            item_list.append('size=?')
            query_list.append(size)
    if (date_added is not None):
        if (type(date_added) == type([])):
            item_list.append((('(' + ' OR '.join((len(date_added) * ['date_added=?']))) + ')'))
            for item in date_added:
                query_list.append(item.lower())
        else:
            item_list.append('date_added=?')
            query_list.append(date_added)
    querystring = ('%s %s' % (querystring, ' AND '.join(item_list)))
    with ops.db.Database(ops.db.DRIVERLIST) as db:
        conn = db.cursor()
        curs = conn.execute(querystring, query_list)
        result_list = []
        for row in curs:
            temp_dict = {}
            for key in row.keys():
                temp_dict[key] = row[key]
            result_list.append(temp_dict)
    return result_list