-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtemplate.py
46 lines (39 loc) · 1.22 KB
/
template.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import os
from pathlib import Path
import logging
# Set up logging
logging.basicConfig(level=logging.INFO, format='[%(asctime)s]: %(message)s')
# List of files and directories relative to the current root
list_of_files = [
"docs/.gitkeep",
"flowcharts/.gitkeep",
"notebooks/.gitkeep",
"src/leaflogic/__init__.py",
"src/leaflogic/logger/__init__.py",
"src/leaflogic/exception/__init__.py",
"src/leaflogic/utils/__init__.py",
".gitignore",
"demo.py",
"LICENSE",
"README.md",
"requirements.txt",
"scripts.sh",
"setup.py",
"template.py"
]
# File and directory creation logic
for filepath in list_of_files:
filepath = Path(filepath)
# Split file directory and filename
filedir, filename = os.path.split(filepath)
# Create directories if needed
if filedir != "":
os.makedirs(filedir, exist_ok=True)
logging.info(f"Creating directory: {filedir} for the file {filename}")
# Create file if it doesn't exist or is empty
if not filepath.exists() or filepath.stat().st_size == 0:
with open(filepath, 'w') as f:
pass
logging.info(f"Creating empty file: {filepath}")
else:
logging.info(f"{filepath} already exists")