Skip to content

Commit

Permalink
Install as data by default
Browse files Browse the repository at this point in the history
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 #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.
  • Loading branch information
achadwick committed Sep 2, 2016
1 parent fdb5cde commit 3d6a13c
Show file tree
Hide file tree
Showing 10 changed files with 114 additions and 41 deletions.
10 changes: 1 addition & 9 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,12 +1,4 @@
Makefile
Makefile.in
aclocal.m4
autom4te.cache/
autoscan.log
config/
config.status
config.log
configure
/.project
/.pydevproject
/.settings/
build
2 changes: 2 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
20 changes: 16 additions & 4 deletions INSTALL
Original file line number Diff line number Diff line change
@@ -1,4 +1,16 @@
./autogen.sh
PYTHON=<path to python 2> ./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.
9 changes: 0 additions & 9 deletions Makefile.am

This file was deleted.

Empty file removed NEWS
Empty file.
6 changes: 0 additions & 6 deletions autogen.sh

This file was deleted.

12 changes: 0 additions & 12 deletions configure.ac

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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
94 changes: 94 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -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",
]
)

0 comments on commit 3d6a13c

Please sign in to comment.