Process#
- class emtools.utils.Process(*args, **kwargs)#
- class Logger(logger=None, only_log=False, format='%(asctime)s %(levelname)s %(message)s')#
Use a logger to log commands that are executed via os.system.
- cp(src, dst, retry=None)#
Copy from src to dst.
- mkdir(path, retry=None)#
Make a folder path.
- mv(src, dst, retry=None)#
Move from src to dst.
- rm(path)#
Remove a folder or file.
- system(cmd, retry=None)#
Execute a command and log it.
- Parameters:
cmd – Command string to be executed with os.system
retry – If not None, it should be the time in seconds after which the command will be re-executed on failure until successful completion.
- Returns:
last exit_status from os.system result
- lines()#
Iterate over the lines of the process output.
- static ps(program, workingDir=None, children=False)#
Inspect processes matching a given program name.
- Parameters:
program – string matching the program name
workingDir – if not None, filter processes only with that folder as working directory (cwd)
- static system(cmd, only_print=False, color=None)#
Execute and print a command.
- Parameters:
cmd – Command to be executed.
only_print – If true, the command will only be printed and not executed
color – Optional color for the command
Path#
- class emtools.utils.Path#
Group some path utility functions.
- class ExtDict#
Keep track of number of files and size by extension.
- register(filename, stat=None)#
Register a file, if stat is None it will be calculated.
- update([E, ]**F) None. Update D from dict/iterable E and F. #
If E is present and has a .keys() method, then does: for k in E: D[k] = E[k] If E is present and lacks a .keys() method, then does: for k, v in E: D[k] = v In either case, this is followed by: for k in F: D[k] = F[k]
- static addslash(path)#
Add an slash (/) to the end of the path if not present.
- static copyDir(dir1, dir2, copyFileFunc=None, pl=None, **kwargs)#
This is a test method to copy a whole directory and control the speed of the copy and how files appear in the destination. A custom copyFileFunc can be passed to copy files. If None, Path.copyFile will be used. **kwargs will be passed to copyFile
- static copyFile(file1, file2, sleep=0)#
Copy two files controlling with some possible delay.
- static exists(path)#
Just avoid empty or None path to raise exception from os.path.exists.
- static inSync(dir1, dir2, verbose=False)#
Return True if both dir1 and dir2 are synchronized (i.e. same content) Use rsync as a subprocess to check if the two directories are synchronized. Both directories must exist.
- static lastModified(folder)#
Return the last modified file and modified time.
- static removeBaseExt(filename)#
Take the basename of the filename and remove extension
- static removeExt(filename)#
Remove extension from basename
- static replaceBaseExt(filename, newExt)#
Replace the current basename extension(from last .) with a new one. The new one should not contain the .
- static replaceExt(filename, newExt)#
Replace the current path extension(from last .) with a new one. The new one should not contain the .
- static rmslash(path)#
Remove the slash (/) from the end of the path if present.
System#
- class emtools.utils.System#
- static cpus()#
Return number of CPUs in the system, None if can’t figure it out.
- static gpus()#
Return a dictionary with existing GPUs and their properties.
- static hostname()#
Return the hostname.
- static memory()#
Return the total virtual memory of the system. (in Gb)
- static specs()#
Make an informative summary of the system specs.