compile Python bytecode, install pacman hook
This commit is contained in:
parent
4ab3a194e7
commit
331889d01c
35
.SRCINFO
35
.SRCINFO
|
|
@ -1,28 +1,27 @@
|
|||
pkgbase = hardcode-tray-git
|
||||
pkgdesc = Fixes Hardcoded Tray Icons
|
||||
pkgver = 4.3.r15.g46df7ea
|
||||
pkgdesc = Fixes hardcoded tray icons
|
||||
pkgver = 4.3.r214.ga6ecf12
|
||||
pkgrel = 1
|
||||
url = https://github.com/bil-elmoussaoui/Hardcode-Tray
|
||||
arch = i686
|
||||
arch = x86_64
|
||||
license = GPL-3.0
|
||||
makedepends = ninja
|
||||
makedepends = meson
|
||||
license = GPL3
|
||||
makedepends = git
|
||||
depends = python
|
||||
depends = python-gobject
|
||||
depends = python-cairosvg
|
||||
depends = librsvg
|
||||
makedepends = gobject-introspection
|
||||
makedepends = meson
|
||||
depends = gtk3
|
||||
depends = gobject-introspection
|
||||
optdepends = sni-qt-patched-git: patched qt4 sni plugin to enable icon modification
|
||||
optdepends = inkscape: to convert svg to png with inkscape
|
||||
provides = hardcode-tray-git
|
||||
conflicts = hardcode-tray-fixer-git
|
||||
depends = librsvg
|
||||
depends = python-cairosvg
|
||||
depends = python-gobject
|
||||
optdepends = nodejs-svgexport: option to convert svg to png
|
||||
optdepends = imagemagick: option to convert svg to png
|
||||
optdepends = inkscape: option to convert svg to png
|
||||
provides = hardcode-tray
|
||||
conflicts = hardcode-tray
|
||||
source = git://github.com/bil-elmoussaoui/Hardcode-Tray
|
||||
source = hardcode-tray::git+https://github.com/bil-elmoussaoui/Hardcode-Tray.git
|
||||
source = 90-hardcode-tray.hook
|
||||
source = hook.py
|
||||
sha256sums = SKIP
|
||||
optdepends_x86_64 = lib32-sni-qt-patched-git: 32-bit patched qt4 sni plugin to enable icon modification
|
||||
sha256sums = c16ba6a82d4fe523cb91bf472b44296db82ff301866e3bce18bb4149d0aae5ea
|
||||
sha256sums = 64a9907f74c5c04fb9f32b2b0684a3ce040d3bc2baacabb3ca1e914d70f24c81
|
||||
|
||||
pkgname = hardcode-tray-git
|
||||
|
||||
|
|
|
|||
14
.gitignore
vendored
14
.gitignore
vendored
|
|
@ -1,5 +1,9 @@
|
|||
pkg/
|
||||
src/
|
||||
*.tar.gz
|
||||
*.tar.xz
|
||||
Hardcode-Tray/
|
||||
# Ignore everything
|
||||
*
|
||||
|
||||
# But not these files...
|
||||
!.gitignore
|
||||
!PKGBUILD
|
||||
!.SRCINFO
|
||||
!90-hardcode-tray.hook
|
||||
!hook.py
|
||||
|
|
|
|||
12
90-hardcode-tray.hook
Normal file
12
90-hardcode-tray.hook
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
[Trigger]
|
||||
Operation = Install
|
||||
Operation = Upgrade
|
||||
Type = Package
|
||||
Target = *
|
||||
|
||||
[Action]
|
||||
Description = Updating tray icons...
|
||||
Depends = hardcode-tray-git
|
||||
When = PostTransaction
|
||||
Exec = /usr/bin/python /usr/share/hardcode-tray/hook.py
|
||||
NeedsTargets
|
||||
66
PKGBUILD
66
PKGBUILD
|
|
@ -1,38 +1,52 @@
|
|||
# Maintainer: Yuanji <self@gimo.me>
|
||||
# Maintainer: Mark Wagie <mark dot wagie at tutanota dot com>
|
||||
# Contributor: Yuanji <self@gimo.me>
|
||||
# Contributor: Bilal Elmoussaoui <bil.elmoussaoui@gmail.com>
|
||||
|
||||
_pkgbase=hardcode-tray-git
|
||||
_gitname=Hardcode-Tray
|
||||
pkgname=$_pkgbase
|
||||
pkgver=4.3.r15.g46df7ea
|
||||
pkgname=hardcode-tray-git
|
||||
pkgver=4.3.r214.ga6ecf12
|
||||
pkgrel=1
|
||||
pkgdesc="Fixes Hardcoded Tray Icons"
|
||||
arch=('i686' 'x86_64')
|
||||
pkgdesc="Fixes hardcoded tray icons"
|
||||
arch=('x86_64')
|
||||
url="https://github.com/bil-elmoussaoui/Hardcode-Tray"
|
||||
license=('GPL-3.0')
|
||||
provides=("$_pkgbase")
|
||||
conflicts=("hardcode-tray-fixer-git" "hardcode-tray")
|
||||
makedepends=('ninja' 'meson' 'git')
|
||||
depends=('python' 'python-gobject' 'python-cairosvg' 'librsvg' 'gtk3' 'gobject-introspection')
|
||||
optdepends=('sni-qt-patched-git: patched qt4 sni plugin to enable icon modification' 'inkscape: to convert svg to png with inkscape')
|
||||
optdepends_x86_64=('lib32-sni-qt-patched-git: 32-bit patched qt4 sni plugin to enable icon modification')
|
||||
source=("git://github.com/bil-elmoussaoui/Hardcode-Tray")
|
||||
sha256sums=('SKIP')
|
||||
license=('GPL3')
|
||||
depends=('gtk3' 'librsvg' 'python-cairosvg' 'python-gobject')
|
||||
makedepends=('git' 'gobject-introspection' 'meson')
|
||||
optdepends=('nodejs-svgexport: option to convert svg to png'
|
||||
'imagemagick: option to convert svg to png'
|
||||
'inkscape: option to convert svg to png')
|
||||
provides=("${pkgname%-git}")
|
||||
conflicts=("${pkgname%-git}")
|
||||
source=("${pkgname%-git}::git+https://github.com/bil-elmoussaoui/Hardcode-Tray.git"
|
||||
"90-${pkgname%-git}.hook"
|
||||
"hook.py")
|
||||
sha256sums=('SKIP'
|
||||
'c16ba6a82d4fe523cb91bf472b44296db82ff301866e3bce18bb4149d0aae5ea'
|
||||
'64a9907f74c5c04fb9f32b2b0684a3ce040d3bc2baacabb3ca1e914d70f24c81')
|
||||
|
||||
pkgver() {
|
||||
cd "$srcdir/$_gitname"
|
||||
( set -o pipefail
|
||||
git describe --long --tags 2>/dev/null | sed 's/^v//;s/\([^-]*-g\)/r\1/;s/-/./g' ||
|
||||
printf "r%s.%s" "$(git rev-list --count HEAD)" "$(git rev-parse --short HEAD)"
|
||||
)
|
||||
cd "$srcdir/${pkgname%-git}"
|
||||
git describe --long --tags | sed 's/^v//;s/\([^-]*-g\)/r\1/;s/-/./g'
|
||||
}
|
||||
|
||||
prepare() {
|
||||
cd "$srcdir/${pkgname%-git}"
|
||||
sed -i 's|resources/||g' data/database/bitwarden.electron.json
|
||||
}
|
||||
|
||||
build() {
|
||||
cd "$srcdir/${_gitname}"
|
||||
meson builddir --prefix=/usr
|
||||
arch-meson "${pkgname%-git}" build
|
||||
meson compile -C build
|
||||
}
|
||||
|
||||
package() {
|
||||
cd "$srcdir/${_gitname}"
|
||||
DESTDIR="${pkgdir}" ninja -C builddir install
|
||||
meson install -C build --destdir "$pkgdir"
|
||||
|
||||
# Compile Python bytecode:
|
||||
local site_packages=$(python -c "import site; print(site.getsitepackages()[0])")
|
||||
python -m compileall -d "$site_packages" "$pkgdir$site_packages"
|
||||
python -O -m compileall -d "$site_packages" "$pkgdir$site_packages"
|
||||
|
||||
# Add pacman hook
|
||||
# https://github.com/bilelmoussaoui/Hardcode-Tray/issues/454
|
||||
install -Dm644 "$srcdir/90-${pkgname%-git}.hook" -t "$pkgdir/etc/pacman.d/hooks"
|
||||
install -Dm644 "$srcdir/hook.py" -t "$pkgdir/usr/share/${pkgname%-git}"
|
||||
}
|
||||
|
|
|
|||
135
hook.py
Normal file
135
hook.py
Normal file
|
|
@ -0,0 +1,135 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
import json
|
||||
import re
|
||||
import sys
|
||||
|
||||
from subprocess import run, PIPE
|
||||
from glob import glob
|
||||
from os import path
|
||||
|
||||
from HardcodeTray.const import DB_FOLDER, USERHOME
|
||||
|
||||
HARDCORE_TRAY_PACKAGES = ['hardcode-tray-git', 'hardcode-tray']
|
||||
BLACKLIST = ['mullvad'] # Added cause got /usr/bin in it paths
|
||||
|
||||
CONVERSION_TOOL = 'RSVGConvert' # None if not needed
|
||||
THEME = 'Papirus-Dark' # None if not needed
|
||||
|
||||
|
||||
class Hook:
|
||||
userhome_re = r"{userhome}"
|
||||
|
||||
def __init__(self, packages):
|
||||
self.__packages = packages
|
||||
self.__db = self.read_db_files()
|
||||
|
||||
|
||||
def read_db_files(self):
|
||||
""" Reading all package paths """
|
||||
|
||||
files = glob("{0}*.json".format(path.join(DB_FOLDER, "")))
|
||||
db = {}
|
||||
|
||||
for db_file in files:
|
||||
script_name = path.splitext(path.basename(db_file))[0]
|
||||
|
||||
if script_name in BLACKLIST:
|
||||
continue
|
||||
|
||||
with open(db_file, 'r') as db_file:
|
||||
app_path = json.load(db_file)['app_path']
|
||||
db[script_name] = [re.sub(Hook.userhome_re, USERHOME, sctipt_path) for sctipt_path in app_path]
|
||||
|
||||
return db
|
||||
|
||||
def get_package_paths(self, package):
|
||||
""" Reading all package paths from pacman """
|
||||
|
||||
regex = r"^%s\s+" % re.escape(package)
|
||||
proc = run(
|
||||
[
|
||||
"pacman", "-Ql",
|
||||
package
|
||||
],
|
||||
stdout=PIPE,
|
||||
stderr=PIPE,
|
||||
)
|
||||
|
||||
if proc.returncode == 0:
|
||||
output = str(proc.stdout, "utf-8").split('\n')
|
||||
return [re.sub(regex, '',line) for line in output if re.match(regex, line)]
|
||||
else:
|
||||
return []
|
||||
|
||||
def get_supported_scripts(self):
|
||||
""" Finding supported scripts """
|
||||
|
||||
supported_scripts = [];
|
||||
|
||||
for package in self.__packages:
|
||||
package_paths = self.get_package_paths(package)
|
||||
for path in package_paths:
|
||||
for script_name, script_paths in self.__db.items():
|
||||
if path in script_paths:
|
||||
supported_scripts.append(script_name)
|
||||
|
||||
return set(supported_scripts)
|
||||
|
||||
def run_hadcode_tray(self, packages = None):
|
||||
""" Hardcode tray bit execution """
|
||||
|
||||
args = ["hardcode-tray"]
|
||||
|
||||
if CONVERSION_TOOL != None:
|
||||
args += ["--conversion-tool", CONVERSION_TOOL]
|
||||
|
||||
if THEME != None:
|
||||
args += ["--theme", THEME]
|
||||
|
||||
if packages != None:
|
||||
args += ["--only", ','.join(packages)]
|
||||
|
||||
args.append("--apply")
|
||||
|
||||
proc = run(
|
||||
args,
|
||||
stdout=PIPE,
|
||||
stderr=PIPE,
|
||||
)
|
||||
|
||||
return (proc.returncode == 0)
|
||||
|
||||
def execute(self):
|
||||
""" Execution method running hardcode-tray for supported apps"""
|
||||
|
||||
for package in self.__packages:
|
||||
if package in HARDCORE_TRAY_PACKAGES:
|
||||
if self.run_hadcode_tray():
|
||||
print("All packages are updated.")
|
||||
return True
|
||||
else:
|
||||
print("Packages update failed.")
|
||||
return False
|
||||
|
||||
packages_for_update = self.get_supported_scripts()
|
||||
|
||||
if len(packages_for_update) == 0:
|
||||
print("No packages for update has been found.")
|
||||
return True
|
||||
else:
|
||||
if self.run_hadcode_tray(packages_for_update):
|
||||
print("Packages: %s - updated." % ', '.join(packages_for_update))
|
||||
return True
|
||||
else:
|
||||
print("Packages: %s - failed." % ', '.join(packages_for_update))
|
||||
return False
|
||||
|
||||
return True
|
||||
|
||||
input_str = sys.stdin.read()
|
||||
packages = [x for x in input_str.split('\n') if x]
|
||||
hook = Hook(packages)
|
||||
|
||||
if not hook.execute():
|
||||
sys.exit('Hook failed')
|
||||
Loading…
Reference in a new issue