hashdist.core.links
— Link creation tool¶
execute_links_dsl()
takes a set of rules in a mini-language and
uses it to create (a potentially large number of) links.
The following rules creates links to everything in “/usr/bin”, except for “/usr/bin/gcc-4.6” which is copied (though it could be achieved more easily with the overwrite flag):
[
{
"action": "copy",
"source": "/usr/bin/gcc-4.6",
"target": "$ARTIFACT/bin/gcc-4.6"
},
{
"action": "exclude",
"select": ["/usr/bin/gcc-4.6", "/something/else/too/**"]
},
{
"action": "symlink",
"select": "/usr/bin/*",
"prefix": "/usr",
"target": "$ARTIFACT"
}
]
Rules are executed in order. If a target file already exists, nothing happens.
- action:
One of “symlink”, “absolute_symlink”, “relative_symlink”, “copy”, “exclude”, “launcher”. Other types may be added later.
- absolute_symlink creates absolute symlinks. Just symlink is an alias for absolute symlink.
- relative_symlink creates relative symlinks
- copy copies contents and mode (
shutil.copy
) - exclude makes sure matching files are not considered in rules below
- launcher, see
make_launcher()
- select, prefix:
select contains glob of files to link/copy/exclude. This is in ant-glob format (see
hashdist.core.ant_glob
). If select is given and action is not exclude, one must also supply a prefix (possibly empty string) which will be stripped from each matching path, before recreating the same hierarchy beneath target.Variable substitution is performed both in select and prefix. select and prefix should either both be absolute paths or both be relative paths
- source:
- Provide an exact filename instead of a glob. In this case target should refer to the exact filename of the resulting link/copy.
- target:
- Target filename (source is used) or directory (select is used). Variable substitution is performed.
- dirs:
- If present and True, symlink matching directories, not only files. Only takes effect for select; source always selectes dirs.
- overwrite:
- If present and True, overwrite target.
-
hashdist.core.links.
dry_run_links_dsl
(rules, env={})¶ Turns a DSL for creating links/copying files into a list of actions to be taken.
This takes into account filesystem contents and current directory at the time of call.
See
execute_links_dsl()
for information on the DSL.Parameters: rules : list
List of rules as described in
execute_links_dsl()
.env : dict
Environment to use for variable substitution
Returns: actions : list
What actions should be performed as a list of (func,) + args_to_pass, where func is one of os.symlink,
silent_makedirs()
, shutil.copyfile.
-
hashdist.core.links.
execute_links_dsl
(rules, env={}, launcher_program=None, logger=None)¶ Executes the links DSL for linking/copying files
The input is a set of rules which will be applied in order. The rules are documented above.
Parameters: spec : list
List of rules as described above.
env : dict
Environment to use for variable substitution.
launcher_program : str or None
If the ‘launcher’ action is used, the path to the launcher executable must be provided.
logger : Logger or
None
(default)
-
hashdist.core.links.
make_launcher
(src, dst, launcher_program)¶ The ‘launcher’ action. This is a general tool for processing bin-style directories where the binaries must have a “fake” argv[0] target (read: Python). The action depends on the source type:
- program (i.e., executable not starting with #!):
- Set up as symlink to “launcher”, which is copied into same directory; and “$dst.link” is set up to point relatively to “$src”.
- symlink:
- Copy it verbatim. Thus, e.g.,
python -> python2.7
will point to the newly, “launched-ified”python2.7
. - other (incl. scripts):
- Symlink relatively to it.