Skip to content

Commit

Permalink
v3.7
Browse files Browse the repository at this point in the history
* add initial config file, road to 3.7

* add some documentation
  • Loading branch information
bilelmoussaoui authored Mar 30, 2017
1 parent 3435653 commit 59611a8
Show file tree
Hide file tree
Showing 25 changed files with 106 additions and 41 deletions.
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
[![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.6.6-blue.svg)](https://github.com/bil-elmoussaoui/Hardcode-Tray/releases)
release](https://img.shields.io/badge/release-v3.7-blue.svg)](https://github.com/bil-elmoussaoui/Hardcode-Tray/releases)

# Hardcode-Tray

Expand Down Expand Up @@ -159,6 +159,16 @@ You can also update to the git version of the script
hardcode-tray --update-git
```

### Config file
Hardcode-Tray also supports a JSON config file that can be placed under `~/.config`. The file must be named `hardcode-tray.json`. The file supports the following options for now.
- `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.

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
Expand Down
8 changes: 8 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"blacklist": ["telegram", "hangouts"],
"icons": {
"theme": "Numix",
"size": 24
},
"conversion-tool": "CairoSVG"
}
2 changes: 1 addition & 1 deletion hardcode-tray
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash
version=v3.6.6
version=v3.7
if [[ $EUID -ne 0 ]]; then
case $1 in
-u|--update)
Expand Down
2 changes: 1 addition & 1 deletion modules/applications/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Author : Bilal Elmoussaoui (bil.elmoussaoui@gmail.com)
Contributors : Andreas Angerer, Joshua Fogg
Version : 3.6.6
Version : 3.7
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 Down
2 changes: 1 addition & 1 deletion modules/applications/binary.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Author : Bilal Elmoussaoui (bil.elmoussaoui@gmail.com)
Contributors : Andreas Angerer, Joshua Fogg
Version : 3.6.6
Version : 3.7
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 Down
2 changes: 1 addition & 1 deletion modules/applications/electron.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Author : Bilal Elmoussaoui (bil.elmoussaoui@gmail.com)
Contributors : Andreas Angerer, Joshua Fogg
Version : 3.6.6
Version : 3.7
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 Down
2 changes: 1 addition & 1 deletion modules/applications/nwjs.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Author : Bilal Elmoussaoui (bil.elmoussaoui@gmail.com)
Contributors : Andreas Angerer, Joshua Fogg
Version : 3.6.6
Version : 3.7
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 Down
2 changes: 1 addition & 1 deletion modules/applications/pak.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Author : Bilal Elmoussaoui (bil.elmoussaoui@gmail.com)
Contributors : Andreas Angerer, Joshua Fogg
Version : 3.6.6
Version : 3.7
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 Down
2 changes: 1 addition & 1 deletion modules/applications/qt.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Author : Bilal Elmoussaoui (bil.elmoussaoui@gmail.com)
Contributors : Andreas Angerer, Joshua Fogg
Version : 3.6.6
Version : 3.7
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 Down
2 changes: 1 addition & 1 deletion modules/applications/zip.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Author : Bilal Elmoussaoui (bil.elmoussaoui@gmail.com)
Contributors : Andreas Angerer, Joshua Fogg
Version : 3.6.6
Version : 3.7
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 Down
3 changes: 2 additions & 1 deletion modules/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Author : Bilal Elmoussaoui (bil.elmoussaoui@gmail.com)
Contributors : Andreas Angerer, Joshua Fogg
Version : 3.6.6
Version : 3.7
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 @@ -30,6 +30,7 @@
USERNAME = getenv("SUDO_USER")
USERHOME = get_userhome(USERNAME)
BACKUP_FOLDER = path.join(USERHOME, ".config", "Hardcode-Tray", "")
CONFIG_FILE = path.join(USERHOME, ".config", "hardcode-tray.json")
BACKUP_FILE_FORMAT = "%d-%m-%Y_%H-%M-%S"
LOG_FILE_FORMAT = "%d-%m-%Y_%H-%M-%S"
CHMOD_IGNORE_LIST = ["", "home"]
Expand Down
2 changes: 1 addition & 1 deletion modules/icon.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Author : Bilal Elmoussaoui (bil.elmoussaoui@gmail.com)
Contributors : Andreas Angerer, Joshua Fogg
Version : 3.6.6
Version : 3.7
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 Down
47 changes: 39 additions & 8 deletions modules/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Author : Bilal Elmoussaoui (bil.elmoussaoui@gmail.com)
Contributors : Andreas Angerer, Joshua Fogg
Version : 3.6.6
Version : 3.7
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 Down Expand Up @@ -194,8 +194,9 @@ def replace_vars_path(self, _path):
class ArgsParser:
"""CLI arguments parser."""

def __init__(self, args):
def __init__(self, args, config):
self._args = args
self._config = config
self._parse()

def _parse(self):
Expand All @@ -209,6 +210,11 @@ def _parse(self):
self._parse_path()
self._parse_choice()

@property
def config(self):
"""Property: config."""
return self._config

@property
def args(self):
"""Property : args."""
Expand All @@ -222,7 +228,17 @@ def _parse_theme(self):
"dark": Theme(self.args.dark_theme),
"light": Theme(self.args.light_theme)
}
else:
elif self.config.get("icons", None):
theme = self.config["icons"].get("theme", {})
if isinstance(theme, str):
self.theme = Theme(theme)
else:
if theme.get("light", None) and theme.get("dark", None):
self.theme = {
"dark": Theme(theme["dark"]),
"light": Theme(theme["light"])
}
if not self.theme:
source = Gio.SettingsSchemaSource.get_default()
if source.lookup("org.gnome.desktop.interface", True):
gsettings = Gio.Settings.new("org.gnome.desktop.interface")
Expand All @@ -242,10 +258,14 @@ def _parse_colors(self):
self.colours = colours

def _parse_conversion_tool(self):
conversion_tool = None
if self.args.conversion_tool:
conversion_tool = self.args.conversion_tool
elif self.config.get("conversion-tool", None):
conversion_tool = self.config.get("conversion-tool")
if conversion_tool:
try:
self.svgtopng = CONVERSION_TOOLS[
self.args.conversion_tool](self.colours)
self.svgtopng = CONVERSION_TOOLS[conversion_tool](self.colours)
except SVGNotInstalled:
exit("The selected conversion tool is not installed.")
else:
Expand All @@ -267,9 +287,17 @@ def _parse_icon_size(self):
self.icon_size = self.args.size
else:
if DESKTOP_ENV in ("pantheon", "xfce"):
self.icon_size = 24
icon_size = 24
else:
icon_size = 22
if self.config.get("icons", None):
self.icon_size = self.config["icons"].get("size", icon_size)
if self.icon_size not in [16, 22, 24]:
self.icon_size = icon_size
logging.debug("Icon size in the config file is wrong. "
"Falling back to the detected one...")
else:
self.icon_size = 22
self.icon_size = icon_size

def _parse_scaling_factor(self):
self.scaling_factor = get_scaling_factor(DESKTOP_ENV)
Expand All @@ -280,7 +308,10 @@ def _parse_scaling_factor(self):
def _parse_fix_only(self):
self.only = []
if self.args.only:
self.only = self.args.only.lower().strip().split(",")
only = self.args.only.lower().strip().split(",")
for bfile in self.config.get("blacklist"):
only.remove(bfile)
self.only = only

def _parse_path(self):
self.path = None
Expand Down
2 changes: 1 addition & 1 deletion modules/paths/dropbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Author : Bilal Elmoussaoui (bil.elmoussaoui@gmail.com)
Contributors : Andreas Angerer, Joshua Fogg
Version : 3.6.6
Version : 3.7
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 Down
2 changes: 1 addition & 1 deletion modules/paths/hangouts.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Author : Bilal Elmoussaoui (bil.elmoussaoui@gmail.com)
Contributors : Andreas Angerer, Joshua Fogg
Version : 3.6.6
Version : 3.7
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 Down
2 changes: 1 addition & 1 deletion modules/svg/imagemagick.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Author : Bilal Elmoussaoui (bil.elmoussaoui@gmail.com)
Contributors : Andreas Angerer, Joshua Fogg
Version : 3.6.6
Version : 3.7
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 Down
2 changes: 1 addition & 1 deletion modules/svg/inkscape.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Author : Bilal Elmoussaoui (bil.elmoussaoui@gmail.com)
Contributors : Andreas Angerer, Joshua Fogg
Version : 3.6.6
Version : 3.7
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 Down
2 changes: 1 addition & 1 deletion modules/svg/rsvgconvert.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Author : Bilal Elmoussaoui (bil.elmoussaoui@gmail.com)
Contributors : Andreas Angerer, Joshua Fogg
Version : 3.6.6
Version : 3.7
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 Down
2 changes: 1 addition & 1 deletion modules/svg/svg.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Author : Bilal Elmoussaoui (bil.elmoussaoui@gmail.com)
Contributors : Andreas Angerer, Joshua Fogg
Version : 3.6.6
Version : 3.7
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 Down
2 changes: 1 addition & 1 deletion modules/svg/svgcairo.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Author : Bilal Elmoussaoui (bil.elmoussaoui@gmail.com)
Contributors : Andreas Angerer, Joshua Fogg
Version : 3.6.6
Version : 3.7
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 Down
2 changes: 1 addition & 1 deletion modules/svg/svgexport.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Author : Bilal Elmoussaoui (bil.elmoussaoui@gmail.com)
Contributors : Andreas Angerer, Joshua Fogg
Version : 3.6.6
Version : 3.7
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 Down
2 changes: 1 addition & 1 deletion modules/theme.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Author : Bilal Elmoussaoui (bil.elmoussaoui@gmail.com)
Contributors : Andreas Angerer, Joshua Fogg
Version : 3.6.6
Version : 3.7
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 Down
2 changes: 1 addition & 1 deletion modules/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Author : Bilal Elmoussaoui (bil.elmoussaoui@gmail.com)
Contributors : Andreas Angerer, Joshua Fogg
Version : 3.6.6
Version : 3.7
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 Down
14 changes: 12 additions & 2 deletions modules/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Author : Bilal Elmoussaoui (bil.elmoussaoui@gmail.com)
Contributors : Andreas Angerer, Joshua Fogg
Version : 3.6.6
Version : 3.7
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 Down Expand Up @@ -32,7 +32,7 @@
from modules.const import (USERHOME, CHMOD_IGNORE_LIST, USER_ID, GROUP_ID, LOG_FILE_FORMAT, BACKUP_EXTENSION,
BACKUP_FOLDER, BACKUP_FILE_FORMAT)
from gi.repository import Gio

from json import load

def setup_logging():
"""Setup logging handlern write to a file under /tmp."""
Expand Down Expand Up @@ -68,6 +68,16 @@ def progress(count, count_max, app_name=""):
stdout.flush()


def parse_json(file_name):
"""Parse json file and return the object."""
if path.isfile(file_name):
with open(file_name, 'r') as data:
json = load(data)
data.close()
return json
return {}


def symlink_file(source, link_name):
"""Symlink a file, remove the dest file if already exists."""
try:
Expand Down
Loading

0 comments on commit 59611a8

Please sign in to comment.