caosadvancedtools.loadFiles module#

Utilities to make the LinkAhead server aware of files.

Installation of caosadvancedtools also creates an executable script linkahead-loadfiles which calls the loadpath function. Get the full help with linkahead-loadfiles --help. In short, that script tells the LinkAhead server to create FILE entities for existing files in one branch of the directory tree. It is necessary that this directory is already visible for the server (for example because it is defined as extroot in the LinkAhead profile).

caosadvancedtools.loadFiles.combine_ignore_files(caosdbignore: str, localignore: str, dirname=None) str#

Append the contents of localignore to caosdbignore, save the result, and return the name.

Parameters:
  • caosdbignore (str) – Path to parent level caosdbignore file

  • localignore (str) – Path to current working directory’s local caosdbignore.

  • dirname (str, optional) – The path of the directory to which the temporary combined file is written. If None is given, NamedTemporaryFile’s default is used. Default is None.

Returns:

name – Name of the temporary combined caosdbignore file.

Return type:

str

caosadvancedtools.loadFiles.compile_file_list(caosdbignore: str, localpath: str) list[str]#

Create a list of files that contain all files under localpath except those excluded by caosdbignore.

Parameters:
  • caosdbignore (str) – Path of caosdbignore file

  • localpath (str) – Path of the directory from which the file list will be compiled.

Returns:

file_list – List of files in localpath after appling the ignore rules from caosdbignore.

Return type:

list[str]

caosadvancedtools.loadFiles.convert_size(size: int)#

Convert size from bytes to a human-readable file size in KB, MB, …

caosadvancedtools.loadFiles.create_re_for_file_list(files: list[str], localroot: str, remoteroot: str) str#

Create a regular expression that matches file paths contained in the files argument and all parent directories. The prefix localroot is replaced by the prefix `remoteroot.

Parameters:
  • files (list[str]) – List of file paths to be converted to a regular expression.

  • localroot (str) – Prefix (of the local directory root) to be removed from the paths in files.

  • remoteroot (str) – Prefix (of the LinkAhead filesystem’s directory root) to be prepended to the file paths after the removal of the localroot prefix.

Returns:

regexp – Regular expression that matches all file paths from files adapted for the remote directory root.

Return type:

str

caosadvancedtools.loadFiles.loadpath(path: str, include: str | None, exclude: str | None, prefix: str, dryrun: bool, forceAllowSymlinks: bool, caosdbignore: str | None = None, localpath: str | None = None)#

Make all files in path available to the LinkAhead server as FILE entities.

Notes

Run linkahead-loadfiles --help for more information and examples.

Parameters:
  • path (str) – Path to the directory the files of which are to be made available as seen by the linkahead server (i.e., the path from within the Docker container in a typical LinkAhead Control setup.)

  • include (str or None) – Regular expression matching the files that will be included. If None, all files are matched. This is ignored if a caosdbignore is provided.

  • exclude (str or None) – Regular expression matching files that are to be included.

  • prefix (str) – The prefix under which the files are to be inserted into LinkAhead’s file system.

  • dryrun (bool) – Whether a dryrun should be performed.

  • forceAllowSymlinks (bool) – Whether symlinks in the path to be inserted should be processed.

  • caosdbignore (str, optional) – Path to a caosdbignore file that defines which files shall be included and which do not. The syntax is the same as in a gitignore file. You must also provide the localpath option since the check is done locally. If this is given, any include is ignored.

  • localpath (str, optional) – Path of path on the local machine. Only needed in combination with a caosdbignore file since that is processed locally.

caosadvancedtools.loadFiles.main(argv=None)#

Run loadpath with the arguments specified on the command line, extended by the optional argv parameter. See --help for more information.