Skip to content

Commit

Permalink
V3.8 (#355)
Browse files Browse the repository at this point in the history
* 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
bilelmoussaoui authored May 21, 2017
1 parent d16a79e commit b4dcf51
Show file tree
Hide file tree
Showing 128 changed files with 1,089 additions and 712 deletions.
7 changes: 7 additions & 0 deletions .editorconfig
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.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,6 @@ target/

.idea/

tags
tags

.vscode/
20 changes: 13 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
[![Code Issues](https://www.quantifiedcode.com/api/v1/project/6ebdcd35681d424285ddf9e00e74b6e2/badge.svg)](https://www.quantifiedcode.com/app/project/6ebdcd35681d424285ddf9e00e74b6e2)
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/4d5c0768b874407bb1dcc2f928899ba5)](https://www.codacy.com/app/bil-elmoussaoui/Hardcode-Tray?utm_source=github.com&utm_medium=referral&utm_content=bil-elmoussaoui/Hardcode-Tray&utm_campaign=Badge_Grade)
[![Build Status](https://travis-ci.org/bil-elmoussaoui/Hardcode-Tray.svg?branch=master)](https://travis-ci.org/bil-elmoussaoui/Hardcode-Tray)[![Codacy Badge](https://api.codacy.com/project/badge/Grade/4d5c0768b874407bb1dcc2f928899ba5)](https://www.codacy.com/app/bil-elmoussaoui/Hardcode-Tray?utm_source=github.com&utm_medium=referral&utm_content=bil-elmoussaoui/Hardcode-Tray&utm_campaign=Badge_Grade)
[![Codacy Badge](https://api.codacy.com/project/badge/Coverage/4d5c0768b874407bb1dcc2f928899ba5)](https://www.codacy.com/app/bil-elmoussaoui/Hardcode-Tray?utm_source=github.com&utm_medium=referral&utm_content=bil-elmoussaoui/Hardcode-Tray&utm_campaign=Badge_Coverage)
[![Gitter](https://img.shields.io/gitter/room/nwjs/nw.js.svg)](https://gitter.im/Hardcode-Tray/Lobby?utm_source=share-link&utm_medium=link&utm_campaign=share-link)
[![Hardcode-Tray
release](https://img.shields.io/badge/release-v3.7-blue.svg)](https://github.com/bil-elmoussaoui/Hardcode-Tray/releases)
release](https://img.shields.io/badge/release-v3.8-blue.svg)](https://github.com/bil-elmoussaoui/Hardcode-Tray/releases)

# Hardcode-Tray

Expand Down Expand Up @@ -48,7 +47,7 @@ The one click-installer can be found by following this [link](https://software.o
#### Manual installation:
1. Download and install the script:
```bash
cd /tmp && wget -O - https://raw.githubusercontent.com/bil-elmoussaoui/Hardcode-Tray/master/install.sh | bash
cd /tmp && wget -O - https://raw.githubusercontent.com/bil-elmoussaoui/Hardcode-Tray/master/data/install.sh | bash
```

2. Install dependencies:
Expand All @@ -57,7 +56,7 @@ The one click-installer can be found by following this [link](https://software.o
- `python3`
- `python3-gi`
- [`patched sni-qt`](https://github.com/bil-elmoussaoui/sni-qt) <br>
- 2.1. Pick your favorite conversion tool
- 2.1. Pick up your favorite conversion tool
1. `python3-cairosvg`
2. `librsvg`
3. `inkscape`
Expand Down Expand Up @@ -138,6 +137,13 @@ Your favorite theme does not provide icons for all those hardcoded icons? Just u
hardcode-tray --change-color "#FIRSTCOLOR #REPLACE_FIRST_COLOR" "#SECONDCOLOR #REPLACE_SECOND_COLOR"...
```
- `clear-cache`
Let you clear the backup cache folder
```bash
hardcode-tray --clear-cache
```
- `--version`
You can print the version of Hardcode-Tray using
Expand All @@ -164,15 +170,15 @@ Hardcode-Tray also supports a JSON config file that can be placed under `~/.conf
- `blacklist`: a list of applications that you don't want to be fixed.
- `conversion-tool`: the default tool to be used everytime you use the script.
- `icons` : An object, that contains `theme` and `size` for the Gtk icon theme and the icon size to be used.

- `backup-ignore` : A boolean, to configure either you want default icons to be saved on the backup folder or not.
An example of the config file can be found [here](https://github.com/bil-elmoussaoui/Hardcode-Tray/blob/master/config.json).
Passing `--theme` `--conversion-tool` `--size` will overwrite the default settings.


### Uninstallation
To remove the script completely from your desktop you can use
```bash
cd /tmp && wget -O - https://raw.githubusercontent.com/bil-elmoussaoui/Hardcode-Tray/master/uninstall.sh | bash
cd /tmp && wget -O - https://raw.githubusercontent.com/bil-elmoussaoui/Hardcode-Tray/master/data/uninstall.sh | bash
```

### Credits
Expand Down
5 changes: 3 additions & 2 deletions config.json → data/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
"theme": "Numix",
"size": 24
},
"conversion-tool": "CairoSVG"
}
"conversion-tool": "CairoSVG",
"backup-ignore": true
}
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.
29 changes: 29 additions & 0 deletions data/database/mullvad.json
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.
6 changes: 3 additions & 3 deletions install.sh → data/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ else
versionnb=${version//[a-zA-Z]/}
cd ./Hardcode-Tray-"$versionnb" || exit
fi
rm -rf .git ./screenshots
rm -f .gitignore README.md install.sh uninstall.sh
rm -rf .git ./screenshots
rm -f .gitignore README.md data/install.sh data/uninstall.sh
cd ../ || exit
if [ -d "/opt/Hardcode-Tray" ]; then
sudo rm -rf /opt/Hardcode-Tray
Expand All @@ -34,7 +34,7 @@ else
sudo mv Hardcode-Tray-"$versionnb"/ /opt/Hardcode-Tray
fi
echo "Creating symbolic link.."
if [ -L "/usr/bin/hardcode-tray" ] || [ -f "/usr/bin/hardcode-tray" ];
if [ -L "/usr/bin/hardcode-tray" ] || [ -f "/usr/bin/hardcode-tray" ];
then
sudo rm -f /usr/bin/hardcode-tray
fi
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions hardcode-tray
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash
version=v3.7
version=v3.8
if [[ $EUID -ne 0 ]]; then
case $1 in
-u|--update)
Expand All @@ -23,7 +23,7 @@ if [[ $EUID -ne 0 ]]; then
exit 0 ;;
*)
cd /opt/Hardcode-Tray/
sudo -E python3 script.py "$@"
sudo -E python3 hardcode-tray.py "$@"
esac
else
echo "Script shouldn't be run as root"
Expand Down
116 changes: 30 additions & 86 deletions script.py → hardcode-tray.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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])
Expand Down Expand Up @@ -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
Expand All @@ -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!")
Loading

0 comments on commit b4dcf51

Please sign in to comment.