def has_been_imported(self, p): """ Indicates whether there is an existing file record for this file. """ relpath = os.path.relpath(p, self.rootpath) record = FileRecord.get_by_path(relpath) return record is not None
def create_file_record(parser, app): """ Creates the initial database entry for a specific file. """ # lookup file metadata first. relpath = parser.get_relpath() record = FileRecord.get_by_path(relpath) if record is not None: # This is done on ingest, but we'll check again to make sure. app.log.info("Found existing file record for %s" % (relpath)) return record # Check the MD5 hash to make sure that this isn't a file that has moved # TODO simplify this by using py.path in the parser md5 = path(parser.filepath).read_hexhash("md5") record = FileRecord.find(md5) if record is not None: # TODO should we require user input? app.log.warn("Found duplicate file: $s is the currently stored as %s" % (relpath, record.filepath)) record.update(relpath) else: app.log.info("Creating a file record for %s" % (relpath)) description = "" if parser.misc is not None: description = parser.misc if parser.searchable: description = description + " (searchable)" len(str(md5)) record = FileRecord( md5=md5, description=description.strip(), filepath=relpath, last_updated=datetime.datetime.now(), last_checked=datetime.datetime.now(), ) record.save() return record