示例#1
0
class SlurpSession(object):
    def __init__(self):
        self.ids = IdTranslator()
        self.hostid = 0
        self.catalogid = 0

    def setup_catalog(self, db, catalog):
        rv = db.query("select id from hosts where hostname=? and system=?",
                                        [catalog.hostname, catalog.system])
        if rv:
            self.hostid = rv[0][0]
        else:
            self.hostid = db.insert_row('hosts', ['hostname', 'system'], 
                                        [catalog.hostname, catalog.system])
        if not self.hostid:
            return False
        rv = db.query("select id_local from catalog hosts where lc_filename=? and host=?",
                                   [catalog.filename.lower(), self.hostid])
        if rv:
            self.catalogid = rv[0][0]
        else: 
            self.catalogid = db.insert_row('catalog', 
                                      ['filename', 'lc_filename', 'host'], 
                 [catalog.filename, catalog.filename.lower(), self.hostid])

        if not self.catalogid:
            return False
        return True

    def set_value(self, table, a, b):
        self.ids.set_value(table, a, b)

    def get_value(self, table, a):
        return self.ids.get_value(table, a)

    def dump(self):
        self.ids.dump()