From 3d6a13c9416d1362cb3f8e675357127584e2a11e Mon Sep 17 00:00:00 2001 From: Andrew Chadwick Date: Fri, 2 Sep 2016 12:04:25 +0100 Subject: [PATCH] Install as data by default Installing as a Python module proper was problematic, and was causing Zim to ignore the plugin with a lot of installation types. You could not, for example, install to /usr/local if Zim is installed to /usr. The like-named zim.plugins modules effectively shadow each other. The correct fix is to allow Zim, not Python, to manage plugins: Zim also searches $XDG_DATA_DIRS and $XDG_DATA_HOME for 3rd-party plugins. Unfortunately we cannot allow installs into $XDG_DATA_HOME due to the way DBus service activation works. Ref: http://bazaar.launchpad.net/~jaap.karssenberg/zim/pyzim/view/head:/HACKING/Writing_plugins.txt Closes dsboger/zimsearch#2. Also use distutils, because that is normal for a Python extension. It makes sense even if zimsearch is just data files now, although the absolute path requirement does need special handling. Remove NEWS: was blank, and distutils doesn't require it. Remove autotools machinery, and update .gitignore to deal with distutils build clutter. --- .gitignore | 10 +- ChangeLog | 2 + INSTALL | 20 +++- Makefile.am | 9 -- NEWS | 0 autogen.sh | 6 -- configure.ac | 12 --- ....plugins.gnomeshellsearch.provider.ini.in} | 0 ...gins.gnomeshellsearch.provider.service.in} | 2 +- setup.py | 94 +++++++++++++++++++ 10 files changed, 114 insertions(+), 41 deletions(-) delete mode 100644 Makefile.am delete mode 100644 NEWS delete mode 100755 autogen.sh delete mode 100644 configure.ac rename data/{zim.plugins.gnomeshellsearch.provider.ini => zim.plugins.gnomeshellsearch.provider.ini.in} (100%) rename data/{zim.plugins.gnomeshellsearch.provider.service => zim.plugins.gnomeshellsearch.provider.service.in} (58%) create mode 100644 setup.py diff --git a/.gitignore b/.gitignore index 9916995..47b9dca 100644 --- a/.gitignore +++ b/.gitignore @@ -1,12 +1,4 @@ -Makefile -Makefile.in -aclocal.m4 -autom4te.cache/ -autoscan.log -config/ -config.status -config.log -configure /.project /.pydevproject /.settings/ +build diff --git a/ChangeLog b/ChangeLog index 5342949..487e7f9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -2,6 +2,8 @@ ## [Unreleased] [unreleased] ### Changed: +- install: install to /usr/local/share/zim/plugins by default +- build: Started using distutils - docs: Converted documentation to Markdown syntax - core: LaunchSearch only makes sense if not search_all - core: LaunchSearch opens Jump To (Ctrl+J) and not Search (Ctrl+Shift+F) diff --git a/INSTALL b/INSTALL index c2ec010..b0cb01b 100644 --- a/INSTALL +++ b/INSTALL @@ -1,4 +1,16 @@ -./autogen.sh -PYTHON= ./configure -make -make install +It's worth seeing where files will go first: + + python2 ./setup.py --dry-run install + python ./setup.py --dry-run install --prefix=/usr + +When you're happy with the scenario, run the setup script command +without --dry-run. The default installation goes in /usr/local, try +this if you're unsure: + + python2 ./setup.py install + +Due to limitations of the GNOME search provider interface, this plugin +must be installed into $XDG_DATA_DIRS (i.e. /usr/local/share or +/usr/share). The default prefix will do this. You cannot install it +sensibly into $XDG_DATA_HOME ($HOME/.local/share) because DBus service +activation requires an absolute path. diff --git a/Makefile.am b/Makefile.am deleted file mode 100644 index 286af11..0000000 --- a/Makefile.am +++ /dev/null @@ -1,9 +0,0 @@ - -zimpluginsdir = $(pythondir)/zim/plugins/ -zimplugins_PYTHON = src/gnomeshellsearch.py - -dbusservicedir = $(datarootdir)/dbus-1/services/ -dbusservice_DATA = data/zim.plugins.gnomeshellsearch.provider.service - -shellsearchdir = $(datarootdir)/gnome-shell/search-providers/ -shellsearch_DATA = data/zim.plugins.gnomeshellsearch.provider.ini diff --git a/NEWS b/NEWS deleted file mode 100644 index e69de29..0000000 diff --git a/autogen.sh b/autogen.sh deleted file mode 100755 index 1a558ed..0000000 --- a/autogen.sh +++ /dev/null @@ -1,6 +0,0 @@ -#!/usr/bin/sh - -mkdir -p config -aclocal -I config \ -&& automake --gnu --add-missing \ -&& autoconf diff --git a/configure.ac b/configure.ac deleted file mode 100644 index 92ed725..0000000 --- a/configure.ac +++ /dev/null @@ -1,12 +0,0 @@ -AC_PREREQ([2.69]) -AC_INIT([zimsearch], [0.1], [https://github.com/dsboger/zimsearch]) -AC_CONFIG_AUX_DIR(config) - -AC_PROG_INSTALL - -AM_INIT_AUTOMAKE([1.15]) -AM_PATH_PYTHON([2.7]) -# pass PYTHON= to configure, else it will end with python 3 - -AC_CONFIG_FILES([Makefile]) -AC_OUTPUT diff --git a/data/zim.plugins.gnomeshellsearch.provider.ini b/data/zim.plugins.gnomeshellsearch.provider.ini.in similarity index 100% rename from data/zim.plugins.gnomeshellsearch.provider.ini rename to data/zim.plugins.gnomeshellsearch.provider.ini.in diff --git a/data/zim.plugins.gnomeshellsearch.provider.service b/data/zim.plugins.gnomeshellsearch.provider.service.in similarity index 58% rename from data/zim.plugins.gnomeshellsearch.provider.service rename to data/zim.plugins.gnomeshellsearch.provider.service.in index a0f2d0a..8a53164 100644 --- a/data/zim.plugins.gnomeshellsearch.provider.service +++ b/data/zim.plugins.gnomeshellsearch.provider.service.in @@ -1,3 +1,3 @@ [D-BUS Service] Name=net.launchpad.zim.plugins.gnomeshellsearch.provider -Exec=/usr/bin/zim --plugin gnomeshellsearch +Exec=@INSTALLDIR@/bin/zim --plugin gnomeshellsearch diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..c56034d --- /dev/null +++ b/setup.py @@ -0,0 +1,94 @@ +#!/usr/bin/env python2 +# -*- encoding: utf-8 -*- + +from distutils.core import setup +from distutils.command.install_data import install_data +from distutils import log +import os +import sys +import textwrap + + +if not ((2,) < sys.version_info < (3,)): + print("This program requires Python 2.x") + print("Please re-run using 'python2 setup.py [...]'") + sys.exit(1) + + +# Support classes: + +class InstallDataSubst (install_data): + """Standard install_data command, extended for variable substitution + + This recognises input filenames with ".in" filename extensions, and + performs some variable subsitutions on them instead of a regular + copy. Subst'ed output files are written without the extension. + + """ + # All this just because DBUS .service files require an absolute path + + def copy_file(self, infile, outfile, *args, **kwargs): + if not infile.endswith(".in"): + result = install_data.copy_file(self, infile, outfile, + *args, **kwargs) + else: + out_basename = os.path.basename(infile) + (out_basename, _) = os.path.splitext(out_basename) + outfile = os.path.join(outfile, out_basename) + log.info("expanding %s -> %s", infile, outfile) + substs = [ + ("@INSTALLDIR@", self.install_dir), + ] + log.debug("substs: %r", substs) + if not self.dry_run: + in_fp = open(infile, 'r') + if os.path.exists(outfile): + os.unlink(outfile) + out_fp = open(outfile, 'w') + for line in in_fp: + for s, r in substs: + line = line.replace(s, r) + out_fp.write(line) + in_fp.close() + out_fp.close() + result = (outfile, 1) + return result + + +# Script and GNOME search provider installation: + +setup( + name='zimsearch', + version='0.0.0', + description='GNOME integration for Zim', + url='https://github.com/dsboger/zimsearch', + requires=["dbus"], + long_description=textwrap.dedent(""" + Integrates Zim into the GNOME search dialog. + + This plugin provides search results for GNOME Shell. + """).strip(), + author='Davi da Silva Böger', + author_email='dsboger [at] gmail [dot] com', + data_files=[ + ('share/zim/plugins', + ["src/gnomeshellsearch.py"]), + ('share/dbus-1/services', + ["data/zim.plugins.gnomeshellsearch.provider.service.in"]), + ('share/gnome-shell/search-providers', + ["data/zim.plugins.gnomeshellsearch.provider.ini.in"]), + ], + cmdclass={'install_data': InstallDataSubst}, + classifiers=[ + "Development Status :: 3 - Alpha", + "Environment :: X11 Applications :: Gnome", + "Environment :: Plugins", + ("License :: OSI Approved :: " + "GNU General Public License v2 or later (GPLv2+)"), + "Intended Audience :: End Users/Desktop", + "Operating System :: POSIX", + "Programming Language :: Python :: 2", + "Topic :: Desktop Environment", + "Topic :: Utilities", + ] +)