예제 #1
0
    def autoUpdateFPR(self):
        self.maxLastUpdate = self.getMaxLastUpdate()
        maxLastUpdateAtStart = self.maxLastUpdate
        databaseInterface.runSQL("SET foreign_key_checks = 0;")
        for x in [("CommandRelationships",
                   self.fprserver + "CommandRelationship/"),
                  ("FileIDsBySingleID", self.fprserver + "FileIDsBySingleID/"),
                  ("FileIDs", self.fprserver + "FileID/"),
                  ("Commands", self.fprserver + "Command/"),
                  ("CommandTypes", self.fprserver + "CommandType/"),
                  ("CommandClassifications",
                   self.fprserver + "CommandClassification/"),
                  ("FileIDTypes", self.fprserver + "FileIDType/")]:
            table, url = x
            #params = {"format":"json", "order_by":"lastmodified", "lastmodified__gte":maxLastUpdateAtStart, "limit":"0"}
            params = {
                "format": "json",
                "order_by": "lastmodified",
                "lastmodified__gte": maxLastUpdateAtStart,
                "limit": "0"
            }
            entries = getFromRestAPI(url, params, verbose=False, auth=None)
            #print "test", entries
            for entry in entries:
                #print table, entry

                #check if it already exists
                sql = """SELECT pk FROM %s WHERE pk = '%s'""" % (table,
                                                                 entry['uuid'])
                if databaseInterface.queryAllSQL(sql):
                    #pass
                    continue

                if not 'replaces' in entry:
                    print >> sys.stderr, "Required entry 'replaces' missing."
                    print entry
                    #continue
                    exit(3)

                #If updating a disabled entry, it will continue to be disabled.
                if entry['replaces'] != None:
                    sql = """SELECT enabled FROM %s WHERE pk = '%s';""" % (
                        table, entry['replaces'])
                    enabled = databaseInterface.queryAllSQL(sql)[0][0]
                    if not enabled:
                        entry['enabled'] = 0
                    sql = """UPDATE %s SET enabled=FALSE WHERE pk = '%s';""" % (
                        table, entry['replaces'])
                    databaseInterface.runSQL(sql)

                self.create(table, entry)

        addLinks()
        databaseInterface.runSQL("SET foreign_key_checks = 1;")
        if self.maxLastUpdate != maxLastUpdateAtStart:
            self.setMaxLastUpdate(self.maxLastUpdate)
예제 #2
0
    def autoUpdateFPR(self):
        self.maxLastUpdate = self.getMaxLastUpdate()
        maxLastUpdateAtStart = self.maxLastUpdate
        databaseInterface.runSQL("SET foreign_key_checks = 0;")
        for x in [
            ("CommandRelationships", self.fprserver + "/fpr/api/v1/CommandRelationship/"),
            ("FileIDsBySingleID", self.fprserver + "/fpr/api/v1/FileIDsBySingleID/"),
            ("FileIDs", self.fprserver + "/fpr/api/v1/FileID/"),
            ("Commands", self.fprserver + "/fpr/api/v1/Command/"),
            ("CommandTypes", self.fprserver + "/fpr/api/v1/CommandType/"),
            ("CommandClassifications", self.fprserver + "/fpr/api/v1/CommandClassification/"),
            ("FileIDTypes", self.fprserver + "/fpr/api/v1/FileIDType/"),
        ]:
            table, url = x
            # params = {"format":"json", "order_by":"lastmodified", "lastmodified__gte":maxLastUpdateAtStart, "limit":"0"}
            params = {
                "format": "json",
                "order_by": "lastmodified",
                "lastmodified__gte": maxLastUpdateAtStart,
                "limit": "0",
            }
            entries = getFromRestAPI(url, params, verbose=False, auth=None)
            # print "test", entries
            for entry in entries:
                # print table, entry

                # check if it already exists
                sql = """SELECT pk FROM %s WHERE pk = '%s'""" % (table, entry["uuid"])
                if databaseInterface.queryAllSQL(sql):
                    # pass
                    continue

                if not "replaces" in entry:
                    print >> sys.stderr, "Required entry 'replaces' missing."
                    print entry
                    # continue
                    exit(3)

                # If updating a disabled entry, it will continue to be disabled.
                if entry["replaces"] != None:
                    sql = """SELECT enabled FROM %s WHERE pk = '%s';""" % (table, entry["replaces"])
                    enabled = databaseInterface.queryAllSQL(sql)[0][0]
                    if not enabled:
                        entry["enabled"] = 0
                    sql = """UPDATE %s SET enabled=FALSE WHERE pk = '%s';""" % (table, entry["replaces"])
                    databaseInterface.runSQL(sql)

                self.create(table, entry)

        addLinks()
        databaseInterface.runSQL("SET foreign_key_checks = 1;")
        if self.maxLastUpdate != maxLastUpdateAtStart:
            self.setMaxLastUpdate(self.maxLastUpdate)
예제 #3
0
         #print table, entry
         
         #check if it already exists
         sql = """SELECT pk FROM %s WHERE pk = '%s'""" % (table, entry['uuid'])
         if databaseInterface.queryAllSQL(sql):
             #pass
             continue
         
         if not 'replaces' in entry:
             print >>sys.stderr, "Required entry 'replaces' missing."
             print entry
             #continue
             exit(3)
             
         #If updating a disabled entry, it will continue to be disabled.
         if entry['replaces'] != None:
              sql = """SELECT enabled FROM %s WHERE pk = '%s';""" % (table, entry['replaces'])
              enabled=databaseInterface.queryAllSQL(sql)[0][0]
              if not enabled:
                  entry['enabled'] = 0
              sql = """UPDATE %s SET enabled=FALSE WHERE pk = '%s';""" % (table, entry['replaces'])
              databaseInterface.runSQL(sql)
              
         create(table, entry) 
         
 #createLinks()
 addLinks()
 databaseInterface.runSQL("SET foreign_key_checks = 1;")
 if maxLastUpdate != maxLastUpdateAtStart:
     setMaxLastUpdate(maxLastUpdate)
 print maxLastUpdate
예제 #4
0
            sql = """SELECT pk FROM %s WHERE pk = '%s'""" % (table,
                                                             entry['uuid'])
            if databaseInterface.queryAllSQL(sql):
                #pass
                continue

            if not 'replaces' in entry:
                print >> sys.stderr, "Required entry 'replaces' missing."
                print entry
                #continue
                exit(3)

            #If updating a disabled entry, it will continue to be disabled.
            if entry['replaces'] != None:
                sql = """SELECT enabled FROM %s WHERE pk = '%s';""" % (
                    table, entry['replaces'])
                enabled = databaseInterface.queryAllSQL(sql)[0][0]
                if not enabled:
                    entry['enabled'] = 0
                sql = """UPDATE %s SET enabled=FALSE WHERE pk = '%s';""" % (
                    table, entry['replaces'])
                databaseInterface.runSQL(sql)

            create(table, entry)

    #createLinks()
    addLinks()
    databaseInterface.runSQL("SET foreign_key_checks = 1;")
    if maxLastUpdate != maxLastUpdateAtStart:
        setMaxLastUpdate(maxLastUpdate)
    print maxLastUpdate