Skip to content

Commit

Permalink
+ Options to customize config and rules files path
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxBQb committed Mar 21, 2023
1 parent 6442e8b commit 78559d3
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 7 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,11 @@ Features:
# 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)
## Theme used: [forest-dark](https://github.com/rdbende/Forest-ttk-theme) with minor changes
## Main lib used: [WinJobster](https://github.com/SemperSolus0x3d/WinJobster) with minor changes

# Multiple configs and rules lists
Path to config can be configured with `-c`/`--config` params on start
```cmd
BulkStartStop.exe --config path/to/config.json
```

Path to rules list file can be set with config.
1 change: 0 additions & 1 deletion WinJobster/WinJobsterLoader.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ def load(self) -> c.WinDLL:
dll_path = pathlib.Path(__file__).parent
architecture = 64 if platform.architecture()[0] == '64bit' else 86
dll_path = str(dll_path.joinpath(f'WinJobster-x{architecture}.dll').absolute())
print(dll_path)
lib = c.WinDLL(dll_path)
lib.StartProcess.restype = c.c_uint32
lib.StartProcess.errcheck = WinJobsterLoader._errcheck
Expand Down
30 changes: 24 additions & 6 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
import os.path
import re
import shlex
import sys
import tkinter as tk
import tkinter.filedialog
import tkinter.ttk as ttk
import winreg
import argparse
from WinJobster import Process
import jsons

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

def load(self):
try:
mkdir(self.filename)
with open(self.filename, 'r', encoding='utf-8-sig') as file:
self._paths = {path.strip() for path in file.readlines() if path}
except OSError:
Expand All @@ -46,6 +49,13 @@ def paths(self, value: set[str]):
class Config:
run_all_at_startup: bool = False
kill_all_on_close: bool = False
rules_path: str = 'apps_to_manage.txt'


def mkdir(path):
dirname = os.path.dirname(path)
if dirname and not (os.path.exists(dirname) and os.path.isdir(dirname)):
os.mkdir(dirname)


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

def load(self):
try:
mkdir(self.filename)
with open(self.filename, 'r', encoding='utf-8-sig') as file:
self.config = jsons.loads(file.read(), Config)
except OSError:
Expand Down Expand Up @@ -125,10 +136,10 @@ def toggle(self):


class Model:
def __init__(self):
self._paths_storage = PathsStorage()
self._config_storage = ConfigStorage()
def __init__(self, args):
self._config_storage = ConfigStorage(args.config)
self._config_storage.load()
self._paths_storage = PathsStorage(self.settings.rules_path)
self.paths: list = list(self._paths_storage.paths)
self._processes = {path: ProcessModel(path) for path in self.paths}

Expand Down Expand Up @@ -338,12 +349,12 @@ def set_kill_on_close(self, value: bool):


class App(tk.Tk):
def __init__(self):
def __init__(self, args):
super().__init__()
self.title('Apps bulk start/stop')
self.geometry('640x480')
self.apply_theme()
model = Model()
model = Model(args)
view = View(self)
view.pack(fill=tk.X, padx=8, pady=8)
controller = Controller(model, view)
Expand All @@ -358,8 +369,15 @@ def apply_theme(self):
style.theme_use('forest-dark')


def get_args():
parser = argparse.ArgumentParser(add_help=False)
parser.add_argument('--config', '-c', default='config.json')
return parser.parse_args(sys.argv[1:])


def main():
App().mainloop()
args = get_args()
App(args).mainloop()


if __name__ == '__main__':
Expand Down

0 comments on commit 78559d3

Please sign in to comment.