pyworkflow.utils.path module
This module contains the PATH related utilities inside the utils module
- pyworkflow.utils.path.backup(fpath)[source]
Create directory “backup” if necessary and back up the file.
- Parameters
fpath –
- Returns
None
- pyworkflow.utils.path.commonPath(*paths)[source]
Return the common longest prefix path. It uses the python os.path.commonprefix and then the direname over it since the former is implemented in char-by-char base.
- pyworkflow.utils.path.copyPattern(pattern, destFolder)[source]
Copy all files matching the pattern to the given destination folder.
- pyworkflow.utils.path.copyTree(source, dest)[source]
Wrapper around the shutil.copytree, but allowing that the dest folder also os.path.exists.
- pyworkflow.utils.path.createLink(source, dest)[source]
Creates a relative link to a given file path. Try to use common path for source and dest to avoid errors. Different relative paths may exist since there are different valid paths for a file, it depends on the current working dir path
- pyworkflow.utils.path.createUniqueFileName(fn)[source]
This function creates a file name that is similar to the original by adding a unique numeric suffix. check NamedTemporaryFile from tempfile for alternatives
- pyworkflow.utils.path.expandPattern(pattern, vars=True, user=True)[source]
Expand environment vars and user from a given pattern.
- pyworkflow.utils.path.findFile(filename, *paths, recursive=False)[source]
Search if a file/folder is present in any of the paths provided.
- Parameters
filename – Name (myfile.txt) of the file to look for.
paths – N number of folders to look at.
recursive – If True it will iterate into the subfolders.
- Returns
None if nothing is found.
- pyworkflow.utils.path.findFileRecursive(filename, path)[source]
Finds a file/folder in a single path recursively
- Parameters
filename – Name (myfile.txt) of the file to look for.
path – folder to start the search from.
- Returns
The absolute path to the ‘filename’ found or None if not found.
- pyworkflow.utils.path.findRootFrom(referenceFile, searchFile)[source]
This method will find a path (root) from ‘referenceFile’ from which the ‘searchFile’ os.path.exists. A practical example of ‘referenceFile’ is a metadata file and ‘searchFile’ is an image to be found from the metadata. Return None if the path is not found.
- pyworkflow.utils.path.getFileLastModificationDate(fn)[source]
Returns the last modification date of a file or None if it doesn’t exist.
- pyworkflow.utils.path.getFiles(folderPath)[source]
Gets all files of given folder and it subfolders. folderPath – Folder path to get files. returns – Set with all folder files.
- pyworkflow.utils.path.getParentFolder(path)[source]
Returns the absolute parent folder of a file or folder. Work for folders that ens with “/” which dirname can’t
- pyworkflow.utils.path.hasChangedSince(fn, time)[source]
- Returns if the file has changed since the timestamp passed as parameter. It will check
the last modified time of the file this set uses to persists.
- Parameters
time – timestamp to compare to the last modification time
- pyworkflow.utils.path.isFileFinished(fn, duration=60)[source]
Returns True if the file (fn) last modification has not changed for 60 seconds (default duration)
- pyworkflow.utils.path.iterBigFile(textfile, offset=0, size=None, maxSize=400, headSize=40, tailSize=None)[source]
Yield lines from file textfile. If the size to read is bigger than maxSize then yield the first lines until headSize bytes, then yield None, then yield the last lines from tailSize bytes to the end.
- pyworkflow.utils.path.makeFilePath(*files)[source]
Make the path to ensure that files can be written.
- pyworkflow.utils.path.makePath(*paths)[source]
Create a list of paths if they don’t os.path.exists. Recursively create all folder needed in a path. If a path passed is a file, only the directory will be created.
- pyworkflow.utils.path.makeTmpPath(protocol)[source]
Create the scratch folder if SCIPION_SCRATCH variable is defined into the Scipion config, i.o.c create tmp folder
- pyworkflow.utils.path.missingPaths(*paths)[source]
Check if the list of paths os.path.exists. Will return the list of missing files, if the list is empty means that all path os.path.exists
- pyworkflow.utils.path.removeBaseExt(filename)[source]
Take the basename of the filename and remove extension
- pyworkflow.utils.path.renderLine(line, add, lineNo=1, numberLines=True)[source]
Find all the fragments of formatted text in line and call add(fragment, tag) for each of them.
- pyworkflow.utils.path.renderTextFile(fname, add, offset=0, lineNo=0, numberLines=True, maxSize=400, headSize=40, tailSize=None, notifyLine=None, errors='strict')[source]
Call callback function add() on each fragment of text from file fname, delimited by lines and/or color codes.
- Parameters
add – callback function with signature (txt, tag=’normal’)
offset – byte offset - we start reading the file from there
lineNo – lines will be numbered from this value on
numberLines – whether to prepend the line numbers