This repository has been archived by the owner on Aug 15, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added a logger class to create and manage log files internally. Added…
… an auto-suspend functionality where the macro automatically suspends unused instances. Added a keybind to suspend and unsuspend instances manually as well. Changes to .gitignore and README.md.
- Loading branch information
1 parent
19b6d73
commit 8ad824c
Showing
9 changed files
with
284 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ | |
__pycache__/ | ||
*.py[cod] | ||
*$py.class | ||
log/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
""" | ||
This is the module that implements a logger as a class. | ||
Custom designed for the project(MultiInstanceLinux). | ||
""" | ||
# Author: sathya-pramodh | ||
# Github: https://github.com/sathya-pramodh | ||
|
||
# Software Licensed under the MIT License. | ||
|
||
# License terms: | ||
|
||
# MIT License | ||
|
||
# Copyright (c) 2022 sathya-pramodh | ||
|
||
# Permission is hereby granted, free of charge, to any person obtaining a copy | ||
# of this software and associated documentation files (the "Software"), to deal | ||
# in the Software without restriction, including without limitation the rights | ||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
# copies of the Software, and to permit persons to whom the Software is | ||
# furnished to do so, subject to the following conditions: | ||
|
||
# The above copyright notice and this permission notice shall be included in all | ||
# copies or substantial portions of the Software. | ||
|
||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
# SOFTWARE. | ||
|
||
# Imports | ||
from datetime import datetime | ||
|
||
|
||
class Logging: | ||
""" | ||
Custom implementation of a logging class. | ||
""" | ||
|
||
def __init__(self, output_path): | ||
""" | ||
Initializer method for the class. | ||
output_path | ||
The full path to the folder to which you want to output the logs to. | ||
""" | ||
self._path = output_path | ||
self._session_log_file = ( | ||
output_path + datetime.now().strftime("%Y-%m-%d") + ".log" | ||
) | ||
|
||
def log(self, message): | ||
""" | ||
Method to log a message to a log file. | ||
message | ||
A string data type containing the message to be logged. | ||
Returns None | ||
""" | ||
with open(self._session_log_file, "a") as file: | ||
write_string = ( | ||
"\n" | ||
+ "[MultiInstanceLinux {}]".format(datetime.now().strftime("%H:%M:%S")) | ||
+ ": " | ||
+ message | ||
) | ||
file.write(write_string) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
""" | ||
This is a helper script that handles the suspend keybinds. | ||
Called from handle_instance_keybinds() in multi_instance.py | ||
""" | ||
# Author: sathya-pramodh | ||
# Github: https://github.com/sathya-pramodh | ||
# Software licensed under the MIT license. | ||
# License Terms: | ||
|
||
# MIT License | ||
|
||
# Copyright (c) 2022 sathya-pramodh | ||
|
||
# Permission is hereby granted, free of charge, to any person obtaining a copy | ||
# of this software and associated documentation files (the "Software"), to deal | ||
# in the Software without restriction, including without limitation the rights | ||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
# copies of the Software, and to permit persons to whom the Software is | ||
# furnished to do so, subject to the following conditions: | ||
|
||
# The above copyright notice and this permission notice shall be included in all | ||
# copies or substantial portions of the Software. | ||
|
||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
# SOFTWARE. | ||
import os | ||
import subprocess | ||
|
||
|
||
def suspend_all_macro(pids): | ||
""" | ||
The function that handles suspending all instances other than the current active instance. | ||
pids | ||
A list of the PIDs of all the open instances. | ||
Returns the hex code of the current active instance for logging purposes. | ||
""" | ||
current_hex_code_in_base_ten = subprocess.check_output( | ||
["xdotool", "getwindowfocus"] | ||
).decode("UTF-8") | ||
current_hex_code = hex(int(current_hex_code_in_base_ten)) | ||
if len(current_hex_code.split("x")[1]) == 7: | ||
current_hex_code = ( | ||
current_hex_code.split("x")[0] + "x0" + current_hex_code.split("x")[1] | ||
) | ||
for hex_code, pid in pids.items(): | ||
if hex_code != current_hex_code: | ||
os.system("kill -STOP " + pid) | ||
|
||
return current_hex_code | ||
|
||
|
||
def unsuspend_all_macro(pids): | ||
""" | ||
The function that handles unsuspending all instances other than the current active instance. | ||
pids | ||
A list of PIDs of all the open instances. | ||
Returns the hex code of the current active instance for logging purposes. | ||
""" | ||
for hex_code, pid in pids.items(): | ||
os.system("kill -CONT " + pid) |
Oops, something went wrong.