Package XPyLIB :: Module pckgmisc
[hide private]
[frames] | no frames]

Source Code for Module XPyLIB.pckgmisc

 1  #!/usr/bin/env python
 
 2  # -*- coding: utf-8 -*-
 
 3  #--------------------------------------------------------------------
 
 4  # Author: Mazhugin Aleksey
 
 5  # Created: 2007/09/25
 
 6  # ID: $Id: XPyLIB.pckgmisc-pysrc.html 24 2008-12-01 17:51:12Z alex $
 
 7  # URL: $URL: file:///myfiles/svn_/XPyLIB/trunc/doc/html/XPyLIB.pckgmisc-pysrc.html $
 
 8  # Copyright: Copyright (c) 2007, Mazhugin Aleksey
 
 9  # License: BSD
 
10  #--------------------------------------------------------------------
 
11  
 
12  """
 
13  Miscelaneous functions for packages.
 
14  """ 
15  
 
16  import inspect 
17  import os 
18  
 
19 -def GetObjectDocs(obj):
20 """ 21 Return first docs strings from objects item. 22 23 @param obj: Object to introspection. 24 Item may be modules, classes, functions. 25 @type obj: object 26 @note: Get docs for all objects, include imported. 27 @return: First docs strings from objects item. 28 @rtype: string 29 """ 30 d='\n'.join([name + ' - ' + str(inspect.getdoc(value)).split('\n')[0] 31 for name, value in inspect.getmembers(obj, 32 lambda m: inspect.ismodule(m) or inspect.isclass(m) or 33 inspect.isfunction(m)) ]) 34 return d
35
36 -def ExtendPaths(sPath, *lRelPaths):
37 """ 38 Combine sPath to each path from relative path list. 39 40 @param sPath: List with item[0] = base path. 41 It's list will be extended. 42 B{[in/out]} parametr. 43 @type sPath: list 44 @param lRelPaths: Arguments list of relative paths. 45 @type lRelPaths: *string 46 @return: Combined C{sPath} to each path from relative path list in the 47 B{sPath}. 48 @rtype: None 49 """ 50 sPath.extend([os.path.join(sPath[0], item) for item in lRelPaths])
51
52 -def cutarch(path, arch='.zip'):
53 """ 54 If path C{path} end with C{arch} file then remove this file and return 55 path without C{arch}. 56 57 For define archive test ends of path and if it equal arch then archive is defined. 58 59 For example if C{path = 'c:/lib/pack.zip'} then return C{'c:/lib'}. 60 61 @param path: Path. 62 @type path: str 63 @param arch: Archive type. 64 @type arch: str = {'.zip'} 65 @return: Path without archive at end. 66 @rtype: str 67 """ 68 if path.endswith(arch): 69 path = os.path.dirname(path) 70 return path
71