forked from lachlan-00/rb-fileorganizer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlogops.py
More file actions
49 lines (41 loc) · 1.61 KB
/
logops.py
File metadata and controls
49 lines (41 loc) · 1.61 KB
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
49
#!/usr/bin/env python3
""" Fileorganizer log operations
----------------Authors----------------
Lachlan de Waard <lachlan.00@gmail.com>
----------------Licence----------------
Creative Commons - Attribution Share Alike v3.0
"""
import os
import codecs
import configparser
class LogFile():
""" 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 = []
logline.append(logmessage)
files.write((u"".join(logline)) + u"\n")
except UnicodeDecodeError:
print('LOG UNICODE ERROR')
logline = []
logline.append(logmessage.decode('utf-8'))
files.write((u"".join(logline)) + u"\n")
files.close()