pyworkflow.utils.path module¶
This module contains the PATH related utilities inside the utils module
- 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, **kwargs)[source]¶
Search if the file is present in some path in the *paths provided. Return None if not found. ‘recursive’ can be passed in kwargs to iterate into subfolders.
- 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.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.
add: callback function add(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