Skip to content

Commit 7092ea4

Browse files
committed
Switched to PyInstaller, UAC request without tricks, changed logging settings, improved error handling, easy refactoring and new icon
1 parent 005f0c3 commit 7092ea4

20 files changed

Lines changed: 221 additions & 245 deletions

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ cython_debug/
163163
/downloads_for_van/
164164
/dist/
165165
/config.json
166-
/src/data/config.json
166+
/config/config.json
167167
/logging.txt
168168

169169
/pg.lock

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Process Governor
22

3-
![Logo Process Governor](src/resource/favicon.ico)
3+
![Logo Process Governor](resources/app.ico)
44

55
**Process Governor** is a Python utility designed to manage Windows processes and services by adjusting their
66
priorities, I/O priorities, and core affinity based on user-defined rules in a JSON configuration.
@@ -21,17 +21,17 @@ To use Process Governor, follow these steps:
2121
1. Clone this repository.
2222
2. Install the required dependencies using `pip`: `pip install -r requirements.txt`
2323
3. Configure your rules in the `config.json` file. You can create the `config.json` file by running the program once.
24-
4. Run the `process-governor.py` script: `python process-governor.py`
24+
4. Run the `process-governor.py` script with **administrative privileges**: `python process-governor.py`
2525

2626
You can close the program by accessing the tray icon:
2727

2828
![Tray menu screenshot](docs/tray_menu_screenshot.png)
2929

3030
## Creating a Portable Build
3131

32-
You can create a portable version of the program using **pyvan**. Follow these steps to build the portable version:
32+
You can create a portable version of the program using **PyInstaller**. Follow these steps to build the portable version:
3333

34-
1. Install pyvan using `pip install pyvan`.
34+
1. Install PyInstaller using `pip install pyinstaller`.
3535
2. Run the `python build_portable.py` script.
3636
3. After the script completes, you will find the portable build in the `dist` folder.
3737

README.ru.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Process Governor
22

3-
![Logo Process Governor](src/resource/favicon.ico)
3+
![Logo Process Governor](resources/app.ico)
44

55
**Process Governor** - это утилита на Python, предназначенная для управления процессами и службами в Windows путем
66
настройки их приоритетов, приоритетов ввода/вывода и привязки к ядрам на основе пользовательских правил, заданных в
@@ -22,17 +22,17 @@ JSON-конфигурации.
2222
1. Склонируйте этот репозиторий.
2323
2. Установите необходимые зависимости с помощью `pip`: `pip install -r requirements.txt`
2424
3. Настройте правила в файле `config.json`. Вы можете создать файл `config.json`, запустив программу один раз.
25-
4. Запустите скрипт `process-governor.py`: `python process-governor.py`
25+
4. Запустите скрипт `process-governor.py` с правами администратора: `python process-governor.py`
2626

2727
Программу можно закрыть, обратившись к значку в системном трее:
2828

2929
![Tray menu screenshot](docs/tray_menu_screenshot.png)
3030

3131
## Создание портабельной сборки
3232

33-
Вы можете создать портативную версию программы, используя **pyvan**. Чтобы создать портативную версию, выполните следующие шаги:
33+
Вы можете создать портативную версию программы, используя **PyInstaller**. Чтобы создать портативную версию, выполните следующие шаги:
3434

35-
1. Установите pyvan с помощью `pip install pyvan`.
35+
1. Установите PyInstaller с помощью `pip install pyinstaller`.
3636
2. Запустите скрипт `python build_portable.py`.
3737
3. После завершения скрипта, вы найдете портативную версию в папке `dist`.
3838

build_portable.py

Lines changed: 14 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,14 @@
1-
import os
2-
import shutil
3-
from pathlib import Path
4-
5-
import pyvan
6-
from genexe.generate_exe import generate_exe
7-
from pyvan import HEADER_NO_CONSOLE
8-
9-
OPTIONS = {
10-
"main_file_name": "../process-governor.py",
11-
"show_console": False,
12-
"use_existing_requirements": True,
13-
"extra_pip_install_args": [],
14-
"python_version": None,
15-
"use_pipreqs": False,
16-
"install_only_these_modules": [],
17-
"exclude_modules": [],
18-
"include_modules": [],
19-
"path_to_get_pip_and_python_embedded_zip": "downloads_for_van",
20-
"build_dir": "dist",
21-
"pydist_sub_dir": "pydist",
22-
"source_sub_dir": "src",
23-
"icon_file": "src/resource/favicon.ico",
24-
"input_dir": "src"
25-
}
26-
27-
original = pyvan.make_startup_exe
28-
29-
30-
def make_startup_exe(main_file_name, show_console, build_dir, relative_pydist_dir, relative_source_dir, icon_file=None):
31-
""" Make the startup exe file needed to run the script """
32-
print("Making startup exe file")
33-
34-
exe_fname = os.path.join(build_dir, os.path.splitext(os.path.basename(main_file_name))[0] + ".exe")
35-
python_entrypoint = "python.exe"
36-
command_str = f"{{EXE_DIR}}\\{relative_pydist_dir}\\{python_entrypoint} {{EXE_DIR}}\\{relative_source_dir}\\{main_file_name}"
37-
38-
generate_exe(
39-
target=Path(exe_fname),
40-
command=command_str,
41-
icon_file=None if icon_file is None else Path(icon_file),
42-
show_console=show_console
43-
)
44-
45-
main_file_name = os.path.join(build_dir, main_file_name)
46-
47-
if not show_console:
48-
with open(main_file_name, "r", encoding="utf8", errors="surrogateescape") as f:
49-
main_content = f.read()
50-
if HEADER_NO_CONSOLE not in main_content:
51-
with open(main_file_name, "w", encoding="utf8", errors="surrogateescape") as f:
52-
f.write(str(HEADER_NO_CONSOLE + main_content))
53-
54-
shutil.copy(main_file_name, build_dir)
55-
56-
print("Done!")
57-
58-
59-
pyvan.make_startup_exe = make_startup_exe
60-
61-
pyvan.build(**OPTIONS)
1+
import PyInstaller.__main__
2+
3+
PyInstaller.__main__.run([
4+
'process-governor.py',
5+
'--noconfirm',
6+
'--onedir',
7+
'--uac-admin',
8+
'--hide-console', 'hide-early',
9+
'--add-data', './resources/*;./resources',
10+
'--contents-directory', 'scripts',
11+
'--icon', 'resources/app.ico',
12+
'--name', 'Process Governor',
13+
'--debug', 'noarchive',
14+
])

docs/tray_menu_screenshot.png

94 Bytes
Loading

process-governor.py

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,28 @@
1-
import sys, os
2-
if sys.executable.endswith('pythonw.exe'):
3-
sys.stdout = open(os.devnull, 'w')
4-
sys.stderr = open(os.path.join(os.getenv('TEMP'), 'stderr-{}'.format(os.path.basename(sys.argv[0]))), "w")
5-
61
import platform
2+
import sys
3+
74
import pyuac
8-
from util import pyuac_fix
9-
from util.lock_instance import create_lock_file, remove_lock_file
105

116
from main_loop import start_app
7+
from util.lock_instance import create_lock_file, remove_lock_file
8+
from util.messages import message_box, MBIcon
129

1310
if __name__ == "__main__":
1411
if not platform.system() == "Windows":
1512
print("Process Governor is intended to run on Windows only.")
1613
sys.exit(1)
1714

1815
if not pyuac.isUserAdmin():
19-
pyuac_fix.runAsAdmin(wait=False, showCmd=False)
20-
else:
21-
create_lock_file()
22-
try:
23-
start_app()
24-
finally:
25-
remove_lock_file()
16+
message_box(
17+
"Process Governor",
18+
"This program requires administrator privileges to run.\n"
19+
"Please run the program as an administrator to ensure proper functionality.",
20+
MBIcon.INFORMATION
21+
)
22+
sys.exit(1)
23+
24+
create_lock_file()
25+
try:
26+
start_app()
27+
finally:
28+
remove_lock_file()
File renamed without changes.

resources/app.ico

137 KB
Binary file not shown.

0 commit comments

Comments
 (0)