feature: complete target dir transfer logic
This commit is contained in:
parent
73462e4b83
commit
8886be3b6f
4 changed files with 49 additions and 24 deletions
|
@ -1,11 +1,12 @@
|
|||
from constants import SOURCE
|
||||
from constants import TARGET
|
||||
from lib.create_source_dir import create_source_dir
|
||||
from lib.create_target_dir import create_target_dir
|
||||
from lib.transfer_files import transfer_files
|
||||
|
||||
|
||||
def main():
|
||||
output_dir = create_source_dir()
|
||||
print(output_dir)
|
||||
target_dir = create_target_dir(TARGET, SOURCE)
|
||||
transfer_files(f"{TARGET}/{target_dir}", SOURCE)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
|
|
@ -1,21 +0,0 @@
|
|||
import os
|
||||
import shutil
|
||||
import uuid
|
||||
from termcolor import colored
|
||||
from constants import SOURCE, TARGET
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
def create_source_dir():
|
||||
unique_dir_name = uuid.uuid4()
|
||||
if os.path.isdir(TARGET):
|
||||
shutil.rmtree(TARGET)
|
||||
|
||||
# Create route directory and /static directory
|
||||
os.makedirs(f"{TARGET}/{str(unique_dir_name)}/static")
|
||||
print(
|
||||
colored(
|
||||
f"Created new Neuron output directory: {SOURCE}/{unique_dir_name}", "green"
|
||||
)
|
||||
)
|
||||
return unique_dir_name
|
28
src/lib/create_target_dir.py
Normal file
28
src/lib/create_target_dir.py
Normal file
|
@ -0,0 +1,28 @@
|
|||
import os
|
||||
import shutil
|
||||
import uuid
|
||||
from termcolor import colored
|
||||
|
||||
|
||||
def create_target_dir(target_dir, source_dir):
|
||||
try:
|
||||
unique_dir_name = uuid.uuid4()
|
||||
|
||||
# Overwrite existing output directory
|
||||
if os.path.isdir(target_dir):
|
||||
shutil.rmtree(target_dir)
|
||||
|
||||
# Create new output directory
|
||||
os.makedirs(f"{target_dir}/{str(unique_dir_name)}")
|
||||
print(
|
||||
colored(
|
||||
f" Created new Neuron output directory: {source_dir}/{unique_dir_name}",
|
||||
"green",
|
||||
)
|
||||
)
|
||||
return unique_dir_name
|
||||
|
||||
except Exception as e:
|
||||
print(
|
||||
colored(f" Error occurred when creating target directory: {str(e)}", "red")
|
||||
)
|
17
src/lib/transfer_files.py
Normal file
17
src/lib/transfer_files.py
Normal file
|
@ -0,0 +1,17 @@
|
|||
import shutil
|
||||
from termcolor import colored
|
||||
|
||||
|
||||
def transfer_files(target_dir, source_dir):
|
||||
try:
|
||||
# Copy images to /static
|
||||
print(colored(" Copying static files...", "blue"))
|
||||
shutil.copytree(f"{source_dir}/img", f"{target_dir}/static")
|
||||
print(colored(" Static files transferred!", "green"))
|
||||
|
||||
print(colored(" Copying zettels...", "blue"))
|
||||
# Copy notes
|
||||
shutil.copytree(f"{source_dir}/zk", f"{target_dir}", dirs_exist_ok=True)
|
||||
print(colored(" Zettels transferred!", "green"))
|
||||
except Exception as e:
|
||||
print(colored(f"Error occurred when transferring files: {str(e)}", "red"))
|
Loading…
Add table
Reference in a new issue