Skip to content

Commit f0ce6fb

Browse files
committed
Add optional input arguments
Add options for overwriting the default proc lists: -g/--good: override the good procs list -b/--bad: override the bad procs list -G/--appendgood: boolean flag to append the procs list, instead of overwrite -B/--appendbad: boolean flag to append the procs list, instead of overwrite
1 parent 35e159c commit f0ce6fb

File tree

3 files changed

+77
-13
lines changed

3 files changed

+77
-13
lines changed

autoprocprio.py

+72-8
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
4343
# SOFTWARE.
4444

45+
import argparse
4546
import atexit
4647
import datetime
4748
import time
@@ -63,7 +64,7 @@ def platform_is_windows():
6364
import win32api # For catching user closing the app window via the X icon
6465

6566
SCRIPT_NAME = "AutoProcPrio"
66-
SCRIPT_VERSION = "6.0.0"
67+
SCRIPT_VERSION = "6.1.0"
6768

6869

6970
def add_app(executable_name):
@@ -335,13 +336,7 @@ def _try_psutil_set(self, fn, val):
335336
return False
336337

337338

338-
print(f"\n\t== {SCRIPT_NAME} version {SCRIPT_VERSION} ==\n")
339-
340339
PROCS = []
341-
for procname in BAD_PROCNAMES:
342-
PROCS.append(TargetProcs(procname, BAD_NICENESS, BAD_AFFINITY, VERBOSE))
343-
for procname in GOOD_PROCNAMES:
344-
PROCS.append(TargetProcs(procname, GOOD_NICENESS, GOOD_AFFINITY, VERBOSE))
345340

346341

347342
def conditional(decorator, condition):
@@ -372,7 +367,76 @@ def restore_original_ps_values():
372367

373368

374369
def main():
375-
"""Entry point."""
370+
parser = argparse.ArgumentParser(
371+
prog=SCRIPT_NAME,
372+
description="Automatically set processes' CPU priority and affinity "
373+
"by process name",
374+
epilog=f"Version {SCRIPT_VERSION}",
375+
)
376+
parser.add_argument(
377+
"-g",
378+
"--good",
379+
help="comma-delimited list of app(s) to prioritize (optional)",
380+
)
381+
parser.add_argument(
382+
"-b",
383+
"--bad",
384+
help="comma-delimited list of app(s) to deprioritize (optional)",
385+
)
386+
parser.add_argument(
387+
"-G",
388+
"--appendgood",
389+
action="store_true",
390+
help="if set, will append the good apps list instead of overwriting",
391+
)
392+
parser.add_argument(
393+
"-B",
394+
"--appendbad",
395+
action="store_true",
396+
help="if set, will append the bad apps list instead of overwriting",
397+
)
398+
args = parser.parse_args()
399+
400+
print(f"\n\t== {SCRIPT_NAME} version {SCRIPT_VERSION} ==\n")
401+
402+
global PROCS
403+
if args.good is None or args.appendgood:
404+
for procname in GOOD_PROCNAMES:
405+
PROCS.append(
406+
TargetProcs(procname, GOOD_NICENESS, GOOD_AFFINITY, VERBOSE)
407+
)
408+
try:
409+
for procname in [
410+
x
411+
for x in list(set(args.good.split(",")))
412+
if add_app(x) not in GOOD_PROCNAMES
413+
]:
414+
PROCS.append(
415+
TargetProcs(
416+
add_app(procname), GOOD_NICENESS, GOOD_AFFINITY, VERBOSE
417+
)
418+
)
419+
except AttributeError:
420+
pass
421+
422+
if args.bad is None or args.appendbad:
423+
for procname in BAD_PROCNAMES:
424+
PROCS.append(
425+
TargetProcs(procname, BAD_NICENESS, BAD_AFFINITY, VERBOSE)
426+
)
427+
try:
428+
for procname in [
429+
x
430+
for x in list(set(args.bad.split(",")))
431+
if add_app(x) not in BAD_PROCNAMES
432+
]:
433+
PROCS.append(
434+
TargetProcs(add_app(procname), BAD_NICENESS, BAD_AFFINITY,
435+
VERBOSE)
436+
)
437+
except AttributeError:
438+
pass
439+
376440
global EXITING
377441
while not EXITING:
378442
print_info("Proc update...")

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "autoprocprio"
3-
version = "6.0.0"
3+
version = "6.1.0"
44
description = "Automatically prioritize important apps' CPU priority and affinity"
55
authors = ["Rain <[email protected]>"]
66
license = "MIT License"

version.rc

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
VSVersionInfo(
22
ffi=FixedFileInfo(
3-
filevers=(6, 0, 0, 0),
4-
prodvers=(6, 0, 0, 0),
3+
filevers=(6, 1, 0, 0),
4+
prodvers=(6, 1, 0, 0),
55
mask=0x3f,
66
flags=0x0,
77
OS=0x40004,
@@ -15,12 +15,12 @@ VSVersionInfo(
1515
StringTable(
1616
u'040904B0',
1717
[StringStruct(u'FileDescription', u'Automatically prioritize important apps\x27 CPU priority and affinity'),
18-
StringStruct(u'FileVersion', u'6.0.0'),
18+
StringStruct(u'FileVersion', u'6.1.0'),
1919
StringStruct(u'InternalName', u'autoprocprio'),
2020
StringStruct(u'LegalCopyright', u'\xa9 github.com/Rainyan. MIT licensed.'),
2121
StringStruct(u'OriginalFilename', u'autoprocprio.exe'),
2222
StringStruct(u'ProductName', u'AutoProcPrio'),
23-
StringStruct(u'ProductVersion', u'6.0.0')])
23+
StringStruct(u'ProductVersion', u'6.1.0')])
2424
]),
2525
VarFileInfo([VarStruct(u'Translation', [1033, 1200])])
2626
]

0 commit comments

Comments
 (0)