diff --git a/NOTE.md b/NOTE.md new file mode 100644 index 0000000000000000000000000000000000000000..7cbd6c89c74155145ae27d379cca1aa598e94c61 --- /dev/null +++ b/NOTE.md @@ -0,0 +1,173 @@ +# Install-type mapping + + +## https://www.app-addons.org/ + +Category | Install-type +---------|------------- +GnoMenu Skins | - +VLC Skins | - +XMMS Skins | - +Krita Resources | - +Amarok Themes | - +Knights Themes | - +Yakuake Skins | yakuake_skins +Kdenlive FX | - +ODF Templates | - +MPlayer Themes | - + + +## https://www.compiz-themes.org/ + +Category | Install-type +---------|------------- +Compiz Themes | emerald_themes / compiz_themes +Skydomes | - +Cubecaps | - + + +## https://www.e17-stuff.org/ + +Category | Install-type +---------|------------- +Enlightenment Themes | enlightenment_themes +E17 Entrance Themes | - +E17 Enlightenment Backgrounds | enlightenment_backgrounds +E17 Animated Backgrounds | enlightenment_backgrounds + + +## https://www.free-artwork.org/ + +Category | Install-type +---------|------------- +3D Renderings | - +Stock Images | - +Animations | - +Drawings | - +Cliparts | - +Paintings | - +Artwork Contest | - +Inkscape Templates | - +Scribus Templates | - +Logos | - + + +## https://www.box-look.org/ + +Category | Install-type +---------|------------- +Beryl/Emerald Themes | emerald_themes / beryl_themes +Metacity Window Decorations | themes / metacity_themes +Fluxbox Themes | fluxbox_styles +Openbox Themes | themes / openbox_themes +Pek-WM Themes | pekwm_themes +Ice-WM Themes | icewm_themes +FVWM Themes | - +Window-Maker Themes | - + + +## https://www.beryl-themes.org/ + +Category | Install-type +---------|------------- +Beryl/Emerald Themes | emerald_themes / beryl_themes + + +## https://www.cinnamon-look.org/ + +Category | Install-type +---------|------------- +Cinnamon Themes | themes / cinnamon_themes +GTK3 Themes | themes / gtk3_themes +MDM Themes | - +GNOME Icon Themes | icons +Cinnamon Applets | cinnamon_applets +Cinnamon Desklets | cinnamon_desklets +Cinnamon Extensions | cinnamon_extensions + + +## https://www.trinity-look.org/ + +Category | Install-type +---------|------------- +Wallpapers | wallpapers +KDE 3.x Window Decorations | - +KDE 3.x Themes | - +Kbfx Menu Themes | - +Karamba | - +KDM3 Themes | - +KDE 3 Splash Screens | - + + +## https://www.gnome-look.org/ + +Category | Install-type +---------|------------- +Wallpapers | wallpapers +Fonts | fonts +Mouse Themes | cursors +Metacity Window Decorations | themes / metacity_themes +Nautilus Scripts | nautilus_scripts +GnoMenu Skins | - +GDM Themes | - +GNOME 3.x Shell Themes | themes / gnome_shell_themes +GTK3 Themes | themes / gtk3_themes +GTK2 Themes | themes / gtk2_themes +Icon Themes | icons +Gnome Extensions | gnome_shell_extensions +Gnome Color Schemes | - +Gnome Other | - +Cairo Clock Themes | cairo_clock_themes + + +## https://www.mate-look.org/ + +Category | Install-type +---------|------------- +Mouse Themes | cursors +Metacity Window Decorations | themes / metacity_themes +GDM Themes | - +GNOME Icon Themes | icons +GTK2 Themes | themes / gtk2_themes + + +## https://www.xfce-look.org/ + +Category | Install-type +---------|------------- +Wallpapers | wallpapers +Mouse Themes | cursors +Compiz Themes | emerald_themes / compiz_themes +Beryl/Emerald Themes | emerald_themes / beryl_themes +GTK2 Themes | themes / gtk2_themes +XFCE Icon Themes | icons +XFCE/XFWM Themes | themes / xfwm4_themes + + +## https://www.kde-look.org/ + +Category | Install-type +---------|------------- +Plasma Look'n'Feel | plasma_look_and_feel / plasma5_look_and_feel +Plasma 5 Themes | plasma_desktopthemes / plasma5_desktopthemes +Plasma Widget Styles | - +Aurorae Themes | aurorae_themes +deKorator Themes | dekorator_themes +Kvantum Styles | themes / kvantum_themes +QtCurve Styles | qtcurve +Bespin Themes | - +Plasma Splash Screens | - +SDDM Themes | - +Plasma 5 Widgets | plasma_plasmoids / plasma5_plasmoids +Plasma Color Schemes | color_schemes / plasma_color_schemes +Mouse Cursors | cursors +Emoticons | emoticons +Conky Screenlets | - +Kwin Scripts | kwin_scripts +Kwin Switching Layouts | kwin_tabbox +Dolphin Service Menus | - +Amarok 2.x Scripts | amarok_scripts +Plasma Improvements | - +Plasma Comics | - +Yakuake Skins | yakuake_skins +Wallpapers | wallpapers diff --git a/README.md b/README.md index 75964d2f15f153b395f890a359957987183de54a..a09357bc3c6ff4e1ed05f1c886239ec263ca8612 100644 --- a/README.md +++ b/README.md @@ -1 +1,146 @@ -# xdgurl \ No newline at end of file +# xdgurl + +An install helper program for desktop stuff. + +Copyright: 2016, Akira Ohgaki + +License: GPL-3+ + + +## How to install + +For Ubuntu/Debian system, +you can use "install.sh" in the project to install the program. + + $ sh install.sh + +And you can use "uninstall.sh" to uninstall the program. + + $ sh uninstall.sh + + +## How to use + +#### From web browser + +Open XDG-URL by click a links, or type XDG-URL in browser's address bar. + +In firefox, +you can get a program selection window when first time to open XDG-URL, +and you can choose "xdgurl" as custom URL handler. + +If you can not get a program selection window, +you need set the xdgurl program as custom URL handler for xdg:// scheme in browser's settings. + +#### From command-line terminal + +Execute xdgurl program with argument XDG-URL. + + $ xdgurl "XDG-URL" + + +## XDG-URL + +XDG-URL is a custom URL that represent the installation method for desktop stuff. + + [scheme]://[command]?[query string] + + For example: + xdg://install?url=http%3A%2F%2Fexample.com%2Ficons.tar.gz&type=icons + +#### Scheme + +* xdg +* xdgs + +"xdgs" scheme is the same of the xdg scheme for now, +it's a reserved name for secure protocol in the future. + +#### Command + +* download +* install + +Command "download" will download the file from specified URL to local destination of specified install-type. + +Command "install" will make file downloading and trigger installation process. + +#### Query string + +XDG-URL's query string is an option of command. + +*All query string values should be urlencoded.* + +**url** = File URL of desktop stuff + +Must be set. + +**type** = Install-type + +Optional. +Default is "downloads". + +Available install-type: + +Install-type | Local destination +-------------|------------------ +downloads | ~/Downloads +documents | ~/Documents +pictures | ~/Pictures +music | ~/Music +videos | ~/Videos +wallpapers | ~/.local/share/wallpapers +fonts | ~/.fonts +cursors | ~/.icons +icons | ~/.local/share/icons +emoticons | ~/.local/share/emoticons +themes | ~/.themes +emerald_themes | ~/.emerald/themes +enlightenment_themes | ~/.e/e/themes +enlightenment_backgrounds | ~/.e/e/backgrounds +fluxbox_styles | ~/.fluxbox/styles +pekwm_themes | ~/.pekwm/themes +icewm_themes | ~/.icewm/themes +plasma_plasmoids | ~/.local/share/plasma/plasmoids +plasma_look_and_feel | ~/.local/share/plasma/look-and-feel +plasma_desktopthemes | ~/.local/share/plasma/desktoptheme +kwin_effects | ~/.local/share/kwin/effects +kwin_scripts | ~/.local/share/kwin/scripts +kwin_tabbox | ~/.local/share/kwin/tabbox +aurorae_themes | ~/.local/share/aurorae/themes +dekorator_themes | ~/.local/share/deKorator/themes +qtcurve | ~/.local/share/QtCurve +color_schemes | ~/.local/share/color-schemes +gnome_shell_extensions | ~/.local/share/gnome-shell/extensions +cinnamon_applets | ~/.local/share/cinnamon/applets +cinnamon_desklets | ~/.local/share/cinnamon/desklets +cinnamon_extensions | ~/.local/share/cinnamon/extensions +nautilus_scripts | ~/.local/share/nautilus/scripts +amarok_scripts | ~/.kde/share/apps/amarok/scripts +yakuake_skins | ~/.kde/share/apps/yakuake/skins +cairo_clock_themes | ~/.cairo-clock/themes + +Available alias name of the install-type: + +Alias | Install-type +------|------------- +gnome_shell_themes | themes +cinnamon_themes | themes +gtk2_themes | themes +gtk3_themes | themes +metacity_themes | themes +xfwm4_themes | themes +openbox_themes | themes +kvantum_themes | themes +compiz_themes | emerald_themes +beryl_themes | emerald_themes +plasma4_plasmoids | plasma_plasmoids +plasma5_plasmoids | plasma_plasmoids +plasma5_look_and_feel | plasma_look_and_feel +plasma5_desktopthemes | plasma_desktopthemes +plasma_color_schemes | color_schemes + +**filename** = Alternative file name + +Optional. +This option is useful if the download URL does not represent the file name. diff --git a/install.sh b/install.sh new file mode 100644 index 0000000000000000000000000000000000000000..bbc5ced13769c3be50c204ad6bc42c2070ea793f --- /dev/null +++ b/install.sh @@ -0,0 +1,12 @@ +#!/bin/sh + +# Install + +cd `dirname $0` + +sudo apt-get install python +sudo apt-get install python-tk +sudo apt-get install desktop-file-utils +sudo install -D -m 755 src/xdgurl.py /usr/bin/xdgurl +sudo install -D -m 644 src/xdgurl.desktop /usr/share/applications/xdgurl.desktop +sudo update-desktop-database -q /usr/share/applications diff --git a/pkg/arch/PKGBUILD b/pkg/arch/PKGBUILD new file mode 100644 index 0000000000000000000000000000000000000000..cc8d4d1a4f0584a5d3dbd122770cc9e8029e5e4a --- /dev/null +++ b/pkg/arch/PKGBUILD @@ -0,0 +1,21 @@ +# Maintainer: Akira Ohgaki <akiraohgaki@gmail.com> + +pkgname=xdgurl +pkgver=1.0.0 +pkgrel=1 +pkgdesc="An install helper program for desktop stuff." +arch=('i686' 'x86_64') +url="https://github.com/xdgurl/xdgurl" +license=('GPL3') +depends=('tk') +#source=("$pkgname-$pkgver.tar.gz") +source=("$pkgname.tar.gz") +md5sums=() #autofill using updpkgsums + +package() { + #cd "$pkgname-$pkgver" + cd $pkgname + + install -D -m 755 "src/$pkgname.py" "$pkgdir/usr/bin/$pkgname" + install -D -m 644 "src/$pkgname.desktop" "$pkgdir/usr/share/applications/$pkgname.desktop" +} diff --git a/pkg/arch/build.sh b/pkg/arch/build.sh new file mode 100644 index 0000000000000000000000000000000000000000..fb714002d55b8b03b8292daa03dd2709163920e2 --- /dev/null +++ b/pkg/arch/build.sh @@ -0,0 +1,8 @@ +#!/bin/sh + +cd `dirname $0` + +tar -czvf /tmp/xdgurl.tar.gz ../../../xdgurl +mv /tmp/xdgurl.tar.gz ./ +updpkgsums +makepkg -s diff --git a/pkg/fedora/build.sh b/pkg/fedora/build.sh new file mode 100644 index 0000000000000000000000000000000000000000..114224662d012d1d493742cde2bcee89f8718ae1 --- /dev/null +++ b/pkg/fedora/build.sh @@ -0,0 +1,9 @@ +#!/bin/sh + +cd `dirname $0` + +mkdir -p ~/rpmbuild/BUILD +mkdir -p ~/rpmbuild/SPECS +cp -r ../../../xdgurl ~/rpmbuild/BUILD/ +cp xdgurl.spec ~/rpmbuild/SPECS/ +rpmbuild -bb ~/rpmbuild/SPECS/xdgurl.spec diff --git a/pkg/fedora/xdgurl.spec b/pkg/fedora/xdgurl.spec new file mode 100644 index 0000000000000000000000000000000000000000..6f3408e332a9d54f008e5e86dfd23cc14c9e7031 --- /dev/null +++ b/pkg/fedora/xdgurl.spec @@ -0,0 +1,27 @@ +Summary: An install helper program for desktop stuff +Name: xdgurl +Version: 1.0.0 +Release: 1%{?dist} +License: GPLv3+ +Group: Applications/Internet +URL: https://github.com/xdgurl/xdgurl + +Source0: xdgurl.tar.gz + +Requires: tkinter, python3-tkinter + +%description +An install helper program for desktop stuff. + +%build +install -D -m 755 xdgurl/src/xdgurl.py $RPM_BUILD_ROOT/%{_bindir}/xdgurl +install -D -m 644 xdgurl/src/xdgurl.desktop $RPM_BUILD_ROOT/%{_datadir}/applications/xdgurl.desktop + +%files +%defattr(-,root,root) +%{_bindir}/xdgurl +%{_datadir}/applications/xdgurl.desktop + +%changelog +* Wed Jul 06 2016 Akira Ohgaki <akiraohgaki@gmail.com> - 1.0.0-1 +- Initial release diff --git a/pkg/ubuntu/build.sh b/pkg/ubuntu/build.sh new file mode 100644 index 0000000000000000000000000000000000000000..211236a5afdd6eb48fae2695b65e0b11178588c4 --- /dev/null +++ b/pkg/ubuntu/build.sh @@ -0,0 +1,6 @@ +#!/bin/sh + +cd `dirname $0` + +debuild -uc -us -b +#fakeroot debian/rules clean diff --git a/pkg/ubuntu/debian/changelog b/pkg/ubuntu/debian/changelog new file mode 100644 index 0000000000000000000000000000000000000000..5ec1b0af6b3f70d14c72520ad8df9da0b4e0e521 --- /dev/null +++ b/pkg/ubuntu/debian/changelog @@ -0,0 +1,5 @@ +xdgurl (1.0.0-0ubuntu1) xenial; urgency=low + + * Initial release + + -- Akira Ohgaki <akiraohgaki@gmail.com> Wed, 06 Jul 2016 20:23:29 +0000 diff --git a/pkg/ubuntu/debian/compat b/pkg/ubuntu/debian/compat new file mode 100644 index 0000000000000000000000000000000000000000..ec635144f60048986bc560c5576355344005e6e7 --- /dev/null +++ b/pkg/ubuntu/debian/compat @@ -0,0 +1 @@ +9 diff --git a/pkg/ubuntu/debian/control b/pkg/ubuntu/debian/control new file mode 100644 index 0000000000000000000000000000000000000000..68a1d227a8200f93b03a4cdabd1a5422b5dc9bf1 --- /dev/null +++ b/pkg/ubuntu/debian/control @@ -0,0 +1,12 @@ +Source: xdgurl +Section: web +Priority: optional +Maintainer: Akira Ohgaki <akiraohgaki@gmail.com> +Build-Depends: build-essential (>= 11), devscripts (>= 2.14), debhelper (>= 9), fakeroot (>= 1.20) +Standards-Version: 3.9.4 + +Package: xdgurl +Architecture: any +Depends: ${shlibs:Depends}, ${misc:Depends}, python-tk (>= 2.7.0), python3-tk (>= 3.2.0) +Description: xdgurl + An install helper program for desktop stuff. diff --git a/pkg/ubuntu/debian/copyright b/pkg/ubuntu/debian/copyright new file mode 100644 index 0000000000000000000000000000000000000000..5e4c2739d8fd9bf4e1d75d27646f8441c8757f7b --- /dev/null +++ b/pkg/ubuntu/debian/copyright @@ -0,0 +1,10 @@ +Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ +Upstream-Name: xdgurl +Upstream-Contact: Akira Ohgaki <akiraohgaki@gmail.com> +Source: https://github.com/xdgurl/xdgurl + +Files: * +Copyright: 2016, Akira Ohgaki +License: GPL-3+ + On Debian systems, the full text of the GNU General Public License version 3 + can be found in the `/usr/share/common-licenses/GPL-3' file. diff --git a/pkg/ubuntu/debian/rules b/pkg/ubuntu/debian/rules new file mode 100755 index 0000000000000000000000000000000000000000..3ac7de5e4ae5716041e1e7ed6decd80ec4e69578 --- /dev/null +++ b/pkg/ubuntu/debian/rules @@ -0,0 +1,11 @@ +#!/usr/bin/make -f + +%: + dh $@ + +override_dh_auto_build: + install -D -m 755 ../../src/xdgurl.py usr/bin/xdgurl + install -D -m 644 ../../src/xdgurl.desktop usr/share/applications/xdgurl.desktop + +override_dh_shlibdeps: + # ignore diff --git a/pkg/ubuntu/debian/xdgurl.install b/pkg/ubuntu/debian/xdgurl.install new file mode 100644 index 0000000000000000000000000000000000000000..dcca62ee52466ef8bd412092cf039b29539b6a9a --- /dev/null +++ b/pkg/ubuntu/debian/xdgurl.install @@ -0,0 +1,2 @@ +usr/bin/xdgurl +usr/share/applications/xdgurl.desktop diff --git a/src/xdgurl.desktop b/src/xdgurl.desktop new file mode 100644 index 0000000000000000000000000000000000000000..688ca021c06b73247aa4f47294fc0e66585d6e8f --- /dev/null +++ b/src/xdgurl.desktop @@ -0,0 +1,8 @@ +[Desktop Entry] +Name=xdgurl +Exec=xdgurl %u +Type=Application +Terminal=false +NoDisplay=true +Categories=Network;Utility; +MimeType=x-scheme-handler/xdg;x-scheme-handler/xdgs; diff --git a/src/xdgurl.py b/src/xdgurl.py new file mode 100644 index 0000000000000000000000000000000000000000..d09b7440cd0fd71158c26a584ba396b0c2ec8530 --- /dev/null +++ b/src/xdgurl.py @@ -0,0 +1,413 @@ +#!/usr/bin/env python + +"""xdgurl +An install helper program for desktop stuff. + +Copyright: 2016, Akira Ohgaki +License: GPL-3+ + +https://github.com/xdgurl/xdgurl +""" + +import sys +import os +import shutil +import json +import tempfile +import mimetypes +import subprocess +import argparse + +if sys.version_info.major >= 3: + import urllib.request + import urllib.error + import urllib.parse + import tkinter + import tkinter.messagebox +else: + import urllib + import urlparse + import Tkinter + import tkMessageBox + +class XdgUrl: + """Core class of xdgurl""" + + def __init__(self, xdg_url=''): + self.xdg_url = xdg_url + self.meta = self.parse() + + self.temp_dir = tempfile.gettempdir() + self.home_dir = os.path.expanduser('~') + #self.config_dir = os.path.join(self.home_dir, '.config', 'xdgurl') + self.data_dir = os.path.join(self.home_dir, '.local', 'share') + self.kde_data_dir = os.path.join(self.home_dir, '.kde', 'share') + + #self.config = {} + + self.destinations = { + 'downloads': os.path.join(self.home_dir, 'Downloads'), + 'documents': os.path.join(self.home_dir, 'Documents'), + 'pictures': os.path.join(self.home_dir, 'Pictures'), + 'music': os.path.join(self.home_dir, 'Music'), + 'videos': os.path.join(self.home_dir, 'Videos'), + 'wallpapers': os.path.join(self.data_dir, 'wallpapers'), + 'fonts': os.path.join(self.home_dir, '.fonts'), + 'cursors': os.path.join(self.home_dir, '.icons'), + 'icons': os.path.join(self.data_dir, 'icons'), + 'emoticons': os.path.join(self.data_dir, 'emoticons'), + 'themes': os.path.join(self.home_dir, '.themes'), + 'emerald_themes': os.path.join(self.home_dir, '.emerald', 'themes'), + 'enlightenment_themes': os.path.join(self.home_dir, '.e', 'e', 'themes'), + 'enlightenment_backgrounds': os.path.join(self.home_dir, '.e', 'e', 'backgrounds'), + 'fluxbox_styles': os.path.join(self.home_dir, '.fluxbox', 'styles'), + 'pekwm_themes': os.path.join(self.home_dir, '.pekwm', 'themes'), + 'icewm_themes': os.path.join(self.home_dir, '.icewm', 'themes'), + 'plasma_plasmoids': os.path.join(self.data_dir, 'plasma', 'plasmoids'), + 'plasma_look_and_feel': os.path.join(self.data_dir, 'plasma', 'look-and-feel'), + 'plasma_desktopthemes': os.path.join(self.data_dir, 'plasma', 'desktoptheme'), + 'kwin_effects': os.path.join(self.data_dir, 'kwin', 'effects'), + 'kwin_scripts': os.path.join(self.data_dir, 'kwin', 'scripts'), + 'kwin_tabbox': os.path.join(self.data_dir, 'kwin', 'tabbox'), + 'aurorae_themes': os.path.join(self.data_dir, 'aurorae', 'themes'), + 'dekorator_themes': os.path.join(self.data_dir, 'deKorator', 'themes'), + 'qtcurve': os.path.join(self.data_dir, 'QtCurve'), + 'color_schemes': os.path.join(self.data_dir, 'color-schemes'), + 'gnome_shell_extensions': os.path.join(self.data_dir, 'gnome-shell', 'extensions'), + 'cinnamon_applets': os.path.join(self.data_dir, 'cinnamon', 'applets'), + 'cinnamon_desklets': os.path.join(self.data_dir, 'cinnamon', 'desklets'), + 'cinnamon_extensions': os.path.join(self.data_dir, 'cinnamon', 'extensions'), + 'nautilus_scripts': os.path.join(self.data_dir, 'nautilus', 'scripts'), + 'amarok_scripts': os.path.join(self.kde_data_dir, 'apps', 'amarok', 'scripts'), + 'yakuake_skins': os.path.join(self.kde_data_dir, 'apps', 'yakuake', 'skins'), + 'cairo_clock_themes': os.path.join(self.home_dir, '.cairo-clock', 'themes') + } + self.destinations_alias = { + 'gnome_shell_themes': self.destinations['themes'], + 'cinnamon_themes': self.destinations['themes'], + 'gtk2_themes': self.destinations['themes'], + 'gtk3_themes': self.destinations['themes'], + 'metacity_themes': self.destinations['themes'], + 'xfwm4_themes': self.destinations['themes'], + 'openbox_themes': self.destinations['themes'], + 'kvantum_themes': self.destinations['themes'], + 'compiz_themes': self.destinations['emerald_themes'], + 'beryl_themes': self.destinations['emerald_themes'], + 'plasma4_plasmoids': self.destinations['plasma_plasmoids'], + 'plasma5_plasmoids': self.destinations['plasma_plasmoids'], + 'plasma5_look_and_feel': self.destinations['plasma_look_and_feel'], + 'plasma5_desktopthemes': self.destinations['plasma_desktopthemes'], + 'plasma_color_schemes': self.destinations['color_schemes'] + } + self.destinations.update(self.destinations_alias) + + self.archive_types = { + 'tar': [ + 'application/x-tar', + 'application/x-gzip', + 'application/gzip', + 'application/x-bzip', + 'application/x-bzip2', + 'application/x-xz', + 'application/x-lzma', + 'application/x-lzip', + 'application/x-compressed-tar', + 'application/x-bzip-compressed-tar', + 'application/x-bzip2-compressed-tar', + 'application/x-xz-compressed-tar', + 'application/x-lzma-compressed-tar', + 'application/x-lzip-compressed-tar' + ], + 'zip': ['application/zip'], + '7z': ['application/x-7z-compressed'], + 'rar': [ + 'application/x-rar', + 'application/x-rar-compressed' + ] + } + + #self.config.update(self.read_config('config')) + #self.destinations.update(self.read_config('destinations')) + + def read_config(self, name): + path = os.path.join(self.config_dir, name + '.json') + data = {} + if os.path.isfile(path): + f = open(path, 'r') + data = json.load(f) + f.close() + return data + + def write_config(self, name, data): + if not os.path.isdir(self.config_dir): + os.makedirs(self.config_dir) + path = os.path.join(self.config_dir, name + '.json') + f = open(path, 'w') + json.dump(data, f) + f.close() + + def parse(self): + meta = { + 'command': 'download', + 'url': '', + 'type': 'downloads', + 'filename': '' + } + + if sys.version_info.major >= 3: + parse_result = urllib.parse.urlparse(self.xdg_url) + query = urllib.parse.parse_qs(parse_result.query) + else: + parse_result = urlparse.urlparse(self.xdg_url) + query = urlparse.parse_qs(parse_result.query) + + if parse_result.netloc: + meta['command'] = parse_result.netloc + + if 'url' in query and query['url'][0]: + if sys.version_info.major >= 3: + meta['url'] = urllib.parse.unquote(query['url'][0]) + else: + meta['url'] = urllib.unquote(query['url'][0]) + + if 'type' in query and query['type'][0]: + if sys.version_info.major >= 3: + meta['type'] = urllib.parse.unquote(query['type'][0]) + else: + meta['type'] = urllib.unquote(query['type'][0]) + + if 'filename' in query and query['filename'][0]: + if sys.version_info.major >= 3: + meta['filename'] = urllib.parse.unquote(query['filename'][0]).split('?')[0] + else: + meta['filename'] = urllib.unquote(query['filename'][0]).split('?')[0] + + if meta['url'] and not meta['filename']: + meta['filename'] = os.path.basename(meta['url']).split('?')[0] + + return meta + + """ + def detect_desktop_environment(self): + desktop_environment = 'unknown' + if os.environ.get('KDE_FULL_SESSION') == 'true': + desktop_environment = 'kde' + elif os.environ.get('GNOME_DESKTOP_SESSION_ID'): + desktop_environment = 'gnome' + return desktop_environment + """ + + def install_plasmapkg(self, path, type='plasmoid'): + status = subprocess.call(['plasmapkg2', '-t', type, '-i', path]) + if status == 0: + return True + return False + + def uncompress_archive(self, path, target_dir): + (mimetype, encoding) = mimetypes.guess_type(path) + status = None + + if mimetype in self.archive_types['tar']: + status = subprocess.call(['tar', '-xf', path, '-C', target_dir]) + elif mimetype in self.archive_types['zip']: + status = subprocess.call(['unzip', '-o', path, '-d', target_dir]) + elif mimetype in self.archive_types['7z']: + # No space between -o and directory + status = subprocess.call(['7z', 'x', path, '-o' + target_dir]) + elif mimetype in self.archive_types['rar']: + status = subprocess.call(['unrar', 'e', path, target_dir]) + + if status == 0: + return True + return False + + def download(self): + url = self.meta['url'] + type = self.meta['type'] + filename = self.meta['filename'] + destination = self.destinations[type] + + temp_path = os.path.join(self.temp_dir, filename) + path = os.path.join(destination, filename) + + print('Retrieving a file from ' + url) + if sys.version_info.major >= 3: + urllib.request.urlretrieve(url, temp_path) + else: + urllib.urlretrieve(url, temp_path) + + print('Creating a directory ' + destination) + if not os.path.isdir(destination): + os.makedirs(destination) + + print('Saving a file to ' + path) + shutil.move(temp_path, path) + + print('Done') + + def install(self): + url = self.meta['url'] + type = self.meta['type'] + filename = self.meta['filename'] + destination = self.destinations[type] + + temp_path = os.path.join(self.temp_dir, filename) + path = os.path.join(destination, filename) + + print('Retrieving a file from ' + url) + if sys.version_info.major >= 3: + urllib.request.urlretrieve(url, temp_path) + else: + urllib.urlretrieve(url, temp_path) + + print('Creating a directory ' + destination) + if not os.path.isdir(destination): + os.makedirs(destination) + + print('Installing') + if (type in ['plasma_plasmoids', 'plasma4_plasmoids', 'plasma5_plasmoids'] + and self.install_plasmapkg(temp_path, 'plasmoid')): + print('The plasmoid has been installed') + os.remove(temp_path) + elif (type in ['plasma_look_and_feel', 'plasma5_look_and_feel'] + and self.install_plasmapkg(temp_path, 'lookandfeel')): + print('The plasma look and feel has been installed') + os.remove(temp_path) + elif (type in ['plasma_desktopthemes', 'plasma5_desktopthemes'] + and self.install_plasmapkg(temp_path, 'theme')): + print('The plasma desktop theme has been installed') + os.remove(temp_path) + elif (type == 'kwin_effects' + and self.install_plasmapkg(temp_path, 'kwineffect')): + print('The KWin effect has been installed') + os.remove(temp_path) + elif (type == 'kwin_scripts' + and self.install_plasmapkg(temp_path, 'kwinscript')): + print('The KWin script has been installed') + os.remove(temp_path) + elif (type == 'kwin_tabbox' + and self.install_plasmapkg(temp_path, 'windowswitcher')): + print('The KWin window switcher has been installed') + os.remove(temp_path) + elif self.uncompress_archive(temp_path, destination): + print('The archive file has been uncompressed into ' + destination) + os.remove(temp_path) + else: + print('Saving a file to ' + path) + shutil.move(temp_path, path) + + print('Done') + + def execute(self): + if (self.meta['command'] in ['download', 'install'] + and self.meta['url'] + and self.meta['type'] in self.destinations + and self.meta['filename']): + if self.meta['command'] == 'download': + self.download() + elif self.meta['command'] == 'install': + self.install() + else: + raise Exception('Incorrect XDG-URL ' + self.xdg_url) + +''' +class XdgUrlApp(Tkinter.Frame): + """Confirmation dialog for xdgurl""" + + def __init__(self, master=None, core=None): + Tkinter.Frame.__init__(self, master) + self.pack() + self.core = core + self.master.title('xdgurl') + self.master.geometry('300x120') + self.create_widget() + + def create_widget(self): + execute_text = 'Download' + if self.core.meta['command'] == 'install': + execute_text = 'Install' + + info_label = Tkinter.Label(self, text=execute_text + ': ' + self.core.meta['filename']) + info_label.pack(padx=10, pady=5, anchor=Tkinter.W) + + message_label = Tkinter.Label(self, text='Do you want to continue?') + message_label.pack(padx=10, pady=5, anchor=Tkinter.W) + + execute_button = Tkinter.Button(self, text=execute_text, command=self.execute) + execute_button.pack(padx=5, pady=10, side=Tkinter.RIGHT) + + quit_button = Tkinter.Button(self, text='Cancel', command=self.quit) + quit_button.pack(padx=5, pady=10, side=Tkinter.RIGHT) + + def execute(self): + self.core.execute() + sys.exit() + + def quit(self): + sys.exit() +''' + +def main(): + program = 'xdgurl' + version = '1.0.0' + + parser = argparse.ArgumentParser( + prog=program, + description='An install helper program for desktop stuff', + epilog='Check more information on https://github.com/xdgurl/xdgurl' + ) + parser.add_argument( + '-v', '--version', + action='version', + version='%(prog)s ' + version + ) + parser.add_argument('xdg_url', help='XDG-URL') + args = parser.parse_args() + + if args.xdg_url: + """ + core = XdgUrl(args.xdg_url) + window = Tkinter.Tk() + app = XdgUrlApp(window, core) + app.mainloop() + """ + + core = XdgUrl(args.xdg_url) + if sys.version_info.major >= 3: + window = tkinter.Tk() + else: + window = Tkinter.Tk() + window.withdraw() + + execute_text = 'Download' + if core.meta['command'] == 'install': + execute_text = 'Install' + info_text = execute_text + ': ' + core.meta['filename'] + '\nFrom: ' + core.meta['url'] + + print(info_text) + if sys.version_info.major >= 3: + confirm = tkinter.messagebox.askyesno(program, info_text + '\n\nDo you want to continue?') + else: + confirm = tkMessageBox.askyesno(program, info_text + '\n\nDo you want to continue?') + + if confirm: + try: + core.execute(); + except Exception as e: + message = execute_text + ' failed\n' + str(e) + print(message) + if sys.version_info.major >= 3: + tkinter.messagebox.showerror(program, info_text + '\n\n' + message) + else: + tkMessageBox.showerror(program, info_text + '\n\n' + message) + else: + message = execute_text + ' finished' + print(message) + if sys.version_info.major >= 3: + tkinter.messagebox.showinfo(program, info_text + '\n\n' + message) + else: + tkMessageBox.showinfo(program, info_text + '\n\n' + message) + sys.exit() + +if __name__ == '__main__': + main() diff --git a/uninstall.sh b/uninstall.sh new file mode 100644 index 0000000000000000000000000000000000000000..0d46bfd7306ee21df066b259fc1d6f93b1d7141a --- /dev/null +++ b/uninstall.sh @@ -0,0 +1,7 @@ +#!/bin/sh + +# Uninstall + +sudo rm /usr/bin/xdgurl +sudo rm /usr/share/applications/xdgurl.desktop +sudo update-desktop-database -q /usr/share/applications