| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- import csv
- import os
- import sys
- import zipfile
-
- from datetime import datetime
-
-
- def get_humane_date(timestamp, date_format):
- return datetime.fromtimestamp(timestamp).strftime(date_format)
-
-
- def write_csv(csv_path, FIELD_NAMES, rows):
- with open(csv_path, "w", encoding="UTF8", newline="") as file:
- writer = csv.DictWriter(file, fieldnames=FIELD_NAMES)
- writer.writeheader()
- writer.writerows(rows)
-
-
- def package_zip(zip_path, absolute_starting_path, zip_root_path, csv_path):
- shutil.make_archive(
- zip_path.replace(".zip", ""),
- "zip",
- absolute_starting_path.replace(zip_root_path, ""),
- zip_root_path,
- )
- zip = zipfile.ZipFile(zip_path, "a")
- zip.write(csv_path, os.path.basename(csv_path))
- zip.close()
-
-
- def create_export_directory(CONFIG):
- if os.path.exists(CONFIG["export_directory"]) and os.path.isdir(
- CONFIG["export_directory"]
- ):
- os.system("rm '%s' -r" % (CONFIG["export_directory"]))
- os.makedirs(CONFIG["export_directory"])
-
-
- def is_import_directory_okay(path):
- if not os.path.exists(path):
- raise ValueError("aborting: import directory path does not exist")
- if not os.path.isdir(path):
- raise ValueError("aborting: import directory path is not a directory")
- return True
-
-
- def get_document_space(CONFIG, current_path):
- relative_path = os.path.relpath(current_path, CONFIG["absolute_starting_path"])
- if relative_path == ".":
- document_space = CONFIG["document_space"]
- else:
- path = relative_path.replace(".", "_").replace("/", ".")
- document_space = f"{CONFIG['document_space']}.{path}"
- return document_space
-
-
- def get_attachments_folder_path(CONFIG, current_path):
- relative_path = os.path.relpath(current_path, CONFIG["absolute_starting_path"])
- if relative_path == ".":
- attachements_folder_path = os.path.basename(CONFIG["absolute_starting_path"])
- else:
- attachements_folder_path = relative_path.replace("/", ".")
- return attachements_folder_path
-
-
- def get_document_space_title(CONFIG, current_path):
- relative_path = os.path.relpath(current_path, CONFIG["absolute_starting_path"])
- if relative_path == ".":
- document_space_title = CONFIG["document_space_title"]
- else:
- document_space_title = os.path.basename(current_path)
- return document_space_title
|