Path Tools
This module defines functions for handling files and paths.
- prody.utilities.pathtools.addext(filename, extension)[source]
Returns filename, with extension if it does not have one.
- prody.utilities.pathtools.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.BAKis used when one is not set usingconfProDy(). 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.
- prody.utilities.pathtools.glob(*pathnames)[source]
Returns concatenation of ordered lists of paths matching patterns in pathnames.
- prody.utilities.pathtools.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
.gzextension is removed. filename may also be a string buffer, in which case decompressed string buffer or outname that contains buffer will be returned.
- prody.utilities.pathtools.makePath(path)[source]
Make all directories that does not exist in a given path.
- prody.utilities.pathtools.openFile(filename, *args, **kwargs)[source]
Open filename for reading, writing, or appending. First argument in args is treated as the mode. Opening
.gzand.zipfiles 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 settingsbackup_ext (str) – extension for backup file, default is
.BAK
- prody.utilities.pathtools.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.
- prody.utilities.pathtools.openURL(url, timeout=5, **kwargs)[source]
Open url for reading. Raise an
IOErrorif url cannot be reached. Small timeout values are suitable if url is an ip address. kwargs will be used to makeurllib.request.Requestinstance for opening the url.
- prody.utilities.pathtools.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.
- prody.utilities.pathtools.relpath(path)[source]
Returns path on Windows, and relative path elsewhere.
- prody.utilities.pathtools.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.
- prody.utilities.pathtools.unpickle(filename, **kwargs)[source]
Unpickle object in filename using
pickle.load().
- prody.utilities.pathtools.which(program)[source]
This function is based on the example in: http://stackoverflow.com/questions/377017/