Skip to content

Commit aa30778

Browse files
committed
Refactor for Task Scheduler autostart and update checks
- Implement Task Scheduler for autostart management. - Conduct general code refactoring. - Add update checking functionality.
1 parent 4cb39ea commit aa30778

37 files changed

Lines changed: 634 additions & 377 deletions

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,9 @@ cython_debug/
163163
/downloads_for_van/
164164
/dist/
165165
/config.json
166-
/config/config.json
166+
/config_build/config.json
167167
/logging.txt
168168

169169
/pg.lock
170170
/sandbox.py
171+
/versionfile.txt

build_portable.py

Lines changed: 55 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,58 @@
1+
import glob
2+
import os
3+
import shutil
4+
15
import PyInstaller.__main__
6+
import pyinstaller_versionfile
7+
8+
from constants.any import CONFIG_FILE_NAME
9+
from constants.app_info import APP_NAME, APP_VERSION, APP_AUTHOR, APP_NAME_WITH_VERSION
10+
11+
# Setting paths and configuration parameters
12+
VERSION_FILE = "versionfile.txt"
13+
DIST = os.path.join(os.getcwd(), 'dist')
14+
APP_DIST = os.path.join(DIST, APP_NAME)
15+
APP_DIST_WITH_VERSION = os.path.join(DIST, APP_NAME_WITH_VERSION)
16+
CONFIG_FILE_FOR_TESTS = os.path.join(os.getcwd(), CONFIG_FILE_NAME)
17+
CONFIG_FILE_IN_APP_DIST = os.path.join(APP_DIST, CONFIG_FILE_NAME)
18+
SPEC_FILES = r".\*.spec"
19+
20+
# Deleting existing .spec files to clean up the directory
21+
for filename in glob.glob(SPEC_FILES):
22+
os.remove(filename)
223

24+
# Creating a version file for the executable
25+
pyinstaller_versionfile.create_versionfile(
26+
output_file=VERSION_FILE,
27+
version=APP_VERSION,
28+
company_name=APP_AUTHOR,
29+
file_description=APP_NAME,
30+
internal_name=APP_NAME,
31+
legal_copyright=f"© {APP_AUTHOR}",
32+
original_filename=f"{APP_NAME}.exe",
33+
product_name=APP_NAME
34+
)
35+
36+
# Running PyInstaller to build the application
337
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-
])
38+
'process-governor.py', # Source script file
39+
'--clean', # Clean previous builds
40+
'--noconfirm', # No confirmation when deleting dist directory
41+
'--onedir', # Build the app in one directory
42+
'--uac-admin', # Request admin rights on launch
43+
'--hide-console', 'hide-early', # Hide the console on startup
44+
'--add-data', './resources/*;./resources', # Add additional resources
45+
'--contents-directory', 'scripts', # Directory for Python and app scripts in the built package
46+
'--icon', 'resources/app.ico', # Application icon
47+
'--debug', 'noarchive', # Disables bundling of application scripts inside the exe
48+
'--name', APP_NAME, # Name of the executable file
49+
'--version-file', VERSION_FILE, # Path to the version file
50+
'--distpath', DIST, # Directory to save the built application
51+
])
52+
53+
# Creating an archive of the built application
54+
shutil.make_archive(APP_DIST_WITH_VERSION, 'zip', APP_DIST)
55+
56+
# Copying the configuration file for tests into the built application
57+
if os.path.isfile(CONFIG_FILE_FOR_TESTS):
58+
shutil.copyfile(CONFIG_FILE_FOR_TESTS, CONFIG_FILE_IN_APP_DIST)
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from psutil._pswindows import Priority, IOPriority
1+
from psutil._pswindows import Priority
22

33
from configuration.rule import Rule
44
from service.config_service import ConfigService
@@ -51,4 +51,3 @@
5151
]
5252

5353
ConfigService.save_config(config)
54-

process-governor.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,19 @@
33

44
import pyuac
55

6+
from constants.app_info import APP_NAME, APP_NAME_WITH_VERSION
67
from main_loop import start_app
78
from util.lock_instance import create_lock_file, remove_lock_file
8-
from util.messages import show_info, show_error
9+
from util.messages import show_error
910

1011
if __name__ == "__main__":
1112
if not platform.system() == "Windows":
12-
print("Process Governor is intended to run on Windows only.")
13+
print(f"{APP_NAME} is intended to run on Windows only.")
1314
sys.exit(1)
1415

1516
if not pyuac.isUserAdmin():
1617
show_error(
17-
"Process Governor",
18+
APP_NAME_WITH_VERSION,
1819
"This program requires administrator privileges to run.\n"
1920
"Please run the program as an administrator to ensure proper functionality."
2021
)

requirements.txt

64 Bytes
Binary file not shown.

resources/startup.bat

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
@echo off
2-
REM Workaround for start with UAC
3-
start "" "%~1"
2+
set "exe_path=%~1"
3+
set "working_directory=%~dp1"
4+
cd /d "%working_directory%"
5+
start /B "" "%exe_path%"
46
exit

src/configuration/config.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
class Config(BaseModel):
1010
"""
11-
The Config class represents a configuration object for Process Governor.
11+
The Config class represents a configuration object for application.
1212
1313
It defines the structure of the configuration, including rule application interval, logging settings, and rules.
1414
"""
@@ -19,13 +19,13 @@ class Config(BaseModel):
1919
Default is 1 second.
2020
"""
2121

22-
logging: Logs = Field(default_factory=Logs)
22+
logging: Logs = Field(default_factory=Logs, )
2323
"""
24-
An instance of the Logs class that defines logging settings for Process Governor.
24+
An instance of the Logs class that defines logging settings for application.
2525
Default settings are provided by the Logs class.
2626
"""
2727

2828
rules: List[Rule] = Field(default_factory=list)
2929
"""
30-
A list of Rule objects that specify how Process Governor manages processes and services based on user-defined rules.
30+
A list of Rule objects that specify how application manages processes and services based on user-defined rules.
3131
"""

src/configuration/handler/io_priority.py

Lines changed: 3 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,44 +2,18 @@
22
from pydantic import BeforeValidator, PlainSerializer, WithJsonSchema
33
from typing_extensions import Annotated
44

5-
__iopriority_to_str_mapping = {
6-
IOPriority.IOPRIO_VERYLOW: 'VeryLow',
7-
IOPriority.IOPRIO_LOW: 'Low',
8-
IOPriority.IOPRIO_NORMAL: 'Normal',
9-
IOPriority.IOPRIO_HIGH: 'High',
10-
}
11-
12-
__str_to_iopriority_mapping = {
13-
'VeryLow': IOPriority.IOPRIO_VERYLOW,
14-
'Low': IOPriority.IOPRIO_LOW,
15-
'Normal': IOPriority.IOPRIO_NORMAL,
16-
'High': IOPriority.IOPRIO_HIGH,
17-
}
5+
from constants.priority_mappings import iopriority_to_str, str_to_iopriority
186

197

208
def __to_enum(value):
219
if isinstance(value, IOPriority):
2210
return value
23-
return __str_to_iopriority_mapping.get(value)
11+
return str_to_iopriority[value]
2412

2513

2614
IOPriorityStr = Annotated[
2715
IOPriority,
2816
BeforeValidator(__to_enum),
29-
PlainSerializer(lambda value: __iopriority_to_str_mapping.get(value), return_type=str),
17+
PlainSerializer(lambda value: iopriority_to_str[value], return_type=str),
3018
WithJsonSchema({'type': 'string'}, mode='serialization'),
3119
]
32-
33-
34-
def iopriority_to_str(value: IOPriority):
35-
"""
36-
Convert a IO priority value to its corresponding string representation.
37-
38-
Args:
39-
value (int): The IO priority value to convert.
40-
41-
Returns:
42-
str: The string representation of the IO priority value, or None if no
43-
mapping is found.
44-
"""
45-
return __iopriority_to_str_mapping.get(value)

0 commit comments

Comments
 (0)