-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtemplate.py
48 lines (37 loc) · 1.42 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
47
48
import os
from pathlib import Path
import logging #inbuild module inside python
#logging string usually follow
logging.basicConfig(level=logging.INFO, format='[%(asctime)s]: %(message)s:')
#(forword path/) for mac and linux and (\)backward pass for window
list_of_files=[
"src/__init__.py",
"src/helper.py",
"src/prompt/py",
"setup.py",
"research/trials.ipynb",
"app.py",
"store_index.py",
"static/.gitkeep",#for flask
"templates/chat.html",
]
#how to create all this files -->shown below
#writing the code for that
for filepath in list_of_files:
filepath=Path(filepath) #convert filepath into path
# separate folder and file
filedir,filename=os.path.split(filepath)
#if file directory is not empty then create file directory
if filedir !="":
os.makedirs(filedir,exist_ok=True) #exits_ok if we give then if dir is exist then if will not replace it or create it
#log the information
logging.info(f"Creating directory ;{filedir} for the file {filename}")
#now create the file inside folder
#if not created then create it and also check the size
if (not os.path.exists(filepath)) or (os.path.getsize(filepath)==0):
with open(filepath,'w') as f:
pass
logging.info(f"Creating empty file:{filepath}")
#if created then it will show this
else:
logging.info(f"{filename} is already created")