Exemplo n.º 1
0
def store_infos(infos, extra_db_entries):
  print " %s" % (infos)
  #web.debug(" %s" % (infos))
  simple_infos = infos.copy()
  multiple_infos = {}
  for imv in config.have_many_values:
    try:
      del simple_infos[imv]
      multiple_infos[imv] = infos[imv]
    except KeyError:
      pass
  #checking for file renaming with sha
  possiblePrevFiles = db.query("select id, filename, batch from images where sha ='"+infos['sha']+"'")
  updatingFile = False
  if len(possiblePrevFiles) == 1:
    #file found in db
    print "INFO duplicate found : "+infos['filename']
    prevFile = possiblePrevFiles[0]
    file_id = prevFile.id
    simple_infos['batch'] = prevFile.batch
    try:
      extra_db_entries.remove(prevFile.filename)
      db.update('images', 'id = %s' % file_id, None, **simple_infos)
      updatingFile = True
    except ValueError:
      #raise with .remove when the filename do not match
      print "WARNING duplicate sha accross fileset, creating new entry"
  else:
    if len(possiblePrevFiles) > 1:
      #more than one file with this sha... 
      print "INFO sha present multiple time for file : "+infos["filename"]
    file_id = db.insert('images', True, **simple_infos)

  for index in multiple_infos.keys():
    #store the value in its table
    for value in multiple_infos[index]:
      try:
        value_id = db.insert(index+'s', True, **{"value" : value})
        #debuginsert(index+'s', False, **{"value" : value})
      except: 
        #TODO should be IntegrityError for mysql but not sure how best integrate that without breaking the DB abstraction...
        #but if the error wasn't an IntegrityError then the next line should fail
        value_id = db.query('select id from %ss where value = "%s"' % (index, value))[0].id
      #store the relationship between the value and the file
      try:
        db.insert("images_"+index+'s', False, **{index+"_id": value_id, "image_id" : file_id})
      except Exception, inst:
        #if we are update a file we might raise some integrity error here
        if updatingFile:
          pass
        else:
          raise inst
Exemplo n.º 2
0
def add(palabro, hint, description):
    new_publish = db.select("palabros", what="DATE_ADD(MAX(publish), INTERVAL 1 DAY) AS new_publish")[0]["new_publish"]
    db.insert("palabros", palabro=palabro, hint=hint, description=description, publish=new_publish)