[Assorted-commits] SF.net SVN: assorted: [584] python-commons/tags
Brought to you by:
yangzhang
From: <yan...@us...> - 2008-03-03 04:55:28
|
Revision: 584 http://assorted.svn.sourceforge.net/assorted/?rev=584&view=rev Author: yangzhang Date: 2008-03-02 20:55:33 -0800 (Sun, 02 Mar 2008) Log Message: ----------- tagged 0.2 release Added Paths: ----------- python-commons/tags/0.2/ python-commons/tags/0.2/README python-commons/tags/0.2/publish.bash python-commons/tags/0.2/setup.py python-commons/tags/0.2/src/commons/__init__.py python-commons/tags/0.2/src/commons/files.py python-commons/tags/0.2/src/commons/setup.py Removed Paths: ------------- python-commons/tags/0.2/README python-commons/tags/0.2/setup.py python-commons/tags/0.2/src/commons/__init__.py python-commons/tags/0.2/src/commons/files.py python-commons/tags/0.2/src/commons/setup.py Copied: python-commons/tags/0.2 (from rev 473, python-commons/trunk) Deleted: python-commons/tags/0.2/README =================================================================== --- python-commons/trunk/README 2008-02-19 09:09:41 UTC (rev 473) +++ python-commons/tags/0.2/README 2008-03-03 04:55:33 UTC (rev 584) @@ -1,5 +0,0 @@ -To install, run setup.py or setup.bash. - -Future releases will come with scripts to build the epydoc API -documentation, but for now please refer to the project homepage for -the full documentation: http://assorted.sf.net/python-commons Copied: python-commons/tags/0.2/README (from rev 565, python-commons/trunk/README) =================================================================== --- python-commons/tags/0.2/README (rev 0) +++ python-commons/tags/0.2/README 2008-03-03 04:55:33 UTC (rev 584) @@ -0,0 +1,35 @@ +[documentation](doc) + +Overview +-------- + +Python Commons is a general-purpose library for Python. To get a sense of +what it provides, please glance over the [documentation](doc). + +Requirements +------------ + +- [Python](http://python.org/) 2.5 +- [setuptools](http://peak.telecommunity.com/DevCenter/setuptools) 0.6 + +Certain sub-modules have extra requirements: + +- `async` requires [Twisted](http://twistedmatrix.com/trac/) 2.5 +- `files` requires [path](http://www.jorendorff.com/articles/python/path/) 2.2 + +This library has only been tested on Linux. + +Setup +----- + +To install, run `easy_install python-commons`, or download the source tarball +and run `python setup.py install`. + +Related Work +------------ + +- [ASPN Cookbook]: a valuable repository of Python snippets +- [AIMA Utilities]: accompaniment to a popular AI textbook + +[ASPN Cookbook]: http://aspn.activestate.com/ASPN/Cookbook/Python +[AIMA Utilities]: http://aima.cs.berkeley.edu/python/utils.py Copied: python-commons/tags/0.2/publish.bash (from rev 566, python-commons/trunk/publish.bash) =================================================================== --- python-commons/tags/0.2/publish.bash (rev 0) +++ python-commons/tags/0.2/publish.bash 2008-03-03 04:55:33 UTC (rev 584) @@ -0,0 +1,12 @@ +#!/usr/bin/env bash + +post-stage() { + epydoc -o $stagedir/doc src/commons/ +} + +fullname='Python Commons' +version=0.2 +license=psf +websrcs=( README ) +rels=( pypi: ) +. assorted.bash "$@" Deleted: python-commons/tags/0.2/setup.py =================================================================== --- python-commons/trunk/setup.py 2008-02-19 09:09:41 UTC (rev 473) +++ python-commons/tags/0.2/setup.py 2008-03-03 04:55:33 UTC (rev 584) @@ -1,44 +0,0 @@ -#!/usr/bin/env python -# -*- mode: python; tab-width: 4; indent-tabs-mode: nil; py-indent-offset: 4; -*- -# vim:ft=python:et:sw=4:ts=4 - -import os,sys -sys.path.insert( 0, os.path.join( os.path.dirname( sys.argv[0] ), 'src' ) ) -from commons import setup - -pkg_info_text = """ -Metadata-Version: 1.1 -Name: python-commons -Version: 0.2 -Author: Yang Zhang -Author-email: yaaang NOSPAM at REMOVECAPS gmail -Home-page: http://assorted.sourceforge.net/python-commons -Download-url: http://assorted.sourceforge.net/python-commons/download -Summary: Python Commons -License: Python Software Foundation License -Description: General-purpose library of utilities and extensions to the - standard library. -Keywords: Python,common,commons,utility,utilities,library,libraries -Platform: any -Provides: commons -Classifier: Development Status :: 4 - Beta -Classifier: Environment :: No Input/Output (Daemon) -Classifier: Intended Audience :: Developers -Classifier: License :: OSI Approved :: Python Software Foundation License -Classifier: Operating System :: OS Independent -Classifier: Programming Language :: Python -Classifier: Topic :: Communications -Classifier: Topic :: Database -Classifier: Topic :: Internet -Classifier: Topic :: Software Development :: Libraries :: Python Modules -Classifier: Topic :: System -Classifier: Topic :: System :: Filesystems -Classifier: Topic :: System :: Logging -Classifier: Topic :: System :: Networking -Classifier: Topic :: Text Processing -Classifier: Topic :: Utilities -""" - -setup.run_setup( pkg_info_text, - #scripts = ['frontend/py_hotshot.py'], - ) Copied: python-commons/tags/0.2/setup.py (from rev 564, python-commons/trunk/setup.py) =================================================================== --- python-commons/tags/0.2/setup.py (rev 0) +++ python-commons/tags/0.2/setup.py 2008-03-03 04:55:33 UTC (rev 584) @@ -0,0 +1,43 @@ +#!/usr/bin/env python +# -*- mode: python; tab-width: 4; indent-tabs-mode: nil; py-indent-offset: 4; -*- +# vim:ft=python:et:sw=4:ts=4 + +import os,sys +sys.path.insert( 0, os.path.join( os.path.dirname( sys.argv[0] ), 'src' ) ) +from commons import setup + +pkg_info_text = """ +Metadata-Version: 1.1 +Name: python-commons +Version: 0.2 +Author: Yang Zhang +Author-email: yaaang NOSPAM at REMOVECAPS gmail +Home-page: http://assorted.sourceforge.net/python-commons +Summary: Python Commons +License: Python Software Foundation License +Description: General-purpose library of utilities and extensions to the + standard library. +Keywords: Python,common,commons,utility,utilities,library,libraries +Platform: any +Provides: commons +Classifier: Development Status :: 4 - Beta +Classifier: Environment :: No Input/Output (Daemon) +Classifier: Intended Audience :: Developers +Classifier: License :: OSI Approved :: Python Software Foundation License +Classifier: Operating System :: OS Independent +Classifier: Programming Language :: Python +Classifier: Topic :: Communications +Classifier: Topic :: Database +Classifier: Topic :: Internet +Classifier: Topic :: Software Development :: Libraries :: Python Modules +Classifier: Topic :: System +Classifier: Topic :: System :: Filesystems +Classifier: Topic :: System :: Logging +Classifier: Topic :: System :: Networking +Classifier: Topic :: Text Processing +Classifier: Topic :: Utilities +""" + +setup.run_setup( pkg_info_text, + #scripts = ['frontend/py_hotshot.py'], + ) Deleted: python-commons/tags/0.2/src/commons/__init__.py =================================================================== --- python-commons/trunk/src/commons/__init__.py 2008-02-19 09:09:41 UTC (rev 473) +++ python-commons/tags/0.2/src/commons/__init__.py 2008-03-03 04:55:33 UTC (rev 584) @@ -1,48 +0,0 @@ -# -*- mode: python; tab-width: 4; indent-tabs-mode: nil; py-indent-offset: 4; -*- -# vim:ft=python:et:sw=4:ts=4 - -""" -U{Python Commons<http://assorted.sf.net/python-commons>} is a collection of -general-purpose utilities released under the U{PSF -license<http://www.python.org/psf/license.html>} (the same license as what -Python is distributed under). - -You can download the latest releases -U{here<http://assorted.sf.net/python-commons/download>}. To install, -run setup.py or setup.bash. setup.bash requires -U{simple-setup<http://assorted.sf.net/shell-tools/simple-setup>} which -is part of U{shell-tools<http://assorted.sf.net/shell-tools>}. - -@author: Yang Zhang -@copyright: Yang Zhang unless otherwise noted -@license: PSF -""" - -__version__ = ( 0, 2, 0 ) -__all__ = [ 'async', - 'control', - 'decs', - 'environ', - 'exceps', - 'files', - 'interp', - 'log', - 'misc', - 'networking', - 'progress', - 'seqs', - 'servers', - 'startup', - 'strs', - 'structs', - 'threads', - 'trace' ] - -# TODO more resources: -# http://aima.cs.berkeley.edu/python/utils.py -# http://aspn.activestate.com/ASPN/Cookbook/Python -# http://aspn.activestate.com/ASPN/Cookbook/Python?&recipe_status=editors -# http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/413486 -# interesting: -# http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/259174 -# http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/473790 Copied: python-commons/tags/0.2/src/commons/__init__.py (from rev 568, python-commons/trunk/src/commons/__init__.py) =================================================================== --- python-commons/tags/0.2/src/commons/__init__.py (rev 0) +++ python-commons/tags/0.2/src/commons/__init__.py 2008-03-03 04:55:33 UTC (rev 584) @@ -0,0 +1,40 @@ +# -*- mode: python; tab-width: 4; indent-tabs-mode: nil; py-indent-offset: 4; -*- +# vim:ft=python:et:sw=4:ts=4 + +""" +U{Python Commons<http://assorted.sf.net/python-commons>} is a +general-purpose library. + +@author: Yang Zhang +@copyright: Yang Zhang unless otherwise noted +@license: PSF +""" + +__version__ = ( 0, 2, 0 ) +__all__ = [ 'async', + 'control', + 'decs', + 'environ', + 'exceps', + 'files', + 'interp', + 'log', + 'misc', + 'networking', + 'progress', + 'seqs', + 'servers', + 'startup', + 'strs', + 'structs', + 'threads', + 'trace' ] + +# TODO more resources: +# http://aima.cs.berkeley.edu/python/utils.py +# http://aspn.activestate.com/ASPN/Cookbook/Python +# http://aspn.activestate.com/ASPN/Cookbook/Python?&recipe_status=editors +# http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/413486 +# interesting: +# http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/259174 +# http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/473790 Deleted: python-commons/tags/0.2/src/commons/files.py =================================================================== --- python-commons/trunk/src/commons/files.py 2008-02-19 09:09:41 UTC (rev 473) +++ python-commons/tags/0.2/src/commons/files.py 2008-03-03 04:55:33 UTC (rev 584) @@ -1,115 +0,0 @@ -# -*- mode: python; tab-width: 4; indent-tabs-mode: nil; py-indent-offset: 4; -*- -# vim:ft=python:et:sw=4:ts=4 - -""" -File and directory manipulation. - -@var invalid_filename_chars: The characters which are usually -prohibited on most modern file systems. - -@var invalid_filename_chars_regex: A regex character class constructed -from L{invalid_filename_chars}. -""" - -from __future__ import with_statement - -import os, re, tempfile - -from path import path - -def soft_makedirs( path ): - """ - Emulate C{mkdir -p} (doesn't complain if it already exists). - - @param path: The path of the directory to create. - @type path: str - - @raise OSError: If it cannot create the directory. It only - swallows OS error 17. - """ - try: - os.makedirs( path ) - except OSError, ex: - if ex.errno == 17: - pass - else: - raise - -def temp_dir( base_dir_name, do_create_subdir = True ): - """ - Get a temporary directory without polluting top-level /tmp. This follows - Ubuntu's conventions, choosing a temporary directory name based on - the given name plus the user name to avoid user conflicts. - - @param base_dir_name: The "name" of the temporary directory. This - is usually identifies the purpose of the directory, or the - application to which the temporary directory belongs. E.g., if joe - calls passes in C{"ssh-agent"} on a standard Linux/Unix system, - then the full path of the temporary directory will be - C{"/tmp/ssh-agent-joe"}. - @type base_dir_name: str - - @param do_create_subdir: If C{True}, then creates a - sub-sub-directory within the temporary sub-directory (and returns - the path to that). The sub-sub-directory's name is randomized - (uses L{tempfile.mkdtemp}). - @type do_create_subdir: bool - - @return: The path to the temporary (sub-)sub-directory. - @rtype: str - """ - base_dir_name += '-' + os.environ[ 'USER' ] - base_dir = paths.path( tempfile.gettempdir() ) / base_dir_name - soft_makedirs( base_dir ) - if do_create_subdir: - return tempfile.mkdtemp( dir = base_dir ) - else: - return base_dir - -invalid_filename_chars = r'*|\/:<>?' -invalid_filename_chars_regex = r'[*|\\\/:<>?]' - -def cleanse_filename( filename ): - """ - Replaces all problematic characters in a filename with C{"_"}, as - specified by L{invalid_filename_chars}. - - @param filename: The filename to cleanse. - @type filename: str - """ - pattern = invalid_filename_chars_regex - return re.sub( pattern, '_', filename ) - -class disk_double_buffer( object ): - """ - A simple disk double-buffer. One file is for reading, the other is for - writing, and a facility for swapping the two roles is provided. - """ - def __init__( self, path_base, do_persist = True ): - self.paths = map( path, [ path_base + '.0', path_base + '.1' ] ) - self.do_persist = do_persist - self.switch_status = path( path_base + '.switched' ) - if not do_persist or not self.switch_status.exists(): - self.w, self.r = 0, 1 # default - else: - self.w, self.r = 1, 0 - self.reload_files() - def reload_files( self ): - self.writer = file( self.paths[ self.w ], 'w' ) - if not self.paths[ self.r ].exists(): - self.paths[ self.r ].touch() - self.reader = file( self.paths[ self.r ] ) - def switch( self ): - self.close() - if self.do_persist: - if self.w == 0: self.switch_status.touch() - else: self.switch_status.remove() - self.r, self.w = self.w, self.r - self.reload_files() - def write( self, x ): - self.writer.write( x ) - def read( self, len = 8192 ): - return self.reader.read( len ) - def close( self ): - self.reader.close() - self.writer.close() Copied: python-commons/tags/0.2/src/commons/files.py (from rev 567, python-commons/trunk/src/commons/files.py) =================================================================== --- python-commons/tags/0.2/src/commons/files.py (rev 0) +++ python-commons/tags/0.2/src/commons/files.py 2008-03-03 04:55:33 UTC (rev 584) @@ -0,0 +1,115 @@ +# -*- mode: python; tab-width: 4; indent-tabs-mode: nil; py-indent-offset: 4; -*- +# vim:ft=python:et:sw=4:ts=4 + +""" +File and directory manipulation. + +@var invalid_filename_chars: The characters which are usually +prohibited on most modern file systems. + +@var invalid_filename_chars_regex: A regex character class constructed +from L{invalid_filename_chars}. +""" + +from __future__ import with_statement + +import os, re, tempfile + +from path import path + +def soft_makedirs( path ): + """ + Emulate C{mkdir -p} (doesn't complain if it already exists). + + @param path: The path of the directory to create. + @type path: str + + @raise OSError: If it cannot create the directory. It only + swallows OS error 17. + """ + try: + os.makedirs( path ) + except OSError, ex: + if ex.errno == 17: + pass + else: + raise + +def temp_dir( base_dir_name, do_create_subdir = True ): + """ + Get a temporary directory without polluting top-level /tmp. This follows + Ubuntu's conventions, choosing a temporary directory name based on + the given name plus the user name to avoid user conflicts. + + @param base_dir_name: The "name" of the temporary directory. This + is usually identifies the purpose of the directory, or the + application to which the temporary directory belongs. E.g., if joe + calls passes in C{"ssh-agent"} on a standard Linux/Unix system, + then the full path of the temporary directory will be + C{"/tmp/ssh-agent-joe"}. + @type base_dir_name: str + + @param do_create_subdir: If C{True}, then creates a + sub-sub-directory within the temporary sub-directory (and returns + the path to that). The sub-sub-directory's name is randomized + (uses L{tempfile.mkdtemp}). + @type do_create_subdir: bool + + @return: The path to the temporary (sub-)sub-directory. + @rtype: str + """ + base_dir_name += '-' + os.environ[ 'USER' ] + base_dir = path( tempfile.gettempdir() ) / base_dir_name + soft_makedirs( base_dir ) + if do_create_subdir: + return tempfile.mkdtemp( dir = base_dir ) + else: + return base_dir + +invalid_filename_chars = r'*|\/:<>?' +invalid_filename_chars_regex = r'[*|\\\/:<>?]' + +def cleanse_filename( filename ): + """ + Replaces all problematic characters in a filename with C{"_"}, as + specified by L{invalid_filename_chars}. + + @param filename: The filename to cleanse. + @type filename: str + """ + pattern = invalid_filename_chars_regex + return re.sub( pattern, '_', filename ) + +class disk_double_buffer( object ): + """ + A simple disk double-buffer. One file is for reading, the other is for + writing, and a facility for swapping the two roles is provided. + """ + def __init__( self, path_base, do_persist = True ): + self.paths = map( path, [ path_base + '.0', path_base + '.1' ] ) + self.do_persist = do_persist + self.switch_status = path( path_base + '.switched' ) + if not do_persist or not self.switch_status.exists(): + self.w, self.r = 0, 1 # default + else: + self.w, self.r = 1, 0 + self.reload_files() + def reload_files( self ): + self.writer = file( self.paths[ self.w ], 'w' ) + if not self.paths[ self.r ].exists(): + self.paths[ self.r ].touch() + self.reader = file( self.paths[ self.r ] ) + def switch( self ): + self.close() + if self.do_persist: + if self.w == 0: self.switch_status.touch() + else: self.switch_status.remove() + self.r, self.w = self.w, self.r + self.reload_files() + def write( self, x ): + self.writer.write( x ) + def read( self, len = 8192 ): + return self.reader.read( len ) + def close( self ): + self.reader.close() + self.writer.close() Deleted: python-commons/tags/0.2/src/commons/setup.py =================================================================== --- python-commons/trunk/src/commons/setup.py 2008-02-19 09:09:41 UTC (rev 473) +++ python-commons/tags/0.2/src/commons/setup.py 2008-03-03 04:55:33 UTC (rev 584) @@ -1,98 +0,0 @@ -#!/usr/bin/env python -# -*- mode: python; tab-width: 4; indent-tabs-mode: nil; py-indent-offset: 4; -*- -# vim:ft=python:et:sw=4:ts=4 - -""" -Common code for setup.py files. -""" - -arg_keys = """ -name -version -author -author_email -description: Summary -download_url: Download-url -long_description: Description -keywords: Keywords -url: Home-page -license -classifiers: Classifier -platforms: Platform -""" - -import sys -if not hasattr(sys, "version_info") or sys.version_info < (2, 3): - from distutils.core import setup - _setup = setup - def setup(**kwargs): - for key in [ - # distutils >= Python 2.3 args - # XXX probably download_url came in earlier than 2.3 - "classifiers", "download_url", - # setuptools args - "install_requires", "zip_safe", "test_suite", - ]: - if kwargs.has_key(key): - del kwargs[key] - # Only want packages keyword if this is a package, - # only want py_modules keyword if this is a single-file module, - # so get rid of packages or py_modules keyword as appropriate. - if kwargs["packages"] is None: - del kwargs["packages"] - else: - del kwargs["py_modules"] - apply(_setup, (), kwargs) -else: - from setuptools import setup, find_packages - -def run_setup( pkg_info_text, *orig_args, **orig_kwargs ): - list_keys = set( [ 'Classifier' ] ) - pkg_info = {} - for line in pkg_info_text.split( '\n' ): - if line.strip() != '': - if line.startswith( ' '*8 ): - pkg_info[ key ] += line[ 7 : ] - else: - key, value = line.split( ': ', 1 ) - if key in list_keys: - try: - pkg_info[ key ].append( value ) - except: - pkg_info[ key ] = [ value ] - else: - pkg_info[ key ] = value - - args_nontranslations = set() - args_translations = {} - for line in arg_keys.split( '\n' ): - if line.strip() != '': - splitted = line.split( ': ', 1 ) - dest_name = splitted[ 0 ] - if len( splitted ) == 2: - source_name = splitted[ 1 ] - args_translations[ source_name ] = dest_name - else: - args_nontranslations.add( dest_name ) - - args = {} - for key, value in pkg_info.iteritems(): - dest_name = None - try: - dest_name = args_translations[ key ] - except KeyError: - key = key.lower().replace('-','_') - if key in args_nontranslations: - dest_name = key - if dest_name is not None: - args[ dest_name ] = value - - # this also allows user to override our args - args.update( orig_kwargs ) - - setup( *orig_args, - package_dir = {'':'src'}, - packages = find_packages('src'), - zip_safe = True, - **args, - ) Copied: python-commons/tags/0.2/src/commons/setup.py (from rev 567, python-commons/trunk/src/commons/setup.py) =================================================================== --- python-commons/tags/0.2/src/commons/setup.py (rev 0) +++ python-commons/tags/0.2/src/commons/setup.py 2008-03-03 04:55:33 UTC (rev 584) @@ -0,0 +1,98 @@ +#!/usr/bin/env python +# -*- mode: python; tab-width: 4; indent-tabs-mode: nil; py-indent-offset: 4; -*- +# vim:ft=python:et:sw=4:ts=4 + +""" +Common code for setup.py files. +""" + +arg_keys = """ +name +version +author +author_email +description: Summary +download_url: Download-url +long_description: Description +keywords: Keywords +url: Home-page +license +classifiers: Classifier +platforms: Platform +""" + +import sys +if not hasattr(sys, "version_info") or sys.version_info < (2, 3): + from distutils.core import setup + _setup = setup + def setup(**kwargs): + for key in [ + # distutils >= Python 2.3 args + # XXX probably download_url came in earlier than 2.3 + "classifiers", "download_url", + # setuptools args + "install_requires", "zip_safe", "test_suite", + ]: + if kwargs.has_key(key): + del kwargs[key] + # Only want packages keyword if this is a package, + # only want py_modules keyword if this is a single-file module, + # so get rid of packages or py_modules keyword as appropriate. + if kwargs["packages"] is None: + del kwargs["packages"] + else: + del kwargs["py_modules"] + apply(_setup, (), kwargs) +else: + from setuptools import setup, find_packages + +def run_setup( pkg_info_text, *orig_args, **orig_kwargs ): + list_keys = set( [ 'Classifier' ] ) + pkg_info = {} + for line in pkg_info_text.split( '\n' ): + if line.strip() != '': + if line.startswith( ' '*8 ): + pkg_info[ key ] += line[ 7 : ] + else: + key, value = line.split( ': ', 1 ) + if key in list_keys: + try: + pkg_info[ key ].append( value ) + except: + pkg_info[ key ] = [ value ] + else: + pkg_info[ key ] = value + + args_nontranslations = set() + args_translations = {} + for line in arg_keys.split( '\n' ): + if line.strip() != '': + splitted = line.split( ': ', 1 ) + dest_name = splitted[ 0 ] + if len( splitted ) == 2: + source_name = splitted[ 1 ] + args_translations[ source_name ] = dest_name + else: + args_nontranslations.add( dest_name ) + + args = {} + for key, value in pkg_info.iteritems(): + dest_name = None + try: + dest_name = args_translations[ key ] + except KeyError: + key = key.lower().replace('-','_') + if key in args_nontranslations: + dest_name = key + if dest_name is not None: + args[ dest_name ] = value + + # this also allows user to override our args + args.update( orig_kwargs ) + args.update( { + 'package_dir': {'':'src'}, + 'packages': find_packages('src'), + 'zip_safe': True, + } ) + + setup( *orig_args, **args ) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |