-
Notifications
You must be signed in to change notification settings - Fork 0
/
logger.py
47 lines (43 loc) · 1.62 KB
/
logger.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
#!/usr/bin/env python3
import os
import time
import getpass
import csv
from pymediainfo import MediaInfo
# Code from IFIScripts github repository
def make_desktop_logs_dir():
desktop_logs_dir = os.path.expanduser("~/Desktop/ucclib_logs")
os.makedirs(desktop_logs_dir, exist_ok= True)
return desktop_logs_dir
def generate_log(log, what2log):
if not os.path.isfile(log):
with open(log, "w", encoding='utf-8') as fo:
fo.write(time.strftime("%Y-%m-%dT%H:%M:%S ")
+ getpass.getuser()
+ ' ' + what2log + ' \n')
else:
with open(log, "a", encoding='utf-8') as fo:
fo.write(time.strftime("%Y-%m-%dT%H:%M:%S ")
+ getpass.getuser()
+ ' ' + what2log + ' \n')
def remove_bad_files(root_dir, log_name_source):
'''
Removes unwanted files.
Verify if this is different than the same function in ififuncs.
'''
rm_these = ['.DS_Store', 'Thumbs.db', 'desktop.ini']
for root, _, files in os.walk(root_dir):
for name in files:
path = os.path.join(root, name)
for i in rm_these:
if name == i:
print(('***********************' + 'removing: ' + path))
generate_log(
log_name_source,
'EVENT = Unwanted file removal - %s was removed' % path
)
try:
os.remove(path)
except OSError:
print('can\'t delete as source is read-only')
print("Bad files removed - exiting process")