def _store(self, text, pdf): sender, title = self._parse_file_name(pdf) relevant_tags = [t for t in Tag.objects.all() if t.matches(text.lower())] stats = os.stat(pdf) self._render(" Saving record to database", 2) doc = Document.objects.create( sender=sender, title=title, content=text, created=timezone.make_aware( datetime.datetime.fromtimestamp(stats.st_mtime)), modified=timezone.make_aware( datetime.datetime.fromtimestamp(stats.st_mtime)) ) if relevant_tags: tag_names = ", ".join([t.slug for t in relevant_tags]) self._render(" Tagging with {}".format(tag_names), 2) doc.tags.add(*relevant_tags) with open(pdf, "rb") as unencrypted: with open(doc.pdf_path, "wb") as encrypted: self._render(" Encrypting", 3) encrypted.write(GnuPG.encrypted(unencrypted))
def _store(self, text, doc): sender, title, tags, file_type = self._guess_attributes_from_name(doc) relevant_tags = set(list(Tag.match_all(text)) + list(tags)) stats = os.stat(doc) self.log("debug", "Saving record to database") document = Document.objects.create( sender=sender, title=title, content=text, file_type=file_type, created=timezone.make_aware( datetime.datetime.fromtimestamp(stats.st_mtime)), modified=timezone.make_aware( datetime.datetime.fromtimestamp(stats.st_mtime)) ) if relevant_tags: tag_names = ", ".join([t.slug for t in relevant_tags]) self.log("debug", "Tagging with {}".format(tag_names)) document.tags.add(*relevant_tags) with open(doc, "rb") as unencrypted: with open(document.source_path, "wb") as encrypted: self.log("debug", "Encrypting") encrypted.write(GnuPG.encrypted(unencrypted)) self.log("info", "Completed")
def _store(self, text, doc): sender, title, tags, file_type = self._guess_attributes_from_name(doc) tags = list(tags) lower_text = text.lower() relevant_tags = set( [t for t in Tag.objects.all() if t.matches(lower_text)] + tags) stats = os.stat(doc) Log.debug("Saving record to database", Log.COMPONENT_CONSUMER) document = Document.objects.create( sender=sender, title=title, content=text, file_type=file_type, created=timezone.make_aware( datetime.datetime.fromtimestamp(stats.st_mtime)), modified=timezone.make_aware( datetime.datetime.fromtimestamp(stats.st_mtime)) ) if relevant_tags: tag_names = ", ".join([t.slug for t in relevant_tags]) Log.debug( "Tagging with {}".format(tag_names), Log.COMPONENT_CONSUMER) document.tags.add(*relevant_tags) with open(doc, "rb") as unencrypted: with open(document.source_path, "wb") as encrypted: Log.debug("Encrypting", Log.COMPONENT_CONSUMER) encrypted.write(GnuPG.encrypted(unencrypted))
def _store(self, text, doc, thumbnail): file_info = FileInfo.from_path(doc) stats = os.stat(doc) self.log("debug", "Saving record to database") with open(doc, "rb") as f: document = Document.objects.create( correspondent=file_info.correspondent, title=file_info.title, content=text, file_type=file_info.extension, checksum=hashlib.md5(f.read()).hexdigest(), created=timezone.make_aware( datetime.datetime.fromtimestamp(stats.st_mtime)), modified=timezone.make_aware( datetime.datetime.fromtimestamp(stats.st_mtime)) ) relevant_tags = set(list(Tag.match_all(text)) + list(file_info.tags)) if relevant_tags: tag_names = ", ".join([t.slug for t in relevant_tags]) self.log("debug", "Tagging with {}".format(tag_names)) document.tags.add(*relevant_tags) # Encrypt and store the actual document with open(doc, "rb") as unencrypted: with open(document.source_path, "wb") as encrypted: self.log("debug", "Encrypting the document") encrypted.write(GnuPG.encrypted(unencrypted)) # Encrypt and store the thumbnail with open(thumbnail, "rb") as unencrypted: with open(document.thumbnail_path, "wb") as encrypted: self.log("debug", "Encrypting the thumbnail") encrypted.write(GnuPG.encrypted(unencrypted)) self.log("info", "Completed") return document
def _store(self, text, doc, thumbnail): file_info = FileInfo.from_path(doc) stats = os.stat(doc) self.log("debug", "Saving record to database") document = Document.objects.create( correspondent=file_info.correspondent, title=file_info.title, content=text, file_type=file_info.extension, created=timezone.make_aware( datetime.datetime.fromtimestamp(stats.st_mtime)), modified=timezone.make_aware( datetime.datetime.fromtimestamp(stats.st_mtime))) relevant_tags = set(list(Tag.match_all(text)) + list(file_info.tags)) if relevant_tags: tag_names = ", ".join([t.slug for t in relevant_tags]) self.log("debug", "Tagging with {}".format(tag_names)) document.tags.add(*relevant_tags) # Encrypt and store the actual document with open(doc, "rb") as unencrypted: with open(document.source_path, "wb") as encrypted: self.log("debug", "Encrypting the document") encrypted.write(GnuPG.encrypted(unencrypted)) # Encrypt and store the thumbnail with open(thumbnail, "rb") as unencrypted: with open(document.thumbnail_path, "wb") as encrypted: self.log("debug", "Encrypting the thumbnail") encrypted.write(GnuPG.encrypted(unencrypted)) self.log("info", "Completed") return document
def _import_files_from_manifest(self): for record in self.manifest: if not record["model"] == "documents.document": continue doc_file = record["__exported_file_name__"] document = Document.objects.get(pk=record["pk"]) with open(doc_file, "rb") as unencrypted: with open(document.source_path, "wb") as encrypted: print("Encrypting {} and saving it to {}".format( doc_file, document.source_path)) encrypted.write(GnuPG.encrypted(unencrypted))
def _store(self, text, pdf): sender, title = self._parse_file_name(pdf) stats = os.stat(pdf) self._render(" Saving record to database", 2) doc = Document.objects.create( sender=sender, title=title, content=text, created=timezone.make_aware(datetime.datetime.fromtimestamp(stats.st_mtime)), modified=timezone.make_aware(datetime.datetime.fromtimestamp(stats.st_mtime)), ) with open(pdf, "rb") as unencrypted: with open(doc.pdf_path, "wb") as encrypted: self._render(" Encrypting", 3) encrypted.write(GnuPG.encrypted(unencrypted))
def _store(self, text, pdf): sender, title = self._parse_file_name(pdf) stats = os.stat(pdf) self._render(" Saving record to database", 2) doc = Document.objects.create( sender=sender, title=title, content=text, created=timezone.make_aware( datetime.datetime.fromtimestamp(stats.st_mtime)), modified=timezone.make_aware( datetime.datetime.fromtimestamp(stats.st_mtime))) with open(pdf, "rb") as unencrypted: with open(doc.pdf_path, "wb") as encrypted: self._render(" Encrypting", 3) encrypted.write(GnuPG.encrypted(unencrypted))