-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathlogops.py
47 lines (39 loc) · 1.55 KB
/
logops.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
""" Fileorganizer log operations
----------------Authors----------------
Lachlan de Waard <[email protected]>
----------------Licence----------------
Creative Commons - Attribution Share Alike v3.0
"""
import os
import codecs
import configparser
class LogFile(object):
""" Log file actions. Open, create and edit log files """
def __init__(self):
self.conf = configparser.RawConfigParser()
conffile = (os.getenv('HOME') + '/.local/share/rhythmbox/' +
'plugins/fileorganizer/fo.conf')
self.conf.read(conffile)
# Write to log file
def log_processing(self, logmessage):
""" Perform log operations """
log_enabled = self.conf.get('conf', 'log_enabled')
log_filename = self.conf.get('conf', 'log_path')
log_filename = os.getenv('HOME') + '/' + log_filename
# Log if Enabled
if log_enabled == 'True':
# Create if missing
if (not os.path.exists(log_filename) or
os.path.getsize(log_filename) >= 1076072):
files = codecs.open(log_filename, "w", "utf8")
files.close()
files = codecs.open(log_filename, "a", "utf8")
try:
logline = [logmessage]
files.write((u"".join(logline)) + u"\n")
except UnicodeDecodeError:
print('LOG UNICODE ERROR')
logline = [logmessage.decode('utf-8')]
files.write((u"".join(logline)) + u"\n")
files.close()