@@ -30,19 +30,20 @@ def __init__(self,
30
30
info : int = Categories .ENABLED ,
31
31
warning : int = Categories .MAXIMUM ) -> None :
32
32
self .bar : ProgressBar = ProgressBar ()
33
- self .__is_empty : bool = True
34
- self .__log : list [LogEntry ] = []
35
- self .__notifier : Notification = notification
36
- self .__program_name : str = program_name
37
- self .__scopes : dict [str , int ] = {
33
+ self .is_empty : bool = True
34
+ self .program_name : str = program_name
35
+ self ._log : list [LogEntry ] = []
36
+ self ._scopes : dict [str , int ] = {
38
37
"DEBUG" : debug , # information for debugging the program
39
38
"ERROR" : error , # errors the program can recover from
40
39
"FATAL" : fatal , # errors that mean the program cannot continue
41
40
"INFO" : info , # general information for the user
42
41
"WARNING" : warning # things that could cause errors later on
43
42
}
43
+ self .__notifier : Notification = notification
44
44
self .__write_logs = False
45
- self .__output_path : str = (
45
+
46
+ self ._output_path : str = (
46
47
self .__define_output_path ()
47
48
if config_path is None else
48
49
f"{ config_path } /logs"
@@ -59,17 +60,17 @@ def __create_log_entry(self, message: str, output: bool, scope: str) -> LogEntry
59
60
60
61
:returns: the created log entry
61
62
"""
62
- entry : LogEntry = LogEntry (message , output , scope , self .__get_time ())
63
- self .__log .append (entry )
63
+ entry : LogEntry = LogEntry (message , output , scope , self ._get_time ())
64
+ self ._log .append (entry )
64
65
return entry
65
66
66
67
def __create_log_folder (self ) -> None :
67
68
"""
68
69
Creates the folder that will contain the log files.
69
70
"""
70
- if not isdir (self .__output_path ):
71
- print (f"Making path: { self .__output_path } " )
72
- makedirs (self .__output_path , exist_ok = True )
71
+ if not isdir (self ._output_path ):
72
+ print (f"Making path: { self ._output_path } " )
73
+ makedirs (self ._output_path , exist_ok = True )
73
74
74
75
def __define_output_path (self ) -> str :
75
76
"""
@@ -91,12 +92,12 @@ def __define_output_path(self) -> str:
91
92
os : str = "" .join (list (platform )[:3 ])
92
93
if os in ["dar" , "lin" , "win" ]:
93
94
path : str = (
94
- environ ["APPDATA" ] + f"\\ { self .__program_name } \logs"
95
+ environ ["APPDATA" ] + f"\\ { self .program_name } \logs"
95
96
if os == "win" else
96
- f"{ expanduser ('~' )} /.config/{ self .__program_name } /logs"
97
+ f"{ expanduser ('~' )} /.config/{ self .program_name } /logs"
97
98
)
98
99
if not isdir (path ):
99
- print (f"INFO: Making path: { path } " )
100
+ print (f"Making path: { path } " )
100
101
makedirs (path , exist_ok = True )
101
102
return path
102
103
else :
@@ -121,14 +122,14 @@ def __display_log_entry(self,
121
122
:param is_bar: whether the progress bar is active
122
123
:param console: whether the message should be printed to the console
123
124
"""
124
- if scope == "NOSCOPE" or (self .__scopes [scope ] != Categories .DISABLED and print_to_console ):
125
+ if scope == "NOSCOPE" or (self ._scopes [scope ] != Categories .DISABLED and print_to_console ):
125
126
print (entry .rendered )
126
127
if is_bar :
127
128
print (self .bar .state , end = "\r " , flush = True )
128
129
if notify :
129
130
self .notify (entry .message )
130
131
131
- def __get_time (self , method : str = "time" ) -> str :
132
+ def _get_time (self , method : str = "time" ) -> str :
132
133
"""
133
134
Gets the current time and parses it to a human-readable format; either
134
135
'YYYY-MM-DD HH:MM:SS' or 'YYYY-MM-DD'.
@@ -159,15 +160,15 @@ def add_scope(self, name: str, category: int) -> bool:
159
160
160
161
:return: a boolean sucess status
161
162
"""
162
- if name in self .__scopes .keys ():
163
+ if name in self ._scopes .keys ():
163
164
self .new (
164
165
f"Attempt was made to add new scope with name { name } , but scope with this name "
165
166
+ "already exists." ,
166
167
"WARNING"
167
168
)
168
169
else :
169
170
if category in set (item for item in Categories ):
170
- self .__scopes [name ] = category
171
+ self ._scopes [name ] = category
171
172
return True
172
173
else :
173
174
self .new (
@@ -181,8 +182,8 @@ def clean(self) -> None:
181
182
"""
182
183
Empties log array. Any log entries not saved to the output file will be lost.
183
184
"""
184
- del self .__log [:]
185
- self .__is_empty = True
185
+ del self ._log [:]
186
+ self .is_empty = True
186
187
self .__write_logs = False
187
188
188
189
def edit_scope (self , name : str , category : int ) -> bool :
@@ -195,9 +196,9 @@ def edit_scope(self, name: str, category: int) -> bool:
195
196
196
197
:returns: a boolean success status
197
198
"""
198
- if name in self .__scopes .keys ():
199
+ if name in self ._scopes .keys ():
199
200
if category in set (item for item in Categories ):
200
- self .__scopes [name ] = category
201
+ self ._scopes [name ] = category
201
202
return True
202
203
else :
203
204
self .new (
@@ -225,22 +226,22 @@ def get(self, mode: str = "all", scope: str = None) -> Union[list[LogEntry], Log
225
226
226
227
:returns: a single log entry or list of log entries, or nothing
227
228
"""
228
- if self .__is_empty :
229
+ if self .is_empty :
229
230
pass
230
231
elif scope is None :
231
- return (self .__log , self .__log [- 1 ])[mode == "recent" ]
232
+ return (self ._log , self ._log [- 1 ])[mode == "recent" ]
232
233
else :
233
234
# return all log entries matching the query
234
235
if mode == "all" :
235
236
data : list [LogEntry ] = []
236
- for entry in self .__log :
237
+ for entry in self ._log :
237
238
if scope is None or entry .scope == scope :
238
239
data .append (entry )
239
240
if data :
240
241
return data
241
242
# iterate through the log in reverse to find the most recent entry matching the query
242
243
elif mode == "recent" :
243
- for entry in reversed (self .__log ):
244
+ for entry in reversed (self ._log ):
244
245
if scope is None or entry .scope == scope :
245
246
return entry
246
247
else :
@@ -274,9 +275,9 @@ def new(self,
274
275
275
276
:returns: a boolean success status
276
277
"""
277
- if scope in self .__scopes or scope == "NOSCOPE" :
278
+ if scope in self ._scopes or scope == "NOSCOPE" :
278
279
output : bool = (
279
- (self .__scopes [scope ] == Categories .MAXIMUM )
280
+ (self ._scopes [scope ] == Categories .MAXIMUM )
280
281
if scope != "NOSCOPE" else
281
282
False
282
283
)
@@ -291,7 +292,7 @@ def new(self,
291
292
self .__display_log_entry (entry , scope , notify , is_bar , print_to_console )
292
293
293
294
self .__write_logs = self .__write_logs or output
294
- self .__is_empty = False
295
+ self .is_empty = False
295
296
296
297
return True
297
298
else :
@@ -304,7 +305,7 @@ def notify(self, message: str) -> None:
304
305
305
306
:param message: the message to display
306
307
"""
307
- self .__notifier .notify (title = self .__program_name , message = message )
308
+ self ._notifier .notify (title = self .program_name , message = message )
308
309
309
310
def output (self ) -> None :
310
311
"""
@@ -314,9 +315,9 @@ def output(self) -> None:
314
315
Log files are marked with the date, so each new day, a new file will be created.
315
316
"""
316
317
if self .__write_logs :
317
- with open (f"{ self .__output_path } /log-{ self .__get_time (method = 'date' )} .txt" ,
318
+ with open (f"{ self ._output_path } /log-{ self ._get_time (method = 'date' )} .txt" ,
318
319
"at+" ) as log_file :
319
- for line in self .__log :
320
+ for line in self ._log :
320
321
if line .output :
321
322
log_file .write (line .rendered + "\n " )
322
323
self .clean ()
@@ -329,8 +330,8 @@ def remove_scope(self, name: str) -> bool:
329
330
330
331
:returns: a boolean success status
331
332
"""
332
- if name in self .__scopes .keys ():
333
- del self .__scopes [name ]
333
+ if name in self ._scopes .keys ():
334
+ del self ._scopes [name ]
334
335
return True
335
336
else :
336
337
self .new (
0 commit comments