3.13. sciexp2.common.utils
Source: sciexp2/common/utils.py
Common utility classes and functions.
Functions
Check that given directory exists, otherwise create it. |
|
Raise an exception if extra keys are present. |
|
Check that given path exists, otherwise create directories. |
|
Copy files. |
|
Copy contents using Python's shutil. |
|
Execute a command and forward SIGINT to it. |
|
Find files matching a given template. |
|
Open the given file, creating any intermediate directory. |
|
Get path after expanding user and environment variables. |
|
Get a temporal file. |
|
Return numeric value of a string, if possible. |
Classes
A mutable set preserving order of insertion. |
Exceptions
|
Invalid operation in |
3.13.2. assert_dir
- assert_dir(path)
Check that given directory exists, otherwise create it.
3.13.3. assert_kwargs
- assert_kwargs(kwargs)
Raise an exception if extra keys are present.
3.13.4. assert_path
- assert_path(path)
Check that given path exists, otherwise create directories.
3.13.5. copy_path
- copy_path(path_from, path_to, preserve=True, dereference=False)
Copy files.
3.13.6. copy_path_shutil
- copy_path_shutil(path_from, path_to, preserve=True, dereference=False)
Copy contents using Python’s shutil.
3.13.7. execute_with_sigint
- execute_with_sigint(cmd, **kwargs)
Execute a command and forward SIGINT to it.
- Parameters:
- cmdlist of string
Command to execute
- kwargsdict
Additional arguments to subprocess.Popen.
- Returns:
- Integer with the command’s return code.
3.13.8. find_files
- find_files(template, path=None, absolute_path=False, sort=True)
Find files matching a given template.
Returns an ‘InstanceGroup’ with all paths of existing files matching the given template. Each matching file path is an Instance with the extracted variables in the template.
- Parameters:
- templatestr
Template of file paths to find.
- pathstr, optional
On each resulting Instance, add a variable with the given name with the file path.
- absolute_pathbool, optional
Make the value in path absolute.
- sortbool, optional
Sort the file paths according to the alphanumeric order of each of the variables in template, in that specific order.
- Raises:
- ValueError
The variable in path is already present in template.
See also
sciexp2.common.text.extract
Argument template is interpreted following the extraction syntax.
Notes
If template ends with
/
it will search for matching paths, and will search for matching files otherwise.Environment variables and user home directories in template will be expanded.
3.13.9. get_file
- get_file(path, mod='w')
Open the given file, creating any intermediate directory.
3.13.10. get_path
- get_path(path)
Get path after expanding user and environment variables.
3.13.11. get_tmp_file
- get_tmp_file(mode='w', delete=True)
Get a temporal file.
3.13.12. str2num
- str2num(arg)
Return numeric value of a string, if possible.