diff options
author | Marko Kreen | 2011-09-05 19:40:33 +0000 |
---|---|---|
committer | Marko Kreen | 2011-09-05 19:40:33 +0000 |
commit | 091d5b3ffbb5e2cee31dc5e7006da6be2e623a6b (patch) | |
tree | 4a32d7889ead6e81aad9a067076e1708e4888672 | |
parent | 57cf4ebdcbfdae907e3da7e76ac241ac0f550f90 (diff) |
Move install logic from Makefile to setup_skytools.py
-rw-r--r-- | Makefile | 33 | ||||
-rwxr-xr-x | setup_skytools.py | 86 |
2 files changed, 68 insertions, 51 deletions
@@ -7,20 +7,6 @@ pyver = $(shell $(PYTHON) -V 2>&1 | sed 's/^[^ ]* \([0-9]*\.[0-9]*\).*/\1/') SUBDIRS = sql doc -#SCRIPTS = python/londiste.py python/qadmin.py python/pgqadm.py python/walmgr.py \ -# scripts/queue_loader.py scripts/queue_mover.py scripts/queue_splitter.py \ -# scripts/scriptmgr.py scripts/skytools_upgrade.py - -# add suffix -SFX_SCRIPTS = python/londiste.py python/walmgr.py scripts/scriptmgr.py \ - scripts/queue_splitter.py scripts/queue_mover.py -# dont add -NOSFX_SCRIPTS = python/qadmin.py - -SCRIPT_SUFFIX = $(SUFFIX) - -SQLDIR = $(prefix)/share/skytools$(SUFFIX) - # modules that use doctest for regtests DOCTESTMODS = skytools.quoting skytools.parsing skytools.timeutil \ skytools.sqltools skytools.querybuilder skytools.natsort \ @@ -66,26 +52,9 @@ python-install: config.mak sub-all rm -rf build $(PYTHON) setup_pkgloader.py install --prefix=$(prefix) --root=$(DESTDIR)/ $(BROKEN_PYTHON) find build -name 'pkgloader*' | xargs rm - $(PYTHON) setup_skytools.py install --prefix=$(prefix) --root=$(DESTDIR)/ \ - --install-lib=$(prefix)/lib/python$(pyver)/$(SITEDIR)/skytools-3.0 \ - --record=tmp_files.lst - for s in $(SFX_SCRIPTS); do \ - exe=`echo $$s|sed -e 's!.*/!!' -e 's/[.]py//'`; \ - install $$s $(DESTDIR)/$(bindir)/$${exe}$(SCRIPT_SUFFIX) || exit 1; \ - done - for s in $(NOSFX_SCRIPTS); do \ - exe=`echo $$s|sed -e 's!.*/!!' -e 's/[.]py//'`; \ - install $$s $(DESTDIR)/$(bindir)/$$exe || exit 1; \ - done + $(PYTHON) setup_skytools.py install --prefix=$(prefix) --root=$(DESTDIR)/ $(BROKEN_PYTHON) $(MAKE) -C doc DESTDIR=$(DESTDIR) install -python-install python-all: python/skytools/installer_config.py -python/skytools/installer_config.py: python/skytools/installer_config.py.in config.mak - sed -e 's!@SQLDIR@!$(SQLDIR)!g' \ - -e 's!@SKYLOG@!$(SKYLOG)!g' \ - -e 's!@PACKAGE_VERSION@!$(PACKAGE_VERSION)!g' \ - $< > $@ - realclean: distclean $(MAKE) -C doc $@ $(MAKE) distclean diff --git a/setup_skytools.py b/setup_skytools.py index bc9bedb5..966d12b2 100755 --- a/setup_skytools.py +++ b/setup_skytools.py @@ -1,38 +1,84 @@ #! /usr/bin/env python -# this script does not perform full installation, -# it is meant for use from Makefile +# this script installs only Python modules, +# scripts and sql files are installed from makefile import sys, os.path, re from distutils.core import setup from distutils.extension import Extension - -# check if configure has run -if not os.path.isfile('config.mak'): - print "please run ./configure && make first" - print "Note: setup.py is supposed to be run from Makefile" - sys.exit(1) +from distutils.command.install import install +from subprocess import Popen # load version buf = open("configure.ac","r").read(256) m = re.search("AC_INIT[(][^,]*,\s+([^)]*)[)]", buf) ac_ver = m.group(1) -def getvar(name): - cf = open('config.mak').read() - m = re.search(r'^%s\s*=\s*(.*)' % name, cf, re.M) - return m.group(1).strip() - -sfx = getvar('SUFFIX') +sfx_scripts = [ + 'python/londiste.py', + 'python/walmgr.py', + 'scripts/scriptmgr.py', + 'scripts/queue_splitter.py', + 'scripts/queue_mover.py', +] +nosfx_scripts = [ + 'python/qadmin.py', +] -share_dup_files = [ +sql_files = [ 'sql/pgq/pgq.sql', 'sql/londiste/londiste.sql', 'sql/pgq_ext/pgq_ext.sql', 'sql/pgq_node/pgq_node.sql', + #'sql/txid/txid.sql', ] -if os.path.isfile('sql/txid/txid.sql'): - share_dup_files.append('sql/txid/txid.sql') +for fn in sql_files: + if not os.path.isfile(fn): + f = open(fn, 'w') + wd = os.path.dirname(fn) + cmd = [sys.executable, '../../scripts/catsql.py', 'structure/install.sql'] + p = Popen(cmd, stdout=f, cwd = wd) + p.communicate() + if p.returncode != 0: + raise Exception('catsql failed') + +def fixscript(fn, dstdir, sfx): + fn = os.path.basename(fn) + fn2 = fn.replace('.py', sfx) + print("Renaming %s -> %s" % (fn, fn2)) + dfn = os.path.join(dstdir, fn) + dfn2 = os.path.join(dstdir, fn2) + os.rename(dfn, dfn2) + +class sk3_install(install): + user_options = install.user_options + [ + ('script-suffix=', None, 'add suffix to scripts'), + ('sk3-subdir', None, 'install modules into "skytools-3.0" subdir') + ] + boolean_options = ['sk3-subdir'] + sk3_subdir = '' + script_suffix = '' + + def run(self): + fn = 'python/skytools/installer_config.py' + cf = open(fn + '.in', 'r').read() + cf = cf.replace('@SQLDIR@', self.prefix + 'share/skytools3') + cf = cf.replace('@PACKAGE_VERSION@', ac_ver) + cf = cf.replace('@SKYLOG@', '1') + open(fn, 'w').write(cf) + + if self.sk3_subdir: + subdir = 'skytools-3.0' + self.install_lib = os.path.join(self.install_lib, subdir) + self.install_purelib = os.path.join(self.install_purelib, subdir) + self.install_platlib = os.path.join(self.install_platlib, subdir) + + install.run(self) + + for sfn in sfx_scripts: + fixscript(sfn, self.install_scripts, self.script_suffix) + for sfn in nosfx_scripts: + fixscript(sfn, self.install_scripts, '') # run actual setup setup( @@ -45,11 +91,13 @@ setup( package_dir = {'': 'python'}, packages = ['skytools', 'londiste', 'londiste.handlers', 'pgq', 'pgq.cascade'], data_files = [ - ('share/doc/skytools%s/conf' % sfx, [ + ('share/doc/skytools3/conf', [ 'python/conf/wal-master.ini', 'python/conf/wal-slave.ini', ]), - ('share/skytools' + sfx, share_dup_files)], + ('share/skytools3', sql_files)], ext_modules=[Extension("skytools._cquoting", ['python/modules/cquoting.c'])], + scripts = sfx_scripts + nosfx_scripts, + cmdclass = { 'install': sk3_install }, ) |