示例#1
0
def uploadMetaFile(filename, uri, dbname):

  if sut.isvalidsambametadatafilename(os.path.basename(filename)) is False:
    return False
  
  theServer = Server(uri)
  db = theServer.get_or_create_db(dbname)
  #print db.info()
  
  #with the meta file docs, I don't have to read anytihng inside of the doc!
  doc = {}
  doc['_id'] = os.path.basename(filename)
  doc['author'] = 'Samba'
  doc['type'] = 'daqmetadatadocuments'
  doc['date_uploaded'] = time.time()
  doc['file_lastmodified'] = os.path.getmtime(filename)
  doc['content'] = 'Meta Data DB Document for a particular Samba Run'
  doc['file'] = os.path.realpath(filename)
  doc['run_name'] = os.path.basename(filename).split('_')[0]
  
  doc['status'] = 'closed'
  doc['hostipaddress'] = socket.gethostbyname( socket.gethostname() )
  doc['hostname'] = socket.gethostname()
  doc['file_size'] = os.path.getsize(doc['file'])

  res = db.save_doc(doc)
  
  return res['ok']
示例#2
0
def getListOfNewSambaFiles(topDir, lastSambaFileDict):

    sambafiles = list()
    metafiles = list()
    sambaLetter = ""

    if os.path.isdir(topDir) == False:
        print topDir, "is not a directory"
        return sambafiles

    try:
        for dirpath, dirs, files in os.walk(topDir):
            for aFileName in files:

                parentdir = os.path.basename(dirpath)
                sambaLetter = parentdir[4]

                # check for data file
                if (
                    sut.isvalidsambadatafilename(aFileName)
                    and sut.isvalidsambarunname(parentdir)
                    and isFileOldEnough(os.path.join(dirpath, aFileName))
                ):

                    add = False

                    if lastSambaFileDict["samba"].has_key(sambaLetter):
                        if aFileName > lastSambaFileDict["samba"][sambaLetter]["lastfile"]:
                            add = True
                    else:
                        add = True

                    if add:
                        _appendToList(sambafiles, os.path.join(dirpath, aFileName), "samba data file found:")

                # check for meta data file
                if (
                    sut.isvalidsambametadatafilename(aFileName)
                    and sut.isvalidsambarunname(parentdir)
                    and isFileOldEnough(os.path.join(dirpath, aFileName))
                ):

                    add = False

                    if lastSambaFileDict["samba"].has_key(sambaLetter):
                        if aFileName > lastSambaFileDict["samba"][sambaLetter]["last_%s" % aFileName.split("_")[1]]:
                            add = True
                    else:
                        add = True

                    if add:
                        _appendToList(metafiles, os.path.join(dirpath, aFileName), "samba meta data file found:")
    except Exception as e:
        print aFileName, parentdir, sambaLetter, len(sambafiles), len(metafiles)
        raise e

    return sambafiles, metafiles
示例#3
0
  def setLastSambaMetaFile(self, aSambaMetaFileName):

    if sut.isvalidsambametadatafilename(aSambaMetaFileName) is False:
      raise TypeError('%s : Invalid Samba Meta Data File Name' % aSambaMetaFileName)

    trackerDoc = self.getTrackerDoc()
    sambakey = os.path.basename(aSambaMetaFileName)[4]
    metakey = 'last_%s' % os.path.basename(aSambaMetaFileName).split('_')[1]

    trackerDoc['samba'][sambakey][metakey] = os.path.basename(aSambaMetaFileName) 
    
    self._save_doc(trackerDoc)