Path Tools

This module defines functions for handling files and paths.

gunzip(filename, outname=None)[source]

Returns output name that contains decompressed contents of filename. When no outname is given, filename is used as the output name as it is or after .gz extension is removed. filename may also be a string buffer, in which case decompressed string buffer or outname that contains buffer will be returned.

backupFile(filename, backup=None, backup_ext='.BAK', **kwargs)[source]

Rename filename with backup_ext appended to its name for backup purposes, if backup is True or if automatic backups is turned on using confProDy(). Default extension .BAK is used when one is not set using confProDy(). If filename does not exist, no action will be taken and filename will be returned. If file is successfully renamed, new filename will be returned.

openFile(filename, *args, **kwargs)[source]

Open filename for reading, writing, or appending. First argument in args is treated as the mode. Opening .gz and .zip files for reading and writing is handled automatically.

Parameters:
  • backup (bool) – backup existing file using backupFile() when opening in append or write modes, default is obtained from package settings
  • backup_ext (str) – extension for backup file, default is .BAK
openDB(filename, *args)[source]

Open a database with given filename.

openSQLite(filename, *args)[source]

Returns a connection to SQLite database filename. If 'n' argument is passed, remove any existing databases with the same name and return connection to a new empty database.

openURL(url, timeout=5, **kwargs)[source]

Open url for reading. Raise an IOError if url cannot be reached. Small timeout values are suitable if url is an ip address. kwargs will be used to make urllib.request.Request instance for opening the url.

copyFile(src, dst)[source]

Returns dst, a copy of src.

isExecutable(path)[source]

Returns true if path is an executable.

isReadable(path)[source]

Returns true if path is readable by the user.

isWritable(path)[source]

Returns true if path is writable by the user.

makePath(path)[source]

Make all directories that does not exist in a given path.

relpath(path)[source]

Returns path on Windows, and relative path elsewhere.

sympath(path, beg=2, end=1, ellipsis='...')[source]

Returns a symbolic path for a long path, by replacing folder names in the middle with ellipsis. beg and end specified how many folder (or file) names to include from the beginning and end of the path.

which(program)[source]

This function is based on the example in: http://stackoverflow.com/questions/377017/

pickle(obj, filename, protocol=2, **kwargs)[source]

Pickle obj using pickle.dump() in filename. protocol is set to 2 for compatibility between Python 2 and 3.

unpickle(filename, **kwargs)[source]

Unpickle object in filename using pickle.load().

glob(*pathnames)[source]

Returns concatenation of ordered lists of paths matching patterns in pathnames.

addext(filename, extension)[source]

Returns filename, with extension if it does not have one.