Permalink
Browse files

Merge branch 'devel'

  • Loading branch information...
2 parents 23cf99c + 3f93369 commit 71951c9409c276a2bf94bc085adb36a527e7b22f @dvarrazzo committed Jul 11, 2012
View
13 CHANGES
@@ -3,11 +3,22 @@
PGXN Client changes log
-----------------------
+pgxnclient 1.1
+==============
+
+- Dropped support for Python 2.4.
+- ``sudo`` is not invoked automatically: the ``--sudo`` option must be
+ specified if the user has not permission to write into PostgreSQL's libdir
+ (ticket #13). The ``--sudo`` option can also be invoked without argument.
+- Make sure the same ``pg_config`` is used both by the current user and by
+ sudo.
+
+
pgxnclient 1.0.3
================
- Can deal with extensions whose ``Makefile`` is created by ``configure``
- and with makefile not in the package root. Patch provided by Hithoshi
+ and with makefile not in the package root. Patch provided by Hitoshi
Harada (ticket #12).
View
@@ -1,4 +1,4 @@
-Copyright (c) 2011, Daniele Varrazzo <daniele.varrazzo@gmail.com>
+Copyright (c) 2011-2012, Daniele Varrazzo <daniele.varrazzo@gmail.com>
All rights reserved.
Redistribution and use in source and binary forms, with or without
View
@@ -1,6 +1,6 @@
# pgxnclient Makefile
#
-# Copyright (C) 2011 Daniele Varrazzo
+# Copyright (C) 2011-2012 Daniele Varrazzo
#
# This file is part of the PGXN client
View
@@ -13,7 +13,7 @@ sibling of the directory containing this script, then are looked for in the
``PATH`` directories.
"""
-# Copyright (C) 2011 Daniele Varrazzo
+# Copyright (C) 2011-2012 Daniele Varrazzo
# This file is part of the PGXN client
View
@@ -3,7 +3,7 @@
pgxnclient -- command line interface
"""
-# Copyright (C) 2011 Daniele Varrazzo
+# Copyright (C) 2011-2012 Daniele Varrazzo
# This file is part of the PGXN client
View
@@ -1,5 +1,5 @@
echo "INSTALL"
-${PGXN} install --nosudo ${LEVEL} ${EXTENSION} || exit
+${PGXN} install ${LEVEL} ${EXTENSION} || exit
echo "CHECK"
${PGXN} check ${TEST_DSN} ${LEVEL} ${EXTENSION}
@@ -12,5 +12,5 @@ ${PGXN} unload ${TEST_DSN} ${LEVEL} ${EXTENSION}
echo "UNINSTALL"
dropdb -h ${PG_HOST} -p ${PG_PORT} ${TEST_DB}
-${PGXN} uninstall --nosudo ${LEVEL} ${EXTENSION} || exit
+${PGXN} uninstall ${LEVEL} ${EXTENSION} || exit
View
@@ -1,9 +1,12 @@
export PG_VERSION=9.1.1
export PG_ROOT=`pwd`/postgresql-${PG_VERSION}/root/
+export PATH=${PG_ROOT}/bin/:${PATH}
export PG_PORT=15432
export PG_HOST=localhost
export TEST_DB=contrib_regression
export TEST_DSN="-d ${TEST_DB} -h ${PG_HOST} -p ${PG_PORT}"
+
+# find the pgxn version to be tested
export PYTHONPATH=`pwd`/..:$PYTHONPATH
-export PATH=`pwd`/../bin:${PG_ROOT}/bin/:${PATH}
+export PATH=`pwd`/../bin:${PATH}
export PGXN=`which pgxn`
View
@@ -1,4 +1,4 @@
#!/bin/bash
source env.sh
-pg_ctl -D postgresql-${PG_VERSION}/data $1
+${PG_ROOT}/bin/pg_ctl -D postgresql-${PG_VERSION}/data $1
View
@@ -2,7 +2,7 @@
#
# Use 'make env', then 'make html' to build the HTML documentation
#
-# Copyright (C) 2011 Daniele Varrazzo
+# Copyright (C) 2011-2012 Daniele Varrazzo
PYTHON := python$(PYTHON_VERSION)
PYTHON_VERSION ?= $(shell $(PYTHON) -c 'import sys; print ("%d.%d" % sys.version_info[:2])')
View
@@ -41,7 +41,7 @@
# General information about the project.
project = u'PGXN Client'
-copyright = u'2011, Daniele Varrazzo'
+copyright = u'2011-2012, Daniele Varrazzo'
# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
View
@@ -4,7 +4,7 @@ Installation
Prerequisites
-------------
-The program is implemented in Python. Versions from Python 2.4 onwards are
+The program is implemented in Python. Versions from Python 2.5 onwards are
supported, including Python 3.0 and successive.
PostgreSQL client-side development tools are required to build and install
View
@@ -79,7 +79,7 @@ Usage:
:class: pgxn-install
pgxn install [--help] [--stable | --testing | --unstable]
- [--pg_config *PATH*] [--sudo *PROG* | --nosudo]
+ [--pg_config *PATH*] [--sudo [*PROG*] | --nosudo]
*SPEC*
The program takes a `package specification`_ identifying the distribution to
@@ -89,25 +89,34 @@ refers to a local directory or package.
Note that the built extension is not loaded in any database: use the command
`load`_ for this purpose.
-The command will run the ``./configure`` script if available in the package,
+The command will run the ``configure`` script if available in the package,
then will perform ``make all`` and ``make install``. It is assumed that the
``Makefile`` provided by the distribution uses PGXS_ to build the extension,
but this is not enforced: you may provide any Makefile as long as the expected
commands are implemented.
.. _PGXS: http://www.postgresql.org/docs/9.1/static/extend-pgxs.html
-The install phase usually requires root privileges in order to install a build
-library and other files in the PostgreSQL directories: by default
-:program:`sudo` will be invoked for the purpose. An alternative program can be
-specified with the option :samp:`--sudo {PROG}`; ``--nosudo`` can be used to
-avoid running any program.
-
If there are many PostgreSQL installations on the system, the extension will
be built and installed against the instance whose :program:`pg_config` is
first found on the :envvar:`PATH`. A different instance can be specified using
the option :samp:`--pg_config {PATH}`.
+If the extension is being installed into a system PostgreSQL installation, the
+install phase will likely require root privileges to be performed. In this
+case either run the command under :program:`sudo` or specify the ``--sudo``
+option: in the latter case :program:`sudo` will only be invoked during the
+"install" phase. An optional program :samp:`{PROG}` to elevate the user
+privileges can be specified as ``--sudo`` option; if none is specified,
+:program:`sudo` will be used.
+
+.. note::
+
+ If ``--sudo`` is the last option and no :samp:`{PROG}` is specified, a
+ ``--`` separator may be required to disambiguate the :samp:`{SPEC}`::
+
+ pgxn install --sudo -- foobar
+
.. _check:
@@ -170,7 +179,7 @@ Usage:
:class: pgxn-uninstall
pgxn uninstall [--help] [--stable | --testing | --unstable]
- [--pg_config *PATH*] [--sudo *PROG* | --nosudo]
+ [--pg_config *PATH*] [--sudo [*PROG*] | --nosudo]
*SPEC*
The command does the opposite of the install_ command, removing a
View
@@ -2,11 +2,11 @@
pgxnclient -- main package
"""
-# Copyright (C) 2011 Daniele Varrazzo
+# Copyright (C) 2011-2012 Daniele Varrazzo
# This file is part of the PGXN client
-__version__ = '1.0.3'
+__version__ = '1.1'
# Paths where to find the command executables.
# If relative, it's from the `pgxnclient` package directory.
View
@@ -2,10 +2,12 @@
pgxnclient -- client API stub
"""
-# Copyright (C) 2011 Daniele Varrazzo
+# Copyright (C) 2011-2012 Daniele Varrazzo
# This file is part of the PGXN client
+from __future__ import with_statement
+
from urllib import urlencode
from pgxnclient.utils import load_json
@@ -20,35 +22,38 @@ def __init__(self, mirror):
def dist(self, dist, version=''):
try:
- return load_json(self.call(
- version and 'meta' or 'dist',
- {'dist': dist, 'version': version}))
+ with self.call(version and 'meta' or 'dist',
+ {'dist': dist, 'version': version}) as f:
+ return load_json(f)
except ResourceNotFound:
raise NotFound("distribution '%s' not found" % dist)
def ext(self, ext):
try:
- return load_json(self.call('extension', {'extension': ext}))
+ with self.call('extension', {'extension': ext}) as f:
+ return load_json(f)
except ResourceNotFound:
raise NotFound("extension '%s' not found" % ext)
def meta(self, dist, version, as_json=True):
- f = self.call('meta', {'dist': dist, 'version': version})
- if as_json:
- return load_json(f)
- else:
- return f.read().decode('utf-8')
+ with self.call('meta', {'dist': dist, 'version': version}) as f:
+ if as_json:
+ return load_json(f)
+ else:
+ return f.read().decode('utf-8')
def readme(self, dist, version):
- return self.call('readme', {'dist': dist, 'version': version}).read()
+ with self.call('readme', {'dist': dist, 'version': version}) as f:
+ return f.read()
def download(self, dist, version):
dist = dist.lower()
version = version.lower()
return self.call('download', {'dist': dist, 'version': version})
def mirrors(self):
- return load_json(self.call('mirrors'))
+ with self.call('mirrors') as f:
+ return load_json(f)
def search(self, where, query):
"""Search into PGXN.
@@ -60,14 +65,16 @@ def search(self, where, query):
# convert the query list into a string
q = ' '.join([' ' in s and ('"%s"' % s) or s for s in query])
- return load_json(self.call('search', {'in': where},
- query={'q': q}))
+ with self.call('search', {'in': where}, query={'q': q}) as f:
+ return load_json(f)
def stats(self, arg):
- return load_json(self.call('stats', {'stats': arg}))
+ with self.call('stats', {'stats': arg}) as f:
+ return load_json(f)
def user(self, username):
- return load_json(self.call('user', {'user': username}))
+ with self.call('user', {'user': username}) as f:
+ return load_json(f)
def call(self, meth, args=None, query=None):
url = self.get_url(meth, args, query)
@@ -91,7 +98,8 @@ def get_index(self):
if self._api_index is None:
url = self.mirror.rstrip('/') + '/index.json'
try:
- self._api_index = load_json(get_file(url))
+ with get_file(url) as f:
+ self._api_index = load_json(f)
except ResourceNotFound:
raise NetworkError("API index not found at '%s'" % url)
View
@@ -2,7 +2,7 @@
pgxnclient -- command line entry point
"""
-# Copyright (C) 2011 Daniele Varrazzo
+# Copyright (C) 2011-2012 Daniele Varrazzo
# This file is part of the PGXN client
@@ -6,10 +6,12 @@
modules.
"""
-# Copyright (C) 2011 Daniele Varrazzo
+# Copyright (C) 2011-2012 Daniele Varrazzo
# This file is part of the PGXN client
+from __future__ import with_statement
+
import os
import sys
import logging
@@ -379,7 +381,8 @@ def get_meta(self, spec):
raise PgxnClientException(
_("file 'META.json' not found in '%s'") % dir)
- return load_json(open(fn))
+ with open(fn) as f:
+ return load_json(f)
elif spec.is_file():
# Get the metadata from a zip file
@@ -460,7 +463,7 @@ def call_pg_config(self, what, _cache={}):
return _cache[what]
logger.debug("running pg_config --%s", what)
- cmdline = [self.opts.pg_config, "--%s" % what]
+ cmdline = [self.get_pg_config(), "--%s" % what]
p = self.popen(cmdline, stdout=PIPE)
out, err = p.communicate()
if p.returncode:
@@ -471,6 +474,25 @@ def call_pg_config(self, what, _cache={}):
rv = _cache[what] = out
return rv
+ def get_pg_config(self):
+ """
+ Return the absolute path of the pg_config binary.
+ """
+ pg_config = self.opts.pg_config
+ if os.path.split(pg_config)[0]:
+ pg_config = os.path.abspath(pg_config)
+ else:
+ for dir in os.environ.get('PATH', '').split(os.pathsep):
+ if not dir: continue
+ fn = os.path.abspath(os.path.join(dir, pg_config))
+ if os.path.exists(fn):
+ pg_config = os.path.abspath(fn)
+ break
+ else:
+ raise PgxnClientException(_("pg_config executable not found"))
+
+ return pg_config
+
import shlex
@@ -500,13 +522,7 @@ def run_make(self, cmd, dir, env=None, sudo=None):
if sudo:
cmdline.extend(shlex.split(sudo))
- # convert to absolute path for makefile, or else it may miss it
- # if the cwd is changed during execution
- pg_config = self.opts.pg_config
- if os.path.split(pg_config)[0]:
- pg_config = os.path.abspath(pg_config)
-
- cmdline.extend(['make', 'PG_CONFIG=%s' % pg_config])
+ cmdline.extend(['make', 'PG_CONFIG=%s' % self.get_pg_config()])
if isinstance(cmd, basestring):
cmdline.append(cmd)
@@ -531,11 +547,12 @@ def customize_parser(self, parser, subparsers, **kwargs):
parser, subparsers, **kwargs)
g = subp.add_mutually_exclusive_group()
- g.add_argument('--sudo', metavar="PROG", default='sudo',
+ g.add_argument('--sudo', metavar="PROG", const='sudo', nargs="?",
help = _("run PROG to elevate privileges when required"
- " [default: %(default)s]"))
+ " [default: %(const)s]"))
g.add_argument('--nosudo', dest='sudo', action='store_false',
- help = _("never elevate privileges"))
+ help = _("never elevate privileges "
+ "(no more needed: for backward compatibility)"))
return subp
@@ -2,7 +2,7 @@
pgxnclient -- help commands implementation
"""
-# Copyright (C) 2011 Daniele Varrazzo
+# Copyright (C) 2011-2012 Daniele Varrazzo
# This file is part of the PGXN client
Oops, something went wrong.

0 comments on commit 71951c9

Please sign in to comment.