-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* make the script more pythony * more improvements, not working yet * a lot of fixes * add support of mullvad fixes #350 and fixes #346 * use @staticmethod * remove unused code * add editorconfig * add some comments * bump version number
- Loading branch information
1 parent
d16a79e
commit b4dcf51
Showing
128 changed files
with
1,089 additions
and
712 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
root = true | ||
[*] | ||
indent_style = space | ||
indent_size = 4 | ||
charset = utf-8 | ||
trim_trailing_whitespace = true | ||
insert_final_newline = true |
File renamed without changes.
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 |
---|---|---|
|
@@ -58,4 +58,6 @@ target/ | |
|
||
.idea/ | ||
|
||
tags | ||
tags | ||
|
||
.vscode/ |
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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,29 @@ | ||
{ | ||
"name": "Mullvad", | ||
"app_path": [ | ||
"/usr/bin/", | ||
"/usr/lib/python2.7/site-packages/mullvad/" | ||
], | ||
"icons_path": [ | ||
"/usr/lib/python2.7/site-packages/mullvad/" | ||
], | ||
"is_qt": false, | ||
"is_script": false, | ||
"force_create_folder": false, | ||
"exec_path_script": false, | ||
"backup_ignore": false, | ||
"icons": { | ||
"error": { | ||
"original": "rdot.png", | ||
"theme": "mullvad-error" | ||
}, | ||
"config": { | ||
"original": "ydot.png", | ||
"theme": "mullvad-config" | ||
}, | ||
"success": { | ||
"original": "gdot.png", | ||
"theme": "mullvad-success" | ||
} | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
File renamed without changes.
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 |
---|---|---|
|
@@ -4,7 +4,7 @@ | |
Author : Bilal Elmoussaoui ([email protected]) | ||
Contributors : Andreas Angerer, Joshua Fogg | ||
Version : 3.7 | ||
Version : 3.8 | ||
Website : https://github.com/bil-elmoussaoui/Hardcode-Tray | ||
Licence : The script is released under GPL, uses a modified script | ||
form Chromium project released under BSD license | ||
|
@@ -20,23 +20,19 @@ | |
You should have received a copy of the GNU General Public License | ||
along with Hardcode-Tray. If not, see <http://www.gnu.org/licenses/>. | ||
""" | ||
from os import path, geteuid | ||
from glob import glob | ||
from os import geteuid | ||
from argparse import ArgumentParser | ||
from modules.parser import Parser, ArgsParser, CONVERSION_TOOLS | ||
from modules.utils import parse_json, progress, get_list_of_themes | ||
from modules.const import DB_FOLDER, DESKTOP_ENV, CONFIG_FILE | ||
|
||
from src.utils import get_list_of_themes | ||
from src.const import DESKTOP_ENV | ||
from src.enum import Action, ConversionTools | ||
from src.app import App | ||
|
||
if geteuid() != 0: | ||
exit("You need to have root privileges to run the script.\ | ||
\nPlease try again, this time using 'sudo'. Exiting.") | ||
|
||
parser = ArgumentParser(prog="hardcode-tray") | ||
THEMES_LIST = get_list_of_themes() | ||
config = parse_json(CONFIG_FILE) | ||
BLACKLIST = config.get("blacklist", []) | ||
|
||
parser.add_argument("--size", "-s", help="use a different icon size instead " | ||
"of the default one.", | ||
type=int, choices=[16, 22, 24]) | ||
|
@@ -73,95 +69,42 @@ | |
help="revert fixed hardcoded tray icons") | ||
parser.add_argument("--conversion-tool", "-ct", | ||
help="Which of conversion tool to use", | ||
type=str, choices=CONVERSION_TOOLS.keys()) | ||
type=str, choices=ConversionTools.choices()) | ||
parser.add_argument('--change-color', "-cc", type=str, nargs='+', | ||
help="Replace a color with an other one, " | ||
"works only with SVG.") | ||
parser.add_argument("--clear-cache", action="store_true", | ||
help="Clear backup files") | ||
args = parser.parse_args() | ||
args = ArgsParser(args, config) | ||
hardcode_tray = App.get_default(args) | ||
|
||
if (not DESKTOP_ENV or DESKTOP_ENV == "other") and not args.icon_size: | ||
if (not DESKTOP_ENV or DESKTOP_ENV == "other") and not App.icon_size(): | ||
exit("You need to run the script using 'sudo -E'.\nPlease try again") | ||
|
||
def get_supported_apps(fix_only, custom_path=""): | ||
"""Get a list of dict, a dict for each supported application.""" | ||
database_files = [] | ||
if len(fix_only) != 0: | ||
for db_file in fix_only: | ||
if db_file not in BLACKLIST: | ||
db_file = "{0}{1}.json".format(DB_FOLDER, db_file) | ||
if path.exists(db_file): | ||
database_files.append(db_file) | ||
else: | ||
files = glob("{0}*.json".format(path.join(DB_FOLDER, ""))) | ||
for file in files: | ||
if path.splitext(path.basename(file))[0] not in BLACKLIST: | ||
database_files.append(file) | ||
if len(fix_only) > 1 and custom_path: | ||
exit("You can't use --path with more than application at once.") | ||
database_files.sort() | ||
supported_apps = [] | ||
for db_file in database_files: | ||
application_data = Parser(db_file, args) | ||
if application_data.is_installed(): | ||
supported_apps.append(application_data.get_application()) | ||
return supported_apps | ||
|
||
|
||
def apply(is_install): | ||
"""Fix Hardcoded Tray icons. | ||
Args: | ||
is_install(bool): | ||
True: To apply the modifications | ||
False: To revert it. | ||
""" | ||
apps = get_supported_apps(args.only, args.path) | ||
done = [] | ||
if len(apps) != 0: | ||
cnt = 0 | ||
counter_total = sum(app.data.supported_icons_cnt for app in apps) | ||
for i, app in enumerate(apps): | ||
app_name = app.get_name() | ||
if is_install: | ||
app.install() | ||
else: | ||
app.reinstall() | ||
if app.is_done: | ||
cnt += app.data.supported_icons_cnt | ||
if app_name not in done: | ||
progress(cnt, counter_total, app_name) | ||
done.append(app_name) | ||
else: | ||
counter_total -= app.data.supported_icons_cnt | ||
if i == len(apps) - 1: | ||
progress(cnt, counter_total) | ||
else: | ||
if is_install: | ||
exit("No apps to fix! Please report on GitHub if this is not the case") | ||
else: | ||
exit("No apps to revert!") | ||
|
||
print("Welcome to the tray icons hardcoder fixer!") | ||
print("Your indicator icon size is : {0}".format(args.icon_size)) | ||
print("Your indicator icon size is : {0}".format(App.icon_size())) | ||
print("The detected desktop environement : {0}".format(DESKTOP_ENV.title())) | ||
if not isinstance(args.theme, dict): | ||
print("Your current icon theme is : {0}".format(args.theme)) | ||
if not isinstance(App.theme(), dict): | ||
print("Your current icon theme is : {0}".format(App.theme())) | ||
else: | ||
print("Your current dark icon theme is : {0}".format(args.theme["dark"])) | ||
print("Your current light icon theme is : {0}".format(args.theme["light"])) | ||
print("Conversion tool : {0}".format(args.svgtopng)) | ||
print("Your current dark icon theme is : {0}".format(App.theme()["dark"])) | ||
print("Your current light icon theme is : {0}".format( | ||
App.theme()["light"])) | ||
print("Conversion tool : {0}".format(App.svg())) | ||
print("Applications will be fixed : ", end="") | ||
print(",".join(map(lambda x: x.title(), args.only)) if args.only else "All") | ||
print(",".join(map(lambda x: x.title(), App.only())) if App.only() else "All") | ||
|
||
choice = args.choice | ||
if not choice: | ||
# Clear backup cache | ||
action = App.action() | ||
if not action: | ||
print("1 - Apply") | ||
print("2 - Revert") | ||
print("3 - Clear Backup Cache") | ||
has_chosen = False | ||
while not has_chosen: | ||
try: | ||
choice = int(input("Please choose: ")) | ||
if choice not in [1, 2]: | ||
action = int(input("Please choose: ")) | ||
if action not in [1, 2, 3]: | ||
print("Please try again") | ||
else: | ||
has_chosen = True | ||
|
@@ -170,11 +113,12 @@ def apply(is_install): | |
except KeyboardInterrupt: | ||
exit("") | ||
|
||
if choice == 1: | ||
if action == Action.APPLY: | ||
print("Applying now..\n") | ||
apply(True) | ||
elif choice == 2: | ||
elif action == Action.REVERT: | ||
print("Reverting now..\n") | ||
apply(False) | ||
elif action == Action.CLEAR_CACHE: | ||
print("Clearing cache...\n") | ||
App.execute(action) | ||
|
||
print("\nDone, Thank you for using the Hardcode-Tray fixer!") |
Oops, something went wrong.