def __init__(self,init='#'): if init=='#': print "product ID is missing" return self.productid=init self.db=dbif.gencur() self.getProduct(init) pass
def __init__(self, itemID, closeStatus='#'): self.db = dbif.gencur("select 'none';") qry = "SELECT ID, STATUS, pid, agentid, targetid, note, LAST_UPDATE FROM queue where ID='%s';" % itemID self.db.cur.execute(qry) rec = self.db.cur.fetchone() if rec == None: #no record found self.id = "#" return self.id = rec[0] self.status = rec[1] self.pid = rec[2] self.agentid = rec[3] self.targetid = rec[4] self.note = rec[5] try: self.note = json.loads(self.note) except: pass self.last_update = rec[6] self.closeStatus = closeStatus self.emergencyDataset = "#" #Get the target characteristic self.connection = dbif.getTargetList("id='%s'" % self.targetid)[0] self.targettype = self.connection['type'] self.rep = self.connection['rep'].replace('$PRJ', prjFolder) self.fullpath = self.rep + os.sep + self.id #Get the download agent characteristic qry = "SELECT ID, cli FROM agent where id='%s';" % self.agentid self.db.cur.execute(qry) rec = self.db.cur.fetchone() if rec != None: self.agentcli = rec[1] else: self.agentcli = "ERROR: Agent CLI not found!" #Get the list of files to be downloaded qry = "SELECT ID, filename, url, dwnstatus FROM files where qid='%s';" % itemID self.db.cur.execute(qry) rec = self.db.cur.fetchall() if rec == None: #no record found return self.files = list() for i in rec: x = dict() x['fileid'] = i[0] x['filename'] = i[1] x['url'] = i[2] x['dwnstatus'] = i[3] self.files.append(x) #Get the product characteristic self.product = libProduct.product(itemID) return
def comparedb(x): wkt=x.coordinatesWKT qry="SELECT id,`name`, AsText(geom) FROM country WHERE MBRContains(GeomFromText('%s'),geom);" % wkt db=dbif.gencur(qry) res=db.cur.fetchall() #print len(res) #import pprint #pprint.pprint(res) for icountry in res: print "adding tag %s" % icountry[1] x.addTag(icountry[1])
def catalogue(self): wkt=self.footprint qry="SELECT DISTINCT id,`name`, AsText(geom) FROM area WHERE MBRContains(GeomFromText('%s'),geom);" % wkt db=dbif.gencur(qry) res=db.cur.fetchall() for icountry in res: print "adding tag %s" % icountry[1] try: self.addTag(icountry[1]) except: print "ERROR: Failed to add tag %s" % icountry[1] traceback.print_exc(file=sys.stdout)
def main(): db = dbif.gencur('SELECT * FROM queue') for isql in sql: out = isql.strip().replace('\n', ' ')[:50] start = datetime.datetime.now() try: db.exe(isql) out += ' OK' except: out += ' ERROR' duration = datetime.datetime.now() - start print out + ' (%s sec)' % duration.seconds pass
def main(): db=dbif.gencur('SELECT * FROM queue') for isql in sql: out=isql.strip().replace('\n',' ')[:50] start = datetime.datetime.now() try: db.exe(isql) out+= ' OK' except: out+= ' ERROR' duration = datetime.datetime.now() - start print out + ' (%s sec)' % duration.seconds pass
def getqueue(self): self.db = dbif.gencur('SELECT * FROM queue limit 1;')