Skip to content
Snippets Groups Projects
Commit 1f7b6fe2 authored by Andreas Domanowski's avatar Andreas Domanowski
Browse files

Add check whether archive file exists

parent 127c4906
Branches ivy-repo
No related tags found
1 merge request!1Hedgedoc import
...@@ -24,7 +24,8 @@ def prepare_target_dir(pathname): ...@@ -24,7 +24,8 @@ def prepare_target_dir(pathname):
"""Create the directory to dump documents to, but refuse to override an existing one.""" """Create the directory to dump documents to, but refuse to override an existing one."""
target_dir = Path(pathname) target_dir = Path(pathname)
if target_dir.exists(): if target_dir.exists():
raise SystemExit(f"error: the target directory {target_dir} already exists") raise SystemExit(f"ERROR: the target directory {target_dir} already exists. Delete it, then re-execute this "
f"script")
target_dir.mkdir() target_dir.mkdir()
return target_dir return target_dir
......
...@@ -33,7 +33,16 @@ def import_single_document(instance_url, hedgedoc_free_url, content, session_id) ...@@ -33,7 +33,16 @@ def import_single_document(instance_url, hedgedoc_free_url, content, session_id)
return response.url return response.url
def check_archive_exists(archive_file):
if not os.path.exists(archive_file):
raise SystemExit(
f"ERROR: File {archive_file} does not exist. Export your data from CodiMD and re-execute this script again!"
f" Aborting...")
def import_into_hedgedoc(instance_url, session_id, export_folder, archive_file): def import_into_hedgedoc(instance_url, session_id, export_folder, archive_file):
print("Beginning import")
check_archive_exists(archive_file)
check_accessibility(instance_url, session_id) check_accessibility(instance_url, session_id)
# let user select browser # let user select browser
browser = select_browser() browser = select_browser()
......
...@@ -4,5 +4,7 @@ from hedgedoc_import import import_into_hedgedoc ...@@ -4,5 +4,7 @@ from hedgedoc_import import import_into_hedgedoc
if __name__ == "__main__": if __name__ == "__main__":
export_folder = "codimd-documents" export_folder = "codimd-documents"
export_archive = "archive.zip"
export_from_codimd("http://localhost:3001", get_sessionid("CodiMD", "connect.sid"), export_folder) export_from_codimd("http://localhost:3001", get_sessionid("CodiMD", "connect.sid"), export_folder)
import_into_hedgedoc("http://hedgedoc:3000", get_sessionid("HedgeDoc", "connect.hedgeDoc.sid"), export_folder, "archive.zip") import_into_hedgedoc("http://hedgedoc:3000", get_sessionid("HedgeDoc", "connect.hedgeDoc.sid"), export_folder,
export_archive)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment