Skip to content

Commit 8643ae8

Browse files
committed
Added checks and updated the initial_set_up function by coping the default standard footer to the data folder created.
1 parent 9e39233 commit 8643ae8

File tree

1 file changed

+79
-35
lines changed

1 file changed

+79
-35
lines changed

Easy_versioning/main.py

Lines changed: 79 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -526,45 +526,89 @@ def initial_set_up():
526526
"""
527527
Simple easy-versioning project set-up.
528528
"""
529-
args = sys.argv[1:] # Takes the parameters from the command line
530-
title = args[0] if len(args) > 0 else "Documentation"
531-
author = args[1] if len(args) > 1 else "Author"
532-
533-
src_path = os.path.join(BASE_DIR, "src") # "src" folder path
534-
data_path = os.path.join(BASE_DIR, "data") # "data" folder path
535-
version_paths = [
536-
[os.path.join(BASE_DIR, "src", "V. 1.0"), "1.0"],
537-
[os.path.join(BASE_DIR, "src", "V. 2.0"), "2.0"]
538-
] # Versions of the documentation folder
539-
540-
if not os.path.exists(src_path): # If no "src" folder is found
541-
for version in version_paths:
542-
os.makedirs(version[0], exist_ok=True) # Creating the src/version folder
543-
command = [
544-
"sphinx-quickstart",
545-
"--quiet",
546-
"-p", title,
547-
"-a", author,
548-
"-v", version[1],
549-
"--sep"
550-
]
551529

552-
try:
553-
# Running the build command inside of the specific folder
554-
result = subprocess.run(
555-
command, capture_output = True, text = True, cwd = version[0]
556-
)
530+
try:
531+
info("Setting up the project structure")
532+
533+
args = sys.argv[1:] # Takes the parameters from the command line
534+
title = args[0] if len(args) > 0 else "Documentation"
535+
author = args[1] if len(args) > 1 else "Author"
557536

558-
if result.returncode == 0:
559-
success(f"Sphinx set-up completed for {version[1]}.")
560-
else:
561-
error(f"Sphinx set-up failed for {version[1]}.")
562-
error(f"{result.stderr}.")
537+
src_path = os.path.join(BASE_DIR, "src") # "src" folder path
538+
539+
version_paths = [
540+
[os.path.join(BASE_DIR, "src", "V. 1.0"), "1.0"],
541+
[os.path.join(BASE_DIR, "src", "V. 2.0"), "2.0"]
542+
] # Versions of the documentation folder
543+
544+
info("Creating the versions and the sphinx projects")
545+
546+
# Check if sphinx is available
547+
subprocess.run(["sphinx-quickstart", "--version"], capture_output=True, text=True, check=True)
548+
549+
550+
# Create version directories and initialize sphinx projects
551+
if not os.path.exists(src_path): # If no "src" folder is found
552+
for version in version_paths:
553+
version_dir = version[0]
554+
if os.path.exists(version_dir) and not os.path.isdir(version_dir):
555+
error(f"Path exists but is not a directory: {version_dir}")
556+
return
557+
558+
os.makedirs(version[0], exist_ok=True) # Creating the src/version folder
559+
command = [
560+
"sphinx-quickstart",
561+
"--quiet",
562+
"-p", title,
563+
"-a", author,
564+
"-v", version[1],
565+
"--sep"
566+
]
567+
568+
try:
569+
result = subprocess.run(command, capture_output=True, text=True, cwd=version[0])
570+
if result.returncode == 0:
571+
success(f"Sphinx set-up completed for {version[1]}.")
572+
else:
573+
error(f"Sphinx set-up failed for {version[1]}.")
574+
error(f"{result.stderr}.")
575+
except Exception as e:
576+
error(f"Exception during the set-up {e}.")
577+
return
578+
579+
# Handle data folder
580+
info("Handling the data function")
581+
data_path = os.path.join(BASE_DIR, "data")
582+
583+
# Check if permissions allow to modify the data directory
584+
if not os.access(BASE_DIR, os.W_OK):
585+
error(f"Permission denied: Cannot write to {BASE_DIR}")
586+
return
587+
588+
if os.path.exists(data_path):
589+
try:
590+
shutil.rmtree(data_path, onexc=handle_remove_readonly)
563591
except Exception as e:
564-
error(f"Exception during the set-up {e}.")
592+
error(f"Failed to remove directory {data_path}: {e}")
593+
return
594+
595+
os.makedirs(data_path, exist_ok=True)
596+
597+
footer_path = os.path.join(FOOTER_PATH, "footer.html")
598+
if not os.path.exists(footer_path):
599+
error(f"Footer file does not exist: {footer_path}")
600+
return
601+
try:
602+
shutil.copy(footer_path, data_path)
603+
success(f"Copied footer from {footer_path} to {data_path}")
604+
except Exception as e:
605+
error(f"Failed to copy footer: {e}")
606+
return
607+
608+
success("Initial set-up ended!")
609+
except Exception as e:
610+
error(f"An unexpected error occurred: {e}")
565611

566-
if not os.path.exists(data_path):
567-
os.makedirs(data_path, exist_ok = True)
568612

569613
################################################################################## Main
570614

0 commit comments

Comments
 (0)