-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdir_tree.py
More file actions
36 lines (29 loc) · 971 Bytes
/
dir_tree.py
File metadata and controls
36 lines (29 loc) · 971 Bytes
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
import os
import logging
import subprocess
DIR_PARSE_LOG = "dir.log"
FILENAME = "directory_tree.conf"
def read_file(filename):
with open(filename, "r") as f:
for line in f:
cmd = line.rstrip("\n")
if os.path.splitext(cmd)[1] == ".sh":
try:
result = subprocess.run(cmd, capture_output=True, text=True)
logging.info(result.stdout)
except FileNotFoundError as e:
logging.error(f"kindy create file: {cmd}")
except PermissionError as e:
logging.error(f"kindy adjust chmod: {cmd}")
else:
logging.info(cmd)
def main():
os.remove(DIR_PARSE_LOG)
logging.basicConfig(
level=logging.INFO,
handlers=[logging.StreamHandler(), logging.FileHandler(DIR_PARSE_LOG)],
format="%(message)s",
)
read_file(FILENAME)
if __name__ == "__main__":
main()