commit python-setproctitle for openSUSE:Factory
Hello community, here is the log from the commit of package python-setproctitle for openSUSE:Factory checked in at Thu Nov 18 18:01:12 CET 2010. -------- --- python-setproctitle/python-setproctitle.changes 2010-06-23 16:55:29.000000000 +0200 +++ python-setproctitle/python-setproctitle.changes 2010-11-18 16:53:11.000000000 +0100 @@ -1,0 +2,6 @@ +Thu Nov 18 15:52:28 UTC 2010 - hvogel@novell.com + +- Update to version 1.1 + * add support python3 + +------------------------------------------------------------------- calling whatdependson for head-i586 Old: ---- setproctitle-1.0.1.tar.bz2 New: ---- setproctitle-1.1.tar.bz2 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ python-setproctitle.spec ++++++ --- /var/tmp/diff_new_pack.AsIo8Q/_old 2010-11-18 17:58:50.000000000 +0100 +++ /var/tmp/diff_new_pack.AsIo8Q/_new 2010-11-18 17:58:50.000000000 +0100 @@ -1,5 +1,5 @@ # -# spec file for package python-setproctitle (Version 1.0.1) +# spec file for package python-setproctitle (Version 1.1) # # Copyright (c) 2010 SUSE LINUX Products GmbH, Nuernberg, Germany. # @@ -19,11 +19,11 @@ %define modname setproctitle Name: python-setproctitle -Version: 1.0.1 +Version: 1.1 Release: 1 License: BSD Summary: Python module to allow customization of the process title -Url: http://pyasn1.sf.net/ +Url: http://pypi.python.org/pypi/setproctitle/ Group: Development/Libraries/Python Source: %{modname}-%{version}.tar.bz2 BuildRequires: python-devel ++++++ setproctitle-1.0.1.tar.bz2 -> setproctitle-1.1.tar.bz2 ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/setproctitle-1.0.1/HISTORY new/setproctitle-1.1/HISTORY --- old/setproctitle-1.0.1/HISTORY 2010-06-04 12:47:53.000000000 +0200 +++ new/setproctitle-1.1/HISTORY 2010-07-03 19:34:20.000000000 +0200 @@ -1,6 +1,12 @@ Releases history ---------------- +Version 1.1 +~~~~~~~~~~~ + +- The module works correctly with Python 3. + + Version 1.0.1 ~~~~~~~~~~~~~ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/setproctitle-1.0.1/MANIFEST new/setproctitle-1.1/MANIFEST --- old/setproctitle-1.0.1/MANIFEST 1970-01-01 01:00:00.000000000 +0100 +++ new/setproctitle-1.1/MANIFEST 2010-07-07 03:27:20.000000000 +0200 @@ -0,0 +1,18 @@ +COPYRIGHT +HISTORY +MANIFEST +Makefile +README +setup.py +src/c.h +src/setproctitle.c +src/spt.h +src/spt_config.h +src/spt_debug.c +src/spt_python.h +src/spt_setup.c +src/spt_setup.h +src/spt_status.c +src/spt_status.h +src/strlcpy.c +tests/setproctitle_test.py diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/setproctitle-1.0.1/Makefile new/setproctitle-1.1/Makefile --- old/setproctitle-1.0.1/Makefile 1970-01-01 01:00:00.000000000 +0100 +++ new/setproctitle-1.1/Makefile 2010-07-07 03:08:47.000000000 +0200 @@ -0,0 +1,50 @@ +# Oh, makefile, help me with the python3 craze :D +# +# Copyright (c) 2010 Daniele Varrazzo <daniele.varrazzo@gmail.com> + +MKDIR = mkdir -p +RM = rm -f +PYTHON = python +PYTHON3 = python3.1 +PY2TO3 = 2to3 + +BUILD_DIR = build/lib.`basename $(PYTHON)` +BUILD3_DIR = build/lib.`basename $(PYTHON3)` + +.PHONY: build test py3 build3 test3 clean + +build: + $(PYTHON) setup.py build --build-lib $(BUILD_DIR) + +test: build + PYTHONPATH=`pwd`/$(BUILD_DIR):$$PYTHONPATH \ + $(PYTHON) `which nosetests` -v -s -w tests + +sdist: MANIFEST + $(PYTHON) setup.py sdist --formats=gztar,zip + +MANIFEST: + # Must run twice because the manifest contains the manifest itself. + $(PYTHON) setup.py sdist --manifest-only + $(PYTHON) setup.py sdist --manifest-only + +py3: MANIFEST + $(MKDIR) py3 + $(MKDIR) py3/src + $(MKDIR) py3/tests + for f in `cat MANIFEST`; do cp -v $$f py3/$$f; done + # setup.py should be executable with python3 as distribute + # currenlty doesn't seem to try to convert it + $(PY2TO3) -w --no-diffs py3/tests + +build3: py3 + $(PYTHON3) py3/setup.py build --build-lib $(BUILD3_DIR) + +test3: build3 + PYTHONPATH=$(BUILD3_DIR):$$PYTHONPATH \ + $(PYTHON3) py3/tests/setproctitle_test.py -v + +clean: + $(RM) -r MANIFEST py3 build dist + + diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/setproctitle-1.0.1/PKG-INFO new/setproctitle-1.1/PKG-INFO --- old/setproctitle-1.0.1/PKG-INFO 2010-06-04 13:01:11.000000000 +0200 +++ new/setproctitle-1.1/PKG-INFO 2010-07-07 03:28:24.000000000 +0200 @@ -1,6 +1,6 @@ Metadata-Version: 1.0 Name: setproctitle -Version: 1.0.1 +Version: 1.1 Summary: Allow customization of the process title. Home-page: http://code.google.com/p/py-setproctitle/ Author: Daniele Varrazzo @@ -35,14 +35,14 @@ You can use ``easy_install`` to install the module: to perform a system-wide installation use:: - sudo easy_install setproctitle + sudo easy_install setproctitle If you are an unprivileged user or you want to limit installation to a local environment, you can use the command:: - easy_install -d /target/path setproctitle + easy_install -d /target/path setproctitle - Notice that ``easy_install`` requires ``/target/path`` to be in your + Notice that ``easy_install`` requires ``/target/path`` to be in your ``PYTHONPATH``. @@ -52,11 +52,11 @@ The module exports the following functions: ``setproctitle(title)`` - Set *title* as the title for the current process. + Set *title* as the title for the current process. ``getproctitle()`` - Return the current process title. + Return the current process title. Module status @@ -81,30 +81,48 @@ .. _Process Explorer: http://technet.microsoft.com/en-us/sysinternals/bb896653.aspx + Python 3 support + ---------------- + + As of version 1.1 the module works with Python 3. In order to install the + module, you can use the `distribute`_ replacemente for ``easy_install``. + + In order to build and test the module under Python 3, the ``Makefile`` + contains some helper targets. + + .. _distribute: http://pypi.python.org/pypi/distribute + + Other known implementations and discussions ------------------------------------------- - - `procname`_: a module exposing the same functionality, but less portable - and not well packaged. + - `procname`_: a module exposing the same functionality, but less portable + and not well packaged. - `Issue 5672`_: where the introduction of such functionality into the stdlib - is being discussed. + is being discussed. .. _procname: http://code.google.com/p/procname/ .. _Issue 5672: http://bugs.python.org/issue5672 .. - vim: set filetype=rst: + vim: set filetype=rst: Releases history ---------------- + Version 1.1 + ~~~~~~~~~~~ + + - The module works correctly with Python 3. + + Version 1.0.1 ~~~~~~~~~~~~~ - ``setproctitle()`` works even when Python messes up with argv, e.g. when run - with the -m option. + with the -m option. Version 1.0 @@ -121,11 +139,11 @@ - Module works on BSD (tested on FreeBSD 7.2). - Module works on Windows. Many thanks to `Develer`_ for providing a neat `GCC - package for Windows with Python integration`__ that made the Windows porting - painless. + package for Windows with Python integration`__ that made the Windows porting + painless. - .. _Develer: http://www.develer.com/ - .. __: http://www.develer.com/oss/GccWinBinaries + .. _Develer: http://www.develer.com/ + .. __: http://www.develer.com/oss/GccWinBinaries Version 0.3 @@ -154,6 +172,7 @@ Classifier: License :: OSI Approved :: BSD License Classifier: Programming Language :: C Classifier: Programming Language :: Python +Classifier: Programming Language :: Python :: 3 Classifier: Operating System :: POSIX :: Linux Classifier: Operating System :: POSIX :: BSD Classifier: Operating System :: MacOS :: MacOS X diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/setproctitle-1.0.1/README new/setproctitle-1.1/README --- old/setproctitle-1.0.1/README 2010-05-21 19:12:52.000000000 +0200 +++ new/setproctitle-1.1/README 2010-07-03 19:34:20.000000000 +0200 @@ -72,6 +72,18 @@ .. _Process Explorer: http://technet.microsoft.com/en-us/sysinternals/bb896653.aspx +Python 3 support +---------------- + +As of version 1.1 the module works with Python 3. In order to install the +module, you can use the `distribute`_ replacemente for ``easy_install``. + +In order to build and test the module under Python 3, the ``Makefile`` +contains some helper targets. + +.. _distribute: http://pypi.python.org/pypi/distribute + + Other known implementations and discussions ------------------------------------------- diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/setproctitle-1.0.1/setup.py new/setproctitle-1.1/setup.py --- old/setproctitle-1.0.1/setup.py 2010-06-04 12:47:53.000000000 +0200 +++ new/setproctitle-1.1/setup.py 2010-07-07 03:23:06.000000000 +0200 @@ -5,7 +5,7 @@ Copyright (c) 2009-2010 Daniele Varrazzo <daniele.varrazzo@gmail.com> """ -VERSION = '1.0.1' +VERSION = '1.1' import os import re @@ -16,11 +16,15 @@ define_macros['SPT_VERSION'] = VERSION +# Check the env to see if piro wants debug messages. +if 'SPT_DEBUG' in os.environ: + define_macros['SPT_DEBUG'] = '1' + if sys.platform == 'linux2': try: - linux_version = map(int, + linux_version = list(map(int, re.search("[.0-9]+", os.popen("uname -r").read()) - .group().split(".")[:3]) + .group().split(".")[:3])) except: pass else: @@ -46,9 +50,11 @@ # But I have none handy to test with. mod_spt = Extension('setproctitle', - define_macros=define_macros.items(), + define_macros=list(define_macros.items()), sources = [ 'src/setproctitle.c', + 'src/spt_debug.c', + 'src/spt_setup.c', 'src/spt_status.c', 'src/strlcpy.c', # TODO: not needed on some platform ]) @@ -80,17 +86,18 @@ download_url = 'http://pypi.python.org/pypi/setproctitle/', license = 'BSD', platforms = ['GNU/Linux', 'BSD', 'MacOS X', 'Windows'], - classifiers = filter(None, map(str.strip, """ + classifiers = [ r for r in map(str.strip, """ Development Status :: 5 - Production/Stable Intended Audience :: Developers License :: OSI Approved :: BSD License Programming Language :: C Programming Language :: Python + Programming Language :: Python :: 3 Operating System :: POSIX :: Linux Operating System :: POSIX :: BSD Operating System :: MacOS :: MacOS X Operating System :: Microsoft :: Windows Topic :: Software Development - """.splitlines())), + """.splitlines()) if r], ext_modules = [mod_spt], **kwargs) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/setproctitle-1.0.1/src/setproctitle.c new/setproctitle-1.1/src/setproctitle.c --- old/setproctitle-1.0.1/src/setproctitle.c 2010-06-04 12:47:53.000000000 +0200 +++ new/setproctitle-1.1/src/setproctitle.c 2010-07-01 02:07:52.000000000 +0200 @@ -6,22 +6,19 @@ * Copyright (c) 2009-2010 Daniele Varrazzo <daniele.varrazzo@gmail.com> * * The module allows Python code to access the functions get_ps_display() - * and set_ps_display(). The process title initialization (functions - * save_ps_display_args() and init_ps_display()) are called at module - * initialization. + * and set_ps_display(). + * *------------------------------------------------------------------------- */ -#include "Python.h" +#include "spt.h" +#include "spt_setup.h" #include "spt_status.h" #ifndef SPT_VERSION #define SPT_VERSION unknown #endif -/* defined in Modules/main.c but not publically declared */ -void Py_GetArgcArgv(int *argc, char ***argv); - /* macro trick to stringify a macro expansion */ #define xstr(s) str(s) #define str(s) #s @@ -76,104 +73,66 @@ }; -/* return a concatenated version of a strings vector - * - * Return newly allocated heap space: clean it up with free() - */ -static char * -join_argv(int argc, char **argv) -{ - /* Calculate the final string length */ - int i; - size_t len = 0; - for (i = 0; i < argc; i++) { - len += strlen(argv[i]) + 1; - } - - char *buf = (char *)malloc(len); - - /* Copy the strings in the buffer joining with spaces */ - char *dest = buf; - char *src; - for (i = 0; i < argc; i++) { - src = argv[i]; - while (*src) { - *dest++ = *src++; - } - *dest++ = ' '; - } - *--dest = '\x00'; - - return buf; -} - - -/* Return a copy of argv referring to the original arg area. - * - * python -m messes up with arg (issue #8): ensure to have a vector to the - * original args or save_ps_display_args() will stop processing too soon. - * - * Return a buffer allocated with malloc: should be cleaned up with free() - * (it is never released though). - */ -static char ** -fix_argv(int argc, char **argv) -{ - char **buf = (char **)malloc(argc * sizeof(char *)); - int i; - char *ptr = argv[0]; - for (i = 0; i < argc; ++i) { - buf[i] = ptr; - ptr += strlen(ptr) + 1; - } - - return buf; -} - - /* Initialization function for the module (*must* be called initsetproctitle) */ static char setproctitle_module_documentation[] = "Allow customization of the process title." ; -void -initsetproctitle(void) +#ifdef IS_PY3K + +static struct PyModuleDef moduledef = { + PyModuleDef_HEAD_INIT, + "setproctitle", + setproctitle_module_documentation, + -1, + spt_methods, + NULL, + NULL, + NULL, + NULL +}; + +#endif + +PyMODINIT_FUNC +INIT_MODULE(setproctitle)(void) { PyObject *m, *d; + spt_debug("module init"); + /* Create the module and add the functions */ +#ifdef IS_PY3K + m = PyModule_Create(&moduledef); +#else m = Py_InitModule3("setproctitle", spt_methods, setproctitle_module_documentation); +#endif + if (m == NULL) { goto exit; } /* Add version string to the module*/ d = PyModule_GetDict(m); - spt_version = PyString_FromString(xstr(SPT_VERSION)); + spt_version = Py_BuildValue("s", xstr(SPT_VERSION)); PyDict_SetItemString(d, "__version__", spt_version); /* Initialize the process title */ -#ifndef WIN32 - int argc; - char **argv; - Py_GetArgcArgv(&argc, &argv); - argv = fix_argv(argc, argv); - save_ps_display_args(argc, argv); - - /* Set up the first title to fully initialize the code */ - char *init_title = join_argv(argc, argv); - init_ps_display(init_title); - free(init_title); -#else - /* On Windows save_ps_display_args is a no-op - * This is a good news, because Py_GetArgcArgv seems not usable. - */ - LPTSTR init_title = GetCommandLine(); - init_ps_display(init_title); -#endif - + spt_setup(); /* Check for errors */ - if (PyErr_Occurred()) + if (PyErr_Occurred()) { Py_FatalError("can't initialize module setproctitle"); + Py_DECREF(m); + m = NULL; + } + +exit: + +#ifdef IS_PY3K + return m; +#else + return; +#endif + } diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/setproctitle-1.0.1/src/spt.h new/setproctitle-1.1/src/spt.h --- old/setproctitle-1.0.1/src/spt.h 1970-01-01 01:00:00.000000000 +0100 +++ new/setproctitle-1.1/src/spt.h 2010-06-25 03:39:21.000000000 +0200 @@ -0,0 +1,20 @@ +/*------------------------------------------------------------------------- + * + * spt.h + * Definitions useful throughout all the extension. + * + * Copyright (c) 2010 Daniele Varrazzo <daniele.varrazzo@gmail.com> + * + *------------------------------------------------------------------------- + */ + +#ifndef SPT_H +#define SPT_H + +#include "spt_config.h" +#include "spt_python.h" + +/* expose the debug function to the extension code */ +void spt_debug(const char *fmt, ...); + +#endif diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/setproctitle-1.0.1/src/spt_debug.c new/setproctitle-1.1/src/spt_debug.c --- old/setproctitle-1.0.1/src/spt_debug.c 1970-01-01 01:00:00.000000000 +0100 +++ new/setproctitle-1.1/src/spt_debug.c 2010-06-25 03:36:16.000000000 +0200 @@ -0,0 +1,32 @@ +/*------------------------------------------------------------------------- + * + * spt_python.c + * A simple function for the module debugging. + * + * Copyright (c) 2009-2010 Daniele Varrazzo <daniele.varrazzo@gmail.com> + * + * Debug logging is enabled if the extension is compiled with the + * SPT_DEBUG symbol and is emitted on stdout. + * + *------------------------------------------------------------------------- + */ + +#include <stdarg.h> +#include <stdio.h> + +void spt_debug(const char *fmt, ...) +{ + +#ifdef SPT_DEBUG + + va_list ap; + + fprintf(stderr, "[SPT]: "); + va_start(ap, fmt); + vfprintf(stderr, fmt, ap); + va_end(ap); + fprintf(stderr, "\n"); + +#endif + +} diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/setproctitle-1.0.1/src/spt_python.h new/setproctitle-1.1/src/spt_python.h --- old/setproctitle-1.0.1/src/spt_python.h 1970-01-01 01:00:00.000000000 +0100 +++ new/setproctitle-1.1/src/spt_python.h 2010-07-03 20:08:55.000000000 +0200 @@ -0,0 +1,35 @@ +/*------------------------------------------------------------------------- + * + * spt_python.h + * Include and customize Python definitions. + * + * Copyright (c) 2010 Daniele Varrazzo <daniele.varrazzo@gmail.com> + * + *------------------------------------------------------------------------- + */ + +#ifndef SPT_PYTHON_H +#define SPT_PYTHON_H + +#include <Python.h> + +/* Things change a lot here... */ +#if PY_MAJOR_VERSION >= 3 +#define IS_PY3K +#endif + +/* defined in Modules/main.c but not publically declared */ +#ifdef IS_PY3K +void Py_GetArgcArgv(int *argc, wchar_t ***argv); +#else +void Py_GetArgcArgv(int *argc, char ***argv); +#endif + +/* Mangle the module name into the name of the module init function */ +#ifdef IS_PY3K +#define INIT_MODULE(m) PyInit_ ## m +#else +#define INIT_MODULE(m) init ## m +#endif + +#endif /* SPT_PYTHON_H */ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/setproctitle-1.0.1/src/spt_setup.c new/setproctitle-1.1/src/spt_setup.c --- old/setproctitle-1.0.1/src/spt_setup.c 1970-01-01 01:00:00.000000000 +0100 +++ new/setproctitle-1.1/src/spt_setup.c 2010-07-07 00:58:19.000000000 +0200 @@ -0,0 +1,263 @@ +/*------------------------------------------------------------------------- + * + * spt_setup.c + * Initalization code for the spt_status.c module functions. + * + * Copyright (c) 2009-2010 Daniele Varrazzo <daniele.varrazzo@gmail.com> + * + *------------------------------------------------------------------------- + */ + +#include "spt_setup.h" + +#include "spt.h" +#include "spt_status.h" + +/* Darwin doesn't export environ */ +#if defined(__darwin__) +#include <crt_externs.h> +#define environ (*_NSGetEnviron()) +#else +extern char **environ; +#endif + +#ifndef WIN32 + +/* return a concatenated version of a strings vector + * + * Return newly allocated heap space: clean it up with free() + */ +static char * +join_argv(int argc, char **argv) +{ + /* Calculate the final string length */ + int i; + size_t len = 0; + for (i = 0; i < argc; i++) { + len += strlen(argv[i]) + 1; + } + + char *buf = (char *)malloc(len); + + /* Copy the strings in the buffer joining with spaces */ + char *dest = buf; + char *src; + for (i = 0; i < argc; i++) { + src = argv[i]; + while (*src) { + *dest++ = *src++; + } + *dest++ = ' '; + } + *--dest = '\x00'; + + return buf; +} + + +#ifndef IS_PY3K + +/* Return a copy of argv referring to the original arg area. + * + * python -m messes up with arg (issue #8): ensure to have a vector to the + * original args or save_ps_display_args() will stop processing too soon. + * + * Return a buffer allocated with malloc: should be cleaned up with free() + * (it is never released though). + */ +static char ** +fix_argv(int argc, char **argv) +{ + char **buf = (char **)malloc(argc * sizeof(char *)); + int i; + char *ptr = argv[0]; + for (i = 0; i < argc; ++i) { + buf[i] = ptr; + ptr += strlen(ptr) + 1; + } + + return buf; +} + +#else + +/* Return a copy of argv[0] encoded in the default encoding. + * + * Return a newly allocated buffer to be released with free() + */ +static char * +get_encoded_arg0(wchar_t *argv0) +{ + PyObject *ua = NULL, *ba = NULL; + char *rv = NULL; + + if (!(ua = PyUnicode_FromWideChar(argv0, -1))) { + spt_debug("failed to convert argv[0] to unicode"); + goto exit; + } + + if (!(ba = PyUnicode_AsEncodedString( + ua, PyUnicode_GetDefaultEncoding(), "strict"))) { + spt_debug("failed to encode argv[0]"); + goto exit; + } + + rv = strdup(PyBytes_AsString(ba)); + +exit: + PyErr_Clear(); + Py_XDECREF(ua); + Py_XDECREF(ba); + + return rv; +} + +/* Find the original arg buffer starting from the env position. + * + * Return nonzero if found. + * + * Required on Python 3 as Py_GetArgcArgv doesn't return pointers to the + * original area. + */ +static int +find_argv_from_env(int *argc_o, char ***argv_o) +{ + int rv = 0; + int argc; + wchar_t **argv; + char **buf = NULL; + char *arg0 = NULL; + + /* Find the number of parameters. */ + Py_GetArgcArgv(&argc, &argv); + + buf = (char **)malloc((argc + 1) * sizeof(char *)); + buf[argc] = NULL; + + /* Walk back from environ until you find argc-1 null-terminated strings. + * Don't look for argv[0] as it's probably not preceded by 0. */ + int i; + char *ptr = environ[0]; + char *limit = ptr - 8192; /* TODO: empiric limit: should use MAX_ARG */ + --ptr; + for (i = argc - 1; i >= 1; --i) { + if (*ptr) { + spt_debug("zero %d not found", i); + goto error; + } + --ptr; + while (*ptr && ptr > limit) { --ptr; } + if (ptr <= limit) { + spt_debug("failed to found arg %d start", i); + goto error; + } + buf[i] = (ptr + 1); + } + + /* The first arg has not a zero in front. But what we have is reliable + * enough (modulo its encoding). Check if it is exactly what found. + * + * The check is known to fail on OS X with locale C if there are + * non-ascii characters in the executable path. See Python issue #9167 + */ + arg0 = get_encoded_arg0(argv[0]); + if (!arg0) { goto error; } + ptr -= strlen(arg0); + + if (ptr <= limit) { + spt_debug("failed to found argv[0] start"); + goto error; + } + if (strcmp(ptr, arg0)) { + spt_debug("failed to recognize argv[0]"); + goto error; + } + + /* We have all the pieces of the jigsaw. */ + buf[0] = ptr; + *argc_o = argc; + *argv_o = buf; + rv = 1; + + goto exit; + +error: + if (buf) { free(buf); } + +exit: + if (arg0) { free(arg0); } + + return rv; +} + +#endif /* IS_PY3K */ + +/* Find the original arg buffer, return nonzero if found. + * + * If found, set argc to the number of arguments, argv to an array + * of pointers to the single arguments. The array is allocated via malloc. + * + * The function overcomes two Py_GetArgcArgv shortcomings: + * - some python parameters mess up with the original argv, e.g. -m + * (see issue #8) + * - with Python 3, argv is a decoded copy and doesn't point to + * the original area. + */ +static int +get_argc_argv(int *argc, char ***argv) +{ + int rv = false; + +#ifdef IS_PY3K + if (!(rv = find_argv_from_env(argc, argv))) { + spt_debug("get_argc_argv failed"); + } +#else + Py_GetArgcArgv(argc, argv); + *argv = fix_argv(*argc, *argv); + rv = true; +#endif + + return rv; +} + +#endif /* WIN32 */ + + +/* Initialize the module internal functions. + * + * The function reproduces the initialization performed by PostgreSQL + * to be able to call the functions in pg_status.c + * + * The function should be called only once in the process lifetime. + * so is called at module initialization. After the function is called, + * set_ps_display() can be used. + */ +void +spt_setup(void) +{ +#ifndef WIN32 + int argc = 0; + char **argv = NULL; + + if (!get_argc_argv(&argc, &argv)) { + spt_debug("setup failed"); + return; + } + + save_ps_display_args(argc, argv); + + /* Set up the first title to fully initialize the code */ + char *init_title = join_argv(argc, argv); + init_ps_display(init_title); + free(init_title); +#else + /* On Windows save_ps_display_args is a no-op + * This is a good news, because Py_GetArgcArgv seems not usable. + */ + LPTSTR init_title = GetCommandLine(); + init_ps_display(init_title); +#endif + +} + diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/setproctitle-1.0.1/src/spt_setup.h new/setproctitle-1.1/src/spt_setup.h --- old/setproctitle-1.0.1/src/spt_setup.h 1970-01-01 01:00:00.000000000 +0100 +++ new/setproctitle-1.1/src/spt_setup.h 2010-06-25 03:46:23.000000000 +0200 @@ -0,0 +1,16 @@ +/*------------------------------------------------------------------------- + * + * spt_setup.h + * Initalization code for the spt_status.c module functions. + * + * Copyright (c) 2009-2010 Daniele Varrazzo <daniele.varrazzo@gmail.com> + * + *------------------------------------------------------------------------- + */ + +#ifndef SPT_SETUP_H +#define SPT_SETUP_H + +void spt_setup(void); + +#endif diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/setproctitle-1.0.1/src/spt_status.c new/setproctitle-1.1/src/spt_status.c --- old/setproctitle-1.0.1/src/spt_status.c 2010-02-26 17:08:11.000000000 +0100 +++ new/setproctitle-1.1/src/spt_status.c 2010-07-02 20:46:47.000000000 +0200 @@ -114,7 +114,7 @@ #endif /* we use this strategy together with another one (probably PS_USE_CLOBBER_ARGV) */ -#if defined(HAVE_SYS_PRCTL_H) && !defined(PS_USE_NONE) +#if defined(HAVE_SYS_PRCTL_H) && defined(PR_SET_NAME) && !defined(PS_USE_NONE) #define PS_USE_PRCTL #endif diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/setproctitle-1.0.1/tests/setproctitle_test.py new/setproctitle-1.1/tests/setproctitle_test.py --- old/setproctitle-1.0.1/tests/setproctitle_test.py 2010-06-04 12:47:53.000000000 +0200 +++ new/setproctitle-1.1/tests/setproctitle_test.py 2010-07-07 03:10:21.000000000 +0200 @@ -13,9 +13,27 @@ import unittest from subprocess import Popen, PIPE, STDOUT -from nose.plugins.skip import SkipTest +IS_PY3K = sys.version_info[0] == 3 + +try: + from nose.plugins.skip import SkipTest +except ImportError: + try: + from unittest import SkipTest + except ImportError: + class SkipTest(Exception): + pass class SetproctitleTestCase(unittest.TestCase): + """Test the module works as expected. + + The tests are executed in external processes: setproctitle should + never be imported directly from here. + + The tests scrits are written in Python 2 syntax: if the test suite is run + with Python 3 they are converted automatically. This test module should + be converted though: the Makefile should do that. + """ def test_runner(self): """Test the script execution method.""" rv = self.run_script(""" @@ -63,7 +81,7 @@ pass if linux_version < [2,6,9]: - raise SkipTest + raise SkipTest("syscall not supported") rv = self.run_script(r""" import setproctitle @@ -118,14 +136,14 @@ os.environ['PYTHONPATH'] = dir + os.pathsep + (pypath or '') try: open(dir + '/' + module + '.py', 'w').write( - self._clean_whitespaces(r""" + self.to3(self._clean_whitespaces(r""" import setproctitle setproctitle.setproctitle("Hello, module!") import os print os.getpid() print os.popen("ps -o pid,command 2> /dev/null").read() - """)) + """))) rv = self.run_script(args="-m " + module) lines = filter(None, rv.splitlines()) @@ -142,31 +160,152 @@ else: del os.environ['PYTHONPATH'] + def test_unicode(self): + """Title can contain unicode characters.""" + if 'utf-8' != sys.getdefaultencoding(): + raise SkipTest("encoding '%s' can't deal with snowmen" + % sys.getdefaultencoding()) + + rv = self.run_script(r""" + snowman = u'\u2603' + + import setproctitle + setproctitle.setproctitle("Hello, " + snowman + "!") + + import os + print os.getpid() + print os.popen("ps -o pid,command 2> /dev/null").read() + """) + lines = filter(None, rv.splitlines()) + pid = lines.pop(0) + pids = dict([r.strip().split(None, 1) for r in lines]) + + snowmen = [ + u'\u2603', # ps supports unicode + r'\M-b\M^X\M^C', # ps output on BSD + r'M-bM^XM^C', # ps output on OS-X + ] + title = self._clean_up_title(pids[pid]) + for snowman in snowmen: + if title == "Hello, " + snowman + "!": + break + else: + self.fail("unexpected ps output: %r" % title) + + def test_weird_args(self): + """No problem with encoded arguments.""" + euro = u'\u20ac' + snowman = u'\u2603' + try: + rv = self.run_script(r""" + import setproctitle + setproctitle.setproctitle("Hello, weird args!") + + import os + print os.getpid() + print os.popen("ps -o pid,command 2> /dev/null").read() + """, args=u" ".join(["-", "hello", euro, snowman])) + except TypeError: + raise SkipTest( + "apparently we can't pass unicode args to a program") + + lines = filter(None, rv.splitlines()) + pid = lines.pop(0) + pids = dict([r.strip().split(None, 1) for r in lines]) + + title = self._clean_up_title(pids[pid]) + self.assertEqual(title, "Hello, weird args!") + + def test_weird_path(self): + """No problem with encoded argv[0] path.""" + self._check_4388() + euro = u'\u20ac' + snowman = u'\u2603' + tdir = tempfile.mkdtemp() + dir = tdir + "/" + euro + "/" + snowman + try: + try: + os.makedirs(dir) + except UnicodeEncodeError: + raise SkipTest("file system doesn't support unicode") + + exc = dir + "/python" + os.symlink(sys.executable, exc) + + rv = self.run_script(r""" + import setproctitle + setproctitle.setproctitle("Hello, weird path!") + + import os + print os.getpid() + print os.popen("ps -o pid,command 2> /dev/null").read() + """, + args=u" ".join(["-", "foo", "bar", "baz"]), + executable=exc) + lines = filter(None, rv.splitlines()) + pid = lines.pop(0) + pids = dict([r.strip().split(None, 1) for r in lines]) - def run_script(self, script=None, args=None): + title = self._clean_up_title(pids[pid]) + self.assertEqual(title, "Hello, weird path!") + finally: + shutil.rmtree(tdir, ignore_errors=True) + + def run_script(self, script=None, args=None, executable=None): """run a script in a separate process. - if the script completes successfully, return the concatenation of - ``stdout`` and ``stderr``. else fail. + if the script completes successfully, return its ``stdout``, + else fail the test. """ - cmdline = sys.executable + if executable is None: + executable = sys.executable + + cmdline = executable if args: cmdline = cmdline + " " + args proc = Popen(cmdline, - stdin=PIPE, stdout=PIPE, stderr=STDOUT, + stdin=PIPE, stdout=PIPE, stderr=PIPE, shell=True, close_fds=True) if script is not None: script = self._clean_whitespaces(script) + script = self.to3(script) + if IS_PY3K: + script = script.encode() - out = proc.communicate(script)[0] + out, err = proc.communicate(script) if 0 != proc.returncode: print out + print err self.fail("test script failed") + # Py3 subprocess generates bytes strings. + if IS_PY3K: + out = out.decode() + return out + def to3(self, script): + """Convert a script to Python3 if required.""" + if not IS_PY3K: + return script + + script = script.encode() + f = tempfile.NamedTemporaryFile(suffix=".py") + f.write(script) + f.flush() + + # 2to3 is way too chatty + import logging + logging.basicConfig(filename=os.devnull) + + from lib2to3.main import main + if main("lib2to3.fixes", ['--no-diffs', '-w', '-n', f.name]): + raise Exception('py3 conversion failed') + + return open(f.name).read() + def _clean_whitespaces(self, script): """clean up a script in a string @@ -208,6 +347,30 @@ return title + def _check_4388(self): + """Check if the system is affected by bug #4388. + + If positive, unicode chars in the cmdline are not reliable, + so bail out. + + see: http://bugs.python.org/issue4388 + """ + if not IS_PY3K: + return + + if sys.getfilesystemencoding() == 'ascii': + # in this case the char below would get translated in some + # inconsistent way. + # I'm not getting why the FS encoding is involved in process + # spawning, the whole story just seems a gigantic can of worms. + return + + from subprocess import Popen, PIPE + p = Popen([sys.executable, '-c', "ord('\xe9')"], stderr=PIPE) + p.communicate() + if p.returncode: + raise SkipTest("bug #4388 detected") + if __name__ == '__main__': unittest.main() ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Remember to have fun... -- To unsubscribe, e-mail: opensuse-commit+unsubscribe@opensuse.org For additional commands, e-mail: opensuse-commit+help@opensuse.org
participants (1)
-
root@hilbert.suse.de