Exemple #1
0
def create_file(userid, filename, mimetype, parentid):
  #fileid "1" is root for active user
  cur, con = mysql_connect()
    
  types  = [sq.int,   sq.int,     sq.str(255), sq.str(100), sq.str(100),   sq.str(255)]
  cols   = ["userid", "parentid", "mimeType", "name",      "other_meta",  "diskpath" ]
  values = [userid,   parentid,   mimetype,   filename,    "" ,           ""         ]
  
  try:
    qstr = sql_insertinto("filedata", cols, values, types)
  except SQLParamError:
    do_param_error("file creation, userid=" + str(userid) + ",  filename="+filename + ", mimetype=" + mimetype, "parentid="+str(parentid))
    raise SQLParamError()
    
  #cur.execute("INSERT INTO filedata (userid,parentid,mimeType,name) VALUES (%d,%d,\"%s\",\"%s\")"%(userid,parentid,mimetype,filename))
  
  cur.execute(qstr);
  con.commit()
  
  return db_engine.get_last_rowid(cur)
  
  cur.execute("SELECT LAST_INSERT_ID()")
  ret = cur.fetchone()
  
  return ret["LAST_INSERT_ID()"]
Exemple #2
0
def resolve_path(path):
  cs = path.split("/")
  while "" in cs:
    cs.remove("")
  
  if cs == None or len(cs) == 0:
    return ROOT_PARENT_ID
  
  parentid = ROOT_PARENT_ID
  cur, con = mysql_connect()
  
  for i, c in enumerate(cs):
    c = c.strip()
    
    types  = [sq.int,     sq.str(512)]
    cols   = ["parentid", "name"     ]
    values = [parentid,   c          ]
    
    try:
      qstr = sql_selectall("filedata", cols, values, types)
    except SQLParamError:
      do_param_error("resolve_path: \"%s\"" % path)
      raise SQLParamError
    
    cur.execute(qstr);
    ret = cur.fetchone()
    if ret == None:
      return None
    
    parentid = ret["fileid"];
    
  return parentid
Exemple #3
0
 def commit(self):
   cur, con = mysql_connect()
   
   dnow = datetime.datetime.now()
   dend = datetime.datetime.now()+datetime.timedelta(days=1)
   
   types   = [sq.token,   sq.path,       sq.datetime, sq.int     ]
   cols    = ["tokenid",  "path",        "time",      "fileid"   ]
   values  = [self.token, self.path,     dnow,        32423423] #we don't use database fileids in local mode
   
   types  += [sq.str(100), sq.path,       sq.int,      sq.int       ]
   cols   += ["name",      "realpath",    "userid",    "permissions"]
   values += [self.name,   self.realpath, self.userid, 0            ]
   
   types  += [sq.datetime,  sq.int,    sq.int  ]
   cols   += ["expiration", "size",    "cur"   ]
   values += [dend,         self.size, self.cur]
   
   try:
     qstr = sql_insertinto("uploadtokens", cols, values, types)
   except SQLParamError:
     #do_param_error(json.dumps(self));
     raise SQLParamError("upload token error; see error.log for details")
   
   print("QSTR", qstr)
   
   cur.execute(qstr)
   con.commit()
Exemple #4
0
 def commit(self):
   cur, con = mysql_connect()
   
   dnow = datetime.datetime.now()
   dend = datetime.datetime.now()+datetime.timedelta(days=1)
   
   types   = [sq.token,   sq.path,       sq.datetime, sq.int     ]
   cols    = ["tokenid",  "path",        "time",      "fileid"   ]
   values  = [self.token, self.path,     dnow,        self.fileid]
   
   types  += [sq.str(100), sq.path,       sq.int,      sq.int       ]
   cols   += ["name",      "realpath",    "userid",    "permissions"]
   values += [self.name,   self.realpath, self.userid, 0            ]
   
   types  += [sq.datetime,  sq.int,    sq.int  ]
   cols   += ["expiration", "size",    "cur"   ]
   values += [dend,         self.size, self.cur]
   
   try:
     qstr = sql_insertinto("uploadtokens", cols, values, types)
   except SQLParamError:
     do_param_error(json.dumps(self));
     raise SQLParamError("upload token error; see error.log for details")
     
   """
   qstr = "INSERT INTO uploadtokens (tokenid,path,time,fileid,"
   qstr += "name,realpath,userid,permissions,expiration,size,cur) VALUES"
   qstr += "(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)" % (
     estr(self.token),
     estr(self.path),
     estr(datetime.datetime.now()),
     estr(self.fileid),
     estr(self.name),
     estr(self.realpath),
     estr(self.userid),
     estr(0),
     estr(datetime.datetime.now()+datetime.timedelta(days=1)),
     estr(self.size),
     estr(self.cur),
   )
   #"""
   
   cur.execute(qstr)
   con.commit()
Exemple #5
0
  
  if ret == None:
    errlog("Warning: invalid fileid %s"%fileid)
    return None
  
  if ret["mimeType"] == FOLDER_MIME:
    f = Folder(ret)
  else:
    f = File(ret)
  
  return f

filetypes = {
  "fileid" : sq.int,
  "parentid" : sq.int,
  "name" : sq.str(512),
  "mimeType" : sq.str(255),
  "other_meta" : sq.str(1024*4),
  "userid" : sq.int,
  "diskpath" : sq.str(512)
}
def update_file(fileid, meta):
  f = fetch_file(fileid)
  
  if f == None:
    errlog("Update for fileid %s failed; invalid id"%fileid)
    return
  
  cur, con = mysql_connect()
  for k in f:
    if k in meta and type(meta[k]) != type(f[k]):