def updateSnap(self,snp,imx=None):
    tp = snp.get("topic",None)
    if tp:
      idx = int(pathLast(tp))
    else:
      raise Exception("internal error: missing idx")
    global snapProps
    conn = self.connection
    tm = int(time.time()*1000)
    cv = snp.get("coverage",None)
    cvv = None
    if type(cv)==str:
      cvv = cv
    elif cv:
      if imx:
        cv = scaleRectDict(cv,1.0/imx)
      cvv = json.dumps(cv)
    cls = []
    vls = []
    for sp in snapProps:
      if sp == "coverage":
        vl = cvv
      else:
        vl = snp.get(sp,None)
      if vl != None:
        vls.append(vl)
        cl = sp +  " = ?"
        cls.append(cl)
    stmt = "update snaps set "+(",".join(cls))+" where idx="+str(idx)
    writeToDb(conn,stmt,vls)

    #cursor.execute(stmt,vls)
    #'insert into snaps (created,isCurrent,owner,caption,cropid,description,coverage) values (?,?,?,?,?,?,?)',vls)
    #conn.commit()
    return idx
 def newVersion(self, id):
     snp = self.getSnap0(id)
     #ctm = snp.get("current_item_create_time")
     idx = snp.get("idx")
     tm = int(time.time() * 1000)
     vprint("SNP", snp)
     rs = self.newSnap(snp, None, id)
     stmt = "update snaps set is_current_version = 0 where idx=" + str(idx)
     writeToDb(self.connection, stmt)
     return rs
 def newVersion(self,snp):
   ctm = snp.get("current_item_create_time")
   tm = int(time.time() * 1000)
   self.newSnap(snp)
   tp = snp.get("topic",None)
   if tp:
     idx = int(pathLast(tp))
   else:
     raise Exception("internal error: missing idx")
   stt ="created = ?"
   stmt = "update snaps set created=? where idx="+str(idx)
   writeToDb(conn,stmt,[ctm])
def deleteSnap(tp,pageStore=None):
  snidx = pathLast(tp)
  alb = snapTopicToAlbumTopic(tp)
  store = storeForAlbum(alb,False,pageStore=pageStore)
  vprint("STORE ",store)
  if store==None: return False
  conn = store.connection
  sp = snapProps
  stmt = "delete from snaps where idx = "+snidx+" and created=-1"
  vprint(stmt)
  writeToDb(conn,stmt)
  #c.execute(stmt)
  #conn.commit()
  return True
  def newSnap(self,snp,imx=None):
    global snapProps
    conn = self.connection
    tm = int(time.time()*1000)
    cv = snp["coverage"]
    pb = snp.get("published",0)
    ord = snp.get("ordinal",-1)
    vprint("CV",cv,imx)
    if type(cv)==str:
      cvv = cv
    else:
      if imx:
        cv = scaleRectDict(cv,1.0/imx)
      cvv = json.dumps(cv)
      vprint("CVV",cvv)
    sp = snapProps
    vls = (-1,tm,snp[sp[2]],snp[sp[3]],snp[sp[4]],snp[sp[5]],snp[sp[6]],cvv,pb,ord)
    stmt = 'insert into snaps ('
    qmarks = []
    for p in snapProps:
      qmarks.append("?")
    stmt += ",".join(snapProps)
    stmt = stmt + ") values (" + ",".join(qmarks)
    stmt += ")"
    #print stmt
    rs = writeToDb(conn,stmt,vls,True)

    #cursor.execute(stmt,vls)
    #'insert into snaps (created,isCurrent,owner,caption,cropid,description,coverage) values (?,?,?,?,?,?,?)',vls)
    #rs = cursor.lastrowid
    #conn.commit()
    return rs
Exemple #6
0
 def newJob(self,jb):
   global snapProps
   conn = self.openConnection()
   tm = int(time.time()*1000)
   jb["start_time"] = tm
   jb["so_far"]=0
   if jb.get("status") == None:
     jb["status"] = "not_started"
   jb["error"] = None
   jb["resources_used"] = None
   if jb.get("retries",None) == None:
     jb["retries"] = 0
   sp = jobProps
   vls = (jb[sp[0]],jb[sp[1]],jb[sp[2]],jb[sp[3]],jb[sp[4]],jb[sp[5]],jb[sp[6]],jb[sp[7]],jb[sp[8]],jb[sp[9]])
   stmt = 'insert into jobs ('
   qmarks = []
   for p in jobProps:
     qmarks.append("?")
   stmt += ",".join(jobProps)
   stmt = stmt + ") values (" + ",".join(qmarks)
   stmt += ")"
   vprint("newJob",stmt)
   rs = writeToDb(conn,stmt,vls,True)
   jb["topic"] = "/job/"+jb["owner"]+"/"+str(rs)
   self.closeConnection()
Exemple #7
0
    def updateEntry(self, tb, idx, updates):
        conn = self.openConnection()
        cls = []
        vls = []
        props = self.tables[tb]
        for p in props:
            pn = p[0]
            vl = updates.get(pn, None)
            if vl != None:
                vls.append(vl)
                cl = pn + " = ?"
                cls.append(cl)
        stmt = "update " + tb + " set " + (
            ",".join(cls)) + " where idx=" + str(idx)
        #print stmt
        #print vls
        writeToDb(conn, stmt, vls)

        #cursor.execute(stmt,vls)
        #cursor.close()
        #'insert into snaps (created,isCurrent,owner,caption,cropid,description,coverage) values (?,?,?,?,?,?,?)',vls)
        #conn.commit()
        return idx
Exemple #8
0
 def updateJob(self,jb):
   
   tp = jb["topic"]
   idx = pathLast(tp)
   global jobProps
   conn = self.openConnection()
   tm = int(time.time()*1000)
   cls = []
   vls = []
   for sp in jobProps:
     vl = jb.get(sp,None)
     if vl != None:
       vls.append(vl)
       cl = sp +  " = ?"
       cls.append(cl)
   stmt = "update jobs set "+(",".join(cls))+" where idx="+str(idx)
   vprint("updateJob",vls)
   writeToDb(conn,stmt,vls)
   self.closeConnection()
   
   #cursor.execute(stmt,vls)
   #'insert into snaps (created,isCurrent,owner,caption,cropid,description,coverage) values (?,?,?,?,?,?,?)',vls)
   #conn.commit()
   return idx
Exemple #9
0
 def newEntry(self, tb, vls):
     conn = self.openConnection()
     props = self.tables[tb]
     #vls = (day,album,bytes,owner)
     stmt = 'insert into ' + tb + ' ('
     qmarks = []
     for p in props:
         qmarks.append("?")
     propnames = [p[0] for p in props]
     stmt += ",".join(propnames)
     stmt = stmt + ") values (" + ",".join(qmarks)
     stmt += ")"
     rs = writeToDb(conn, stmt, vls, returnLastRow=True)
     #cursor.execute(stmt,vls)
     #rs = cursor.lastrowid
     #cursor.close()
     #conn.commit()
     return rs
Exemple #10
0
    def newSnap(self, snp, imx=None, id=-1):
        global snapProps
        vprint("SNP in newSnap", snp)
        conn = self.connection
        tm = int(time.time() * 1000)
        cv = snp["coverage"]
        pb = snp.get("published", 0)
        ord = snp.get("ordinal", -1)
        vprint("CV", cv, imx)
        if type(cv) == str:
            cvv = cv
        else:
            if imx:
                cv = scaleRectDict(cv, 1.0 / imx)
            cvv = json.dumps(cv)
            vprint("CVV", cvv)
        sp = snapProps
        #                  ["idx","created","caption"2,"owner"3,"cropid"4,"description"5,"shares_coverage","coverage"6,"published","ordinal","talk","replicates","id"]
        #(idx integer primary key,created int,caption text 2,owner text 3,cropid int4,description text5,shares_coverage int6,coverage text,published int,ordinal int,talk text,replicates int,id int)''')

        vls = (tm, snp[sp[2]], snp[sp[3]], snp[sp[4]], snp[sp[5]], snp[sp[6]],
               cvv, pb, ord, "", -1, 1, id)
        stmt = 'insert into snaps ('
        qmarks = []

        for p in snapProps:
            if p != "idx":
                qmarks.append("?")
        stmt += ",".join(snapProps[1:])
        stmt = stmt + ") values (" + ",".join(qmarks)
        stmt += ")"
        #print stmt
        rs = writeToDb(conn, stmt, vls, True)  # this returns the
        #cursor.execute(stmt,vls)
        #'insert into snaps (created,isCurrent,owner,caption,cropid,description,coverage) values (?,?,?,?,?,?,?)',vls)
        #rs = cursor.lastrowid
        #conn.commit()

        return rs
 def setOrdinal(self,idx,ord):
   stmt = "update snaps set ordinal = ? where idx=?"
   vls = [ord,idx]
   writeToDb(self.connection,stmt,vls)