Skip to content

Commit 78559d3

Browse files
committed
+ Options to customize config and rules files path
1 parent 6442e8b commit 78559d3

File tree

3 files changed

+32
-7
lines changed

3 files changed

+32
-7
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,11 @@ Features:
1818
# Download: [![Latest](https://img.shields.io/github/v/tag/MBQbUtils/BulkStartStop?sort=date&label=&style=for-the-badge&color=424242)](https://github.com/MBQbUtils/BulkStartStop/releases/latest/download/BulkStartStop_portable.zip)
1919
## Theme used: [forest-dark](https://github.com/rdbende/Forest-ttk-theme) with minor changes
2020
## Main lib used: [WinJobster](https://github.com/SemperSolus0x3d/WinJobster) with minor changes
21+
22+
# Multiple configs and rules lists
23+
Path to config can be configured with `-c`/`--config` params on start
24+
```cmd
25+
BulkStartStop.exe --config path/to/config.json
26+
```
27+
28+
Path to rules list file can be set with config.

WinJobster/WinJobsterLoader.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ def load(self) -> c.WinDLL:
99
dll_path = pathlib.Path(__file__).parent
1010
architecture = 64 if platform.architecture()[0] == '64bit' else 86
1111
dll_path = str(dll_path.joinpath(f'WinJobster-x{architecture}.dll').absolute())
12-
print(dll_path)
1312
lib = c.WinDLL(dll_path)
1413
lib.StartProcess.restype = c.c_uint32
1514
lib.StartProcess.errcheck = WinJobsterLoader._errcheck

main.py

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@
33
import os.path
44
import re
55
import shlex
6+
import sys
67
import tkinter as tk
78
import tkinter.filedialog
89
import tkinter.ttk as ttk
910
import winreg
11+
import argparse
1012
from WinJobster import Process
1113
import jsons
1214

@@ -20,6 +22,7 @@ def __init__(self, filename: str = 'apps_to_manage.txt'):
2022

2123
def load(self):
2224
try:
25+
mkdir(self.filename)
2326
with open(self.filename, 'r', encoding='utf-8-sig') as file:
2427
self._paths = {path.strip() for path in file.readlines() if path}
2528
except OSError:
@@ -46,6 +49,13 @@ def paths(self, value: set[str]):
4649
class Config:
4750
run_all_at_startup: bool = False
4851
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)
4959

5060

5161
class ConfigStorage:
@@ -55,6 +65,7 @@ def __init__(self, filename: str = 'config.json'):
5565

5666
def load(self):
5767
try:
68+
mkdir(self.filename)
5869
with open(self.filename, 'r', encoding='utf-8-sig') as file:
5970
self.config = jsons.loads(file.read(), Config)
6071
except OSError:
@@ -125,10 +136,10 @@ def toggle(self):
125136

126137

127138
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)
131141
self._config_storage.load()
142+
self._paths_storage = PathsStorage(self.settings.rules_path)
132143
self.paths: list = list(self._paths_storage.paths)
133144
self._processes = {path: ProcessModel(path) for path in self.paths}
134145

@@ -338,12 +349,12 @@ def set_kill_on_close(self, value: bool):
338349

339350

340351
class App(tk.Tk):
341-
def __init__(self):
352+
def __init__(self, args):
342353
super().__init__()
343354
self.title('Apps bulk start/stop')
344355
self.geometry('640x480')
345356
self.apply_theme()
346-
model = Model()
357+
model = Model(args)
347358
view = View(self)
348359
view.pack(fill=tk.X, padx=8, pady=8)
349360
controller = Controller(model, view)
@@ -358,8 +369,15 @@ def apply_theme(self):
358369
style.theme_use('forest-dark')
359370

360371

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+
361378
def main():
362-
App().mainloop()
379+
args = get_args()
380+
App(args).mainloop()
363381

364382

365383
if __name__ == '__main__':

0 commit comments

Comments
 (0)