Beispiel #1
0
    def remove_lt(self, ltid):
        args = {"ltid" : ltid}

        # remove from lt
        table_name = "lt"
        l_cond = [db_common.cond("ltid", "=", "ltid")]
        sql = self.db.delete_sql(table_name, l_cond)
        self.db.execute(sql, args)

        # remove from ltg
        table_name = "ltg"
        l_cond = [db_common.cond("ltid", "=", "ltid")]
        sql = self.db.delete_sql(table_name, l_cond)
        self.db.execute(sql, args)
Beispiel #2
0
 def whole_host(self, top_dt = None, end_dt = None):
     table_name = "log"
     l_key = ["host"]
     l_cond = []
     args = {}
     if top_dt is not None:
         l_cond.append(db_common.cond("dt", ">=", "top_dt"))
         args["top_dt"] = top_dt
     if end_dt is not None:
         l_cond.append(db_common.cond("dt", "<", "end_dt"))
         args["end_dt"] = end_dt
     sql = self.db.select_sql(table_name, l_key, l_cond, opt = ["distinct"])
     cursor = self.db.execute(sql, args)
     return [row[0] for row in cursor]
Beispiel #3
0
    def remove_lt(self, ltid):
        args = {"ltid" : ltid}

        # remove from lt
        table_name = "lt"
        l_cond = [db_common.cond("ltid", "=", "ltid")]
        sql = self.db.delete_sql(table_name, l_cond)
        self.db.execute(sql, args)

        # remove from ltg
        table_name = "ltg"
        l_cond = [db_common.cond("ltid", "=", "ltid")]
        sql = self.db.delete_sql(table_name, l_cond)
        self.db.execute(sql, args)
Beispiel #4
0
 def whole_host(self, top_dt = None, end_dt = None):
     table_name = "log"
     l_key = ["host"]
     l_cond = []
     args = {}
     if top_dt is not None:
         l_cond.append(db_common.cond("dt", ">=", "top_dt"))
         args["top_dt"] = top_dt
     if end_dt is not None:
         l_cond.append(db_common.cond("dt", "<", "end_dt"))
         args["end_dt"] = end_dt
     sql = self.db.select_sql(table_name, l_key, l_cond, opt = ["distinct"])
     cursor = self.db.execute(sql, args)
     return [row[0] for row in cursor]
Beispiel #5
0
 def host_area(self, host):
     table_name = area
     l_key = ["area"]
     l_cond = [db_common.cond("host", "=", "host")]
     args = {"host" : host}
     sql = self.db.select_sql(table_name, l_key, l_cond)
     cursor = self.db.execute(sql, args)
     return [row[0] for row in cursor]
Beispiel #6
0
 def get_ltg_members(self, ltgid):
     table_name = "ltg"
     l_key = ["ltid"]
     l_cond = [db_common.cond("ltgid", "=", "ltgid")]
     args = {"ltgid" : ltgid}
     sql = self.db.select_sql(table_name, l_key, l_cond)
     cursor = self.db.execute(sql, args)
     return [int(row[0]) for row in cursor]
Beispiel #7
0
 def host_area(self, host):
     table_name = area
     l_key = ["area"]
     l_cond = [db_common.cond("host", "=", "host")]
     args = {"host" : host}
     sql = self.db.select_sql(table_name, l_key, l_cond)
     cursor = self.db.execute(sql, args)
     return [row[0] for row in cursor]
Beispiel #8
0
 def get_ltg_members(self, ltgid):
     table_name = "ltg"
     l_key = ["ltid"]
     l_cond = [db_common.cond("ltgid", "=", "ltgid")]
     args = {"ltgid" : ltgid}
     sql = self.db.select_sql(table_name, l_key, l_cond)
     cursor = self.db.execute(sql, args)
     return [int(row[0]) for row in cursor]
Beispiel #9
0
    def update_log(self, d_cond, d_update):
        if len(d_cond) == 0:
            _logger.warn("called update with empty condition")
            #raise ValueError("called update with empty condition")
        args = d_cond.copy()

        table_name = "log"
        l_ss = []
        for k, v in d_update.iteritems():
            #assert k in ("ltid", "top_dt", "end_dt", "host")
            keyname = "update_" + k
            l_ss.append(db_common.setstate(k, keyname))
            args[keyname] = v
        l_cond = []
        for c in d_cond.keys():
            if c == "ltgid":
                sql= self.db.select_sql("ltg", ["ltid"],
                        [db_common.cond(c, "=", c)])
                l_cond.append(db_common.cond("ltid", "in", sql, False))
            elif c == "area":
                sql= self.db.select_sql("area", ["host"],
                        [db_common.cond(c, "=", c)])
                l_cond.append(db_common.cond("host", "in", sql, False))
            elif c == "top_dt":
                l_cond.append(db_common.cond("dt", ">=", c))
                args[c] = self.db.strftime(d_cond[c])
            elif c == "end_dt":
                l_cond.append(db_common.cond("dt", "<", c))
                args[c] = self.db.strftime(d_cond[c])
            else:
                l_cond.append(db_common.cond(c, "=", c))
        sql = self.db.update_sql(table_name, l_ss, l_cond)
        self.db.execute(sql, args)
Beispiel #10
0
    def _select_log(self, d_cond):
        if len(d_cond) == 0:
            raise ValueError("called select with empty condition")
        args = d_cond.copy()

        table_name = "log"
        l_key = ["lid", "ltid", "dt", "host", "words"]
        l_cond = []
        for c in d_cond.keys():
            if c == "ltgid":
                sql= self.db.select_sql("ltg", ["ltid"],
                        [db_common.cond(c, "=", c)])
                l_cond.append(db_common.cond("ltid", "in", sql, False))
            elif c == "area":
                sql= self.db.select_sql("area", ["host"],
                        [db_common.cond(c, "=", c)])
                l_cond.append(db_common.cond("host", "in", sql, False))
            elif c == "top_dt":
                l_cond.append(db_common.cond("dt", ">=", c))
                args[c] = self.db.strftime(d_cond[c])
            elif c == "end_dt":
                l_cond.append(db_common.cond("dt", "<", c))
                args[c] = self.db.strftime(d_cond[c])
            else:
                l_cond.append(db_common.cond(c, "=", c))
        sql = self.db.select_sql(table_name, l_key, l_cond)
        return self.db.execute(sql, args)
Beispiel #11
0
    def update_log(self, d_cond, d_update):
        if len(d_cond) == 0:
            raise ValueError("called update with empty condition")
        args = d_cond.copy()

        table_name = "log"
        l_ss = []
        for k, v in d_update.iteritems():
            assert k in ("ltid", "top_dt", "end_dt", "host")
            keyname = "update_" + k
            l_ss.append(db_common.setstate(k, keyname))
            args[keyname] = v
        l_cond = []
        for c in d_cond.keys():
            if c == "ltgid":
                sql= self.db.select_sql("ltg", ["ltid"],
                        [db_common.cond(c, "=", c)])
                l_cond.append(db_common.cond("ltid", "in", sql, False))
            elif c == "area":
                sql= self.db.select_sql("area", ["host"],
                        [db_common.cond(c, "=", c)])
                l_cond.append(db_common.cond("host", "in", sql, False))
            elif c == "top_dt":
                l_cond.append(db_common.cond("dt", ">=", c))
                args[c] = self.db.strftime(d_cond[c])
            elif c == "end_dt":
                l_cond.append(db_common.cond("dt", "<", c))
                args[c] = self.db.strftime(d_cond[c])
            else:
                l_cond.append(db_common.cond(c, "=", c))
        sql = self.db.update_sql(table_name, l_ss, l_cond)
        self.db.execute(sql, args)
Beispiel #12
0
    def _select_log(self, d_cond):
        if len(d_cond) == 0:
            raise ValueError("called select with empty condition")
        args = d_cond.copy()

        table_name = "log"
        l_key = ["lid", "ltid", "dt", "host", "words"]
        l_cond = []
        for c in d_cond.keys():
            if c == "ltgid":
                sql= self.db.select_sql("ltg", ["ltid"],
                        [db_common.cond(c, "=", c)])
                l_cond.append(db_common.cond("ltid", "in", sql, False))
            elif c == "area":
                sql= self.db.select_sql("area", ["host"],
                        [db_common.cond(c, "=", c)])
                l_cond.append(db_common.cond("host", "in", sql, False))
            elif c == "top_dt":
                l_cond.append(db_common.cond("dt", ">=", c))
                args[c] = self.db.strftime(d_cond[c])
            elif c == "end_dt":
                l_cond.append(db_common.cond("dt", "<", c))
                args[c] = self.db.strftime(d_cond[c])
            else:
                l_cond.append(db_common.cond(c, "=", c))
        sql = self.db.select_sql(table_name, l_key, l_cond)
        return self.db.execute(sql, args)
Beispiel #13
0
    def update_lt(self, ltid, ltw, lts, count):
        table_name = "lt"
        l_ss = []
        args = {}
        if ltw is not None:
            l_ss.append(db_common.setstate("ltw", "ltw"))
            args["ltw"] = self._splitter.join(ltw)
        if lts is not None:
            l_ss.append(db_common.setstate("lts", "lts"))
            args["lts"] = self._splitter.join(lts)
        if count is not None:
            l_ss.append(db_common.setstate("count", "count"))
            args["count"] = count
        l_cond = [db_common.cond("ltid", "=", "ltid")]
        args["ltid"] = ltid

        sql = self.db.update_sql(table_name, l_ss, l_cond)
        self.db.execute(sql, args)
Beispiel #14
0
    def update_lt(self, ltid, ltw, lts, count):
        table_name = "lt"
        l_ss = []
        args = {}
        if ltw is not None:
            l_ss.append(db_common.setstate("ltw", "ltw"))
            args["ltw"] = self._splitter.join(ltw)
        if lts is not None:
            l_ss.append(db_common.setstate("lts", "lts"))
            args["lts"] = self._splitter.join(lts)
        if count is not None:
            l_ss.append(db_common.setstate("count", "count"))
            args["count"] = count
        l_cond = [db_common.cond("ltid", "=", "ltid")]
        args["ltid"] = ltid

        sql = self.db.update_sql(table_name, l_ss, l_cond)
        self.db.execute(sql, args)