3
3
import os .path
4
4
import re
5
5
import shlex
6
+ import sys
6
7
import tkinter as tk
7
8
import tkinter .filedialog
8
9
import tkinter .ttk as ttk
9
10
import winreg
11
+ import argparse
10
12
from WinJobster import Process
11
13
import jsons
12
14
@@ -20,6 +22,7 @@ def __init__(self, filename: str = 'apps_to_manage.txt'):
20
22
21
23
def load (self ):
22
24
try :
25
+ mkdir (self .filename )
23
26
with open (self .filename , 'r' , encoding = 'utf-8-sig' ) as file :
24
27
self ._paths = {path .strip () for path in file .readlines () if path }
25
28
except OSError :
@@ -46,6 +49,13 @@ def paths(self, value: set[str]):
46
49
class Config :
47
50
run_all_at_startup : bool = False
48
51
kill_all_on_close : bool = False
52
+ rules_path : str = 'apps_to_manage.txt'
53
+
54
+
55
+ def mkdir (path ):
56
+ dirname = os .path .dirname (path )
57
+ if dirname and not (os .path .exists (dirname ) and os .path .isdir (dirname )):
58
+ os .mkdir (dirname )
49
59
50
60
51
61
class ConfigStorage :
@@ -55,6 +65,7 @@ def __init__(self, filename: str = 'config.json'):
55
65
56
66
def load (self ):
57
67
try :
68
+ mkdir (self .filename )
58
69
with open (self .filename , 'r' , encoding = 'utf-8-sig' ) as file :
59
70
self .config = jsons .loads (file .read (), Config )
60
71
except OSError :
@@ -125,10 +136,10 @@ def toggle(self):
125
136
126
137
127
138
class Model :
128
- def __init__ (self ):
129
- self ._paths_storage = PathsStorage ()
130
- self ._config_storage = ConfigStorage ()
139
+ def __init__ (self , args ):
140
+ self ._config_storage = ConfigStorage (args .config )
131
141
self ._config_storage .load ()
142
+ self ._paths_storage = PathsStorage (self .settings .rules_path )
132
143
self .paths : list = list (self ._paths_storage .paths )
133
144
self ._processes = {path : ProcessModel (path ) for path in self .paths }
134
145
@@ -338,12 +349,12 @@ def set_kill_on_close(self, value: bool):
338
349
339
350
340
351
class App (tk .Tk ):
341
- def __init__ (self ):
352
+ def __init__ (self , args ):
342
353
super ().__init__ ()
343
354
self .title ('Apps bulk start/stop' )
344
355
self .geometry ('640x480' )
345
356
self .apply_theme ()
346
- model = Model ()
357
+ model = Model (args )
347
358
view = View (self )
348
359
view .pack (fill = tk .X , padx = 8 , pady = 8 )
349
360
controller = Controller (model , view )
@@ -358,8 +369,15 @@ def apply_theme(self):
358
369
style .theme_use ('forest-dark' )
359
370
360
371
372
+ def get_args ():
373
+ parser = argparse .ArgumentParser (add_help = False )
374
+ parser .add_argument ('--config' , '-c' , default = 'config.json' )
375
+ return parser .parse_args (sys .argv [1 :])
376
+
377
+
361
378
def main ():
362
- App ().mainloop ()
379
+ args = get_args ()
380
+ App (args ).mainloop ()
363
381
364
382
365
383
if __name__ == '__main__' :
0 commit comments