Revision: 4288 Author: russblau Date: 2007-09-14 16:14:31 +0000 (Fri, 14 Sep 2007)
Log Message: ----------- Add docstring; actually return an absolute path
Modified Paths: -------------- trunk/pywikipedia/wikipediatools.py
Modified: trunk/pywikipedia/wikipediatools.py =================================================================== --- trunk/pywikipedia/wikipediatools.py 2007-09-14 14:16:07 UTC (rev 4287) +++ trunk/pywikipedia/wikipediatools.py 2007-09-14 16:14:31 UTC (rev 4288) @@ -1,18 +1,28 @@ -__version__ = '$Id$' +__version__ = '$Id$' import os, sys
def absoluteFilename(*f): + """Return an absolute path to the filename given as argument; + optionally a directory may be given as the first argument and + filename as the second. + The path is based on the directory from which the script is being + run, if it contains a 'user-config.py' file; otherwise on the directory + from which this module was loaded. + """ if os.path.exists('user-config.py'): #There's config in the current directory, so assume login-data etc will be here as well - return os.path.join('.',*f) - try: - mod = sys.modules['wikipediatools'] - except KeyError: - print sys.modules - location = None + location = "." else: - path = mod.__file__ - location = os.path.split(path)[0] + try: + mod = sys.modules['wikipediatools'] + except KeyError: + print sys.modules + location = None + else: + path = mod.__file__ + location = os.path.split(path)[0] if not location: location='.' + if not os.path.isabs(location): + location = os.path.normpath(os.path.join(os.getcwd(), location)) return os.path.join(location,*f)
pywikipedia-l@lists.wikimedia.org