def _determineMatchingDBFile(session, fileSize, md1, md5, ed2k): # DOC {{{ """Returns the DBFile() that matches the size, the MD5 sum of the first megabyte, the MD5 sum of the entire file and the ED2K sum of the specified DBFile() and is already registered in the register. Parameters session -- an instance of the SQLAlchemy's Session() fileSize -- the size of the file to look for in bytes md1 -- the MD5 sum of the first megabyte of the file md1 -- the MD5 sum of the entire file ed2k -- the ED2K sum of the entire file """ # }}} # CODE {{{ dbfs = DBFileRegister.query( session = session, fileSize = fileSize, md1 = md1, md5 = md5, ed2k = ed2k, ) if ((dbfs is None) or (len(dbfs) == 0)): return None else: return dbfs[0]
def query(self): """ Query the register for any entry matching the parameters. Only parts of the entry have to match the given parameters (ilike) """ ff = None if (isinstance(self.files, list)): if len(self.files) > 1: print("Please provide just one name or none at all!") return elif len(self.files) == 1: ff = self.files[0] # create a new query arguments dbFileQueryArguments = DBFileQueryArguments() # add a query argument matching the file's ID if it is specified {{{ if (self.fileId is not None): dbFileQueryArguments.fileId = self.fileId # }}} # add a query argument matching the file's name if it is specified {{{ if (ff is not None): dbFileQueryArguments.fileName = ff # }}} # add a query argument matching the file's group if it is specified {{{ if (self.group is not None): dbFileQueryArguments.group = self.group # }}} # add a query argument matching the file's comment if it is specified {{{ if (self.comment is not None): dbFileQueryArguments.comment = self.comment # }}} with self.dbConnection.getSessionContext() as session: ll = DBFileRegister.query(session, dbFileQueryArguments) if (ll is None): print("No record matches the query!") else: formatDBFileMethod = self._formatDBFile if self.queryasmysum: formatDBFileMethod = self._formatDBFileAsMysum elif self.queryed2k: formatDBFileMethod = self._formatDBFileAsED2K elif self.queryverbose: formatDBFileMethod = functools.partial(self._formatDBFile, verbose = True) for dbf in ll: print(formatDBFileMethod(dbf))
def _determineFileMightBeRegistered(session, fileSize, md1): # DOC {{{ """Returns True if there is a registered file of the size and the MD5 sum of the first megabyte specified in the provided DBFile(), False otherwise. Parameters session -- an instance of the SQLAlchemy's Session() fileSize -- the size of the file to look for in bytes md1 -- the MD5 sum of the first megabyte of the file """ # }}} # CODE {{{ dbfs = DBFileRegister.query( session = session, fileSize = fileSize, md1 = md1, ) return (dbfs is not None)