|
1 | 1 | import os
|
| 2 | +import site |
2 | 3 |
|
3 | 4 | loc = os.getcwd()
|
4 | 5 | new_loc = loc.replace("\\", "/")
|
| 6 | +venv_templates_path = f"{new_loc}/.venv/Lib/site-packages/Templates" |
| 7 | +# Get the global site-packages directory |
| 8 | +site_packages_path = site.getsitepackages()[0] |
| 9 | +global_templates_path = f"{site_packages_path}/Templates" |
5 | 10 |
|
6 | 11 |
|
7 | 12 | def get_configs(filename):
|
8 |
| - with open(f"{new_loc}/Dev/Templates/Web/configs/HTML/{filename}", "r", encoding="utf-8") as file: |
| 13 | + if os.path.exists(venv_templates_path): |
| 14 | + template_folder = venv_templates_path |
| 15 | + elif os.path.exists(global_templates_path): |
| 16 | + template_folder = global_templates_path |
| 17 | + else: |
| 18 | + return "Error: Templates folder not found" |
| 19 | + |
| 20 | + with open(f"{template_folder}/Web/configs/HTML/{filename}", "r", encoding="utf-8") as file: |
9 | 21 | html_content = file.read()
|
10 | 22 | return html_content
|
11 | 23 |
|
12 | 24 |
|
13 | 25 | def fetch_configs():
|
14 |
| - return os.listdir(f"{new_loc}/Dev/Templates/configs/HTML/") |
| 26 | + if os.path.exists(venv_templates_path): |
| 27 | + template_folder = venv_templates_path |
| 28 | + elif os.path.exists(global_templates_path): |
| 29 | + template_folder = global_templates_path |
| 30 | + else: |
| 31 | + return "Error: Templates folder not found" |
| 32 | + |
| 33 | + return os.listdir(f"{template_folder}/configs/HTML/") |
15 | 34 |
|
16 | 35 |
|
17 | 36 | def setup_configs():
|
18 | 37 | flask_app = """
|
19 | 38 | from flask import Flask, render_template
|
20 |
| -import Dev.Templates.setup_templates as ds |
| 39 | +import Templates.setup_templates as ds |
21 | 40 | import os
|
22 | 41 |
|
23 | 42 | app = Flask(__name__)
|
|
0 commit comments