file
The uw mode for handling filesystem files.
uw file --help
usage: uw file [-h] [--version] ACTION ...
Handle files
Optional arguments:
-h, --help
Show help and exit
--version
Show version info and exit
Positional arguments:
ACTION
copy
Copy files
link
Link files
copy
The copy action stages files in a target directory by copying files. Any KEY positional arguments are used to navigate, in the order given, from the top of the config to the file block.
uw file copy --help
usage: uw file copy [-h] [--version] [--config-file PATH] [--target-dir PATH]
[--cycle CYCLE] [--leadtime LEADTIME] [--dry-run]
[--quiet] [--verbose]
[KEY ...]
Copy files
Optional arguments:
-h, --help
Show help and exit
--version
Show version info and exit
--config-file PATH, -c PATH
Path to UW YAML config file (default: read from stdin)
--target-dir PATH
Root directory for relative destination paths
--cycle CYCLE
The cycle in ISO8601 format (e.g. 2024-05-29T12)
--leadtime LEADTIME
The leadtime as hours[:minutes[:seconds]]
--dry-run
Only log info, making no changes
--quiet, -q
Print no logging messages
--verbose, -v
Print all logging messages
KEY
YAML key leading to file dst/src block
Examples
Given copy-config.yaml containing
config:
files:
foo: src/foo
subdir/bar: src/bar
rm -rf copy-dst
uw file copy --target-dir copy-dst --config-file copy-config.yaml config files
echo
tree copy-dst
[2024-08-02T00:43:08] INFO Validating config against internal schema: files-to-stage
[2024-08-02T00:43:08] INFO 0 UW schema-validation errors found
[2024-08-02T00:43:08] INFO File copies: Initial state: Not Ready
[2024-08-02T00:43:08] INFO File copies: Checking requirements
[2024-08-02T00:43:08] INFO Copy src/foo -> copy-dst/foo: Initial state: Not Ready
[2024-08-02T00:43:08] INFO Copy src/foo -> copy-dst/foo: Checking requirements
[2024-08-02T00:43:08] INFO Copy src/foo -> copy-dst/foo: Requirement(s) ready
[2024-08-02T00:43:08] INFO Copy src/foo -> copy-dst/foo: Executing
[2024-08-02T00:43:08] INFO Copy src/foo -> copy-dst/foo: Final state: Ready
[2024-08-02T00:43:08] INFO Copy src/bar -> copy-dst/subdir/bar: Initial state: Not Ready
[2024-08-02T00:43:08] INFO Copy src/bar -> copy-dst/subdir/bar: Checking requirements
[2024-08-02T00:43:08] INFO Copy src/bar -> copy-dst/subdir/bar: Requirement(s) ready
[2024-08-02T00:43:08] INFO Copy src/bar -> copy-dst/subdir/bar: Executing
[2024-08-02T00:43:08] INFO Copy src/bar -> copy-dst/subdir/bar: Final state: Ready
[2024-08-02T00:43:08] INFO File copies: Final state: Ready
copy-dst
├── foo
└── subdir
└── bar
2 directories, 2 files
Here, foo and bar are copies of their respective source files.
The --cycle and --leadtime options can be used to make Python datetime and timedelta objects, respectively, available for use in Jinja2 expression in the config. For example:
config:
files:
baz-{{ validtime }}: src/{{ yyyymmdd }}/{{ hh }}/{{ nnn }}/baz
yyyymmdd: "{{ cycle.strftime('%Y%m%d') }}"
hh: "{{ cycle.strftime('%H') }}"
nnn: "{{ '%03d' % (leadtime.total_seconds() // 3600) }}"
validtime: "{{ (cycle + leadtime).strftime('%Y-%m-%dT%H') }}"
rm -rf copy-dst-timedep
uw file copy --target-dir copy-dst-timedep --config-file copy-config-timedep.yaml --cycle 2024-05-29T12 --leadtime 6 config files
echo
tree copy-dst-timedep
[2024-08-02T00:43:08] INFO Validating config against internal schema: files-to-stage
[2024-08-02T00:43:08] INFO 0 UW schema-validation errors found
[2024-08-02T00:43:08] INFO File copies: Initial state: Not Ready
[2024-08-02T00:43:08] INFO File copies: Checking requirements
[2024-08-02T00:43:08] INFO Copy src/20240529/12/006/baz -> copy-dst-timedep/baz-2024-05-29T18: Initial state: Not Ready
[2024-08-02T00:43:08] INFO Copy src/20240529/12/006/baz -> copy-dst-timedep/baz-2024-05-29T18: Checking requirements
[2024-08-02T00:43:08] INFO Copy src/20240529/12/006/baz -> copy-dst-timedep/baz-2024-05-29T18: Requirement(s) ready
[2024-08-02T00:43:08] INFO Copy src/20240529/12/006/baz -> copy-dst-timedep/baz-2024-05-29T18: Executing
[2024-08-02T00:43:08] INFO Copy src/20240529/12/006/baz -> copy-dst-timedep/baz-2024-05-29T18: Final state: Ready
[2024-08-02T00:43:08] INFO File copies: Final state: Ready
copy-dst-timedep
└── baz-2024-05-29T18
1 directory, 1 file
The --target-dir option is optional when all destination paths are absolute, and will never be applied to absolute destination paths. If any destination paths are relative, however, it is an error not to provide a target directory:
config:
files:
foo: src/foo
subdir/bar: src/bar
uw file copy --config-file copy-config.yaml config files
[2024-07-26T21:51:23] ERROR Relative path 'foo' requires the target directory to be specified
link
The link action stages files in a target directory by linking files, directories, or other symbolic links. Any KEY positional arguments are used to navigate, in the order given, from the top of the config to the file block.
uw file link --help
usage: uw file link [-h] [--version] [--config-file PATH] [--target-dir PATH]
[--cycle CYCLE] [--leadtime LEADTIME] [--dry-run]
[--quiet] [--verbose]
[KEY ...]
Link files
Optional arguments:
-h, --help
Show help and exit
--version
Show version info and exit
--config-file PATH, -c PATH
Path to UW YAML config file (default: read from stdin)
--target-dir PATH
Root directory for relative destination paths
--cycle CYCLE
The cycle in ISO8601 format (e.g. 2024-05-29T12)
--leadtime LEADTIME
The leadtime as hours[:minutes[:seconds]]
--dry-run
Only log info, making no changes
--quiet, -q
Print no logging messages
--verbose, -v
Print all logging messages
KEY
YAML key leading to file dst/src block
Examples
Given link-config.yaml containing
config:
files:
foo: src/foo
subdir/bar: src/bar
rm -rf link-dst
uw file link --target-dir link-dst --config-file link-config.yaml config files
echo
tree link-dst
[2024-08-02T00:43:08] INFO Validating config against internal schema: files-to-stage
[2024-08-02T00:43:08] INFO 0 UW schema-validation errors found
[2024-08-02T00:43:08] INFO File links: Initial state: Not Ready
[2024-08-02T00:43:08] INFO File links: Checking requirements
[2024-08-02T00:43:08] INFO Link link-dst/foo -> src/foo: Initial state: Not Ready
[2024-08-02T00:43:08] INFO Link link-dst/foo -> src/foo: Checking requirements
[2024-08-02T00:43:08] INFO Link link-dst/foo -> src/foo: Requirement(s) ready
[2024-08-02T00:43:08] INFO Link link-dst/foo -> src/foo: Executing
[2024-08-02T00:43:08] INFO Link link-dst/foo -> src/foo: Final state: Ready
[2024-08-02T00:43:08] INFO Link link-dst/subdir/bar -> src/bar: Initial state: Not Ready
[2024-08-02T00:43:08] INFO Link link-dst/subdir/bar -> src/bar: Checking requirements
[2024-08-02T00:43:08] INFO Link link-dst/subdir/bar -> src/bar: Requirement(s) ready
[2024-08-02T00:43:08] INFO Link link-dst/subdir/bar -> src/bar: Executing
[2024-08-02T00:43:08] INFO Link link-dst/subdir/bar -> src/bar: Final state: Ready
[2024-08-02T00:43:08] INFO File links: Final state: Ready
link-dst
├── foo -> ../src/foo
└── subdir
└── bar -> ../../src/bar
2 directories, 2 files
Here, foo and bar are symbolic links.
The --cycle and --leadtime options can be used to make Python datetime and timedelta objects, respectively, available for use in Jinja2 expression in the config. For example:
config:
files:
baz-{{ validtime }}: src/{{ yyyymmdd }}/{{ hh }}/{{ nnn }}/baz
yyyymmdd: "{{ cycle.strftime('%Y%m%d') }}"
hh: "{{ cycle.strftime('%H') }}"
nnn: "{{ '%03d' % (leadtime.total_seconds() // 3600) }}"
validtime: "{{ (cycle + leadtime).strftime('%Y-%m-%dT%H') }}"
rm -rf link-dst-timedep
uw file link --target-dir link-dst-timedep --config-file link-config-timedep.yaml --cycle 2024-05-29T12 --leadtime 6 config files
echo
tree link-dst-timedep
[2024-08-02T00:43:09] INFO Validating config against internal schema: files-to-stage
[2024-08-02T00:43:09] INFO 0 UW schema-validation errors found
[2024-08-02T00:43:09] INFO File links: Initial state: Not Ready
[2024-08-02T00:43:09] INFO File links: Checking requirements
[2024-08-02T00:43:09] INFO Link link-dst-timedep/baz-2024-05-29T18 -> src/20240529/12/006/baz: Initial state: Not Ready
[2024-08-02T00:43:09] INFO Link link-dst-timedep/baz-2024-05-29T18 -> src/20240529/12/006/baz: Checking requirements
[2024-08-02T00:43:09] INFO Link link-dst-timedep/baz-2024-05-29T18 -> src/20240529/12/006/baz: Requirement(s) ready
[2024-08-02T00:43:09] INFO Link link-dst-timedep/baz-2024-05-29T18 -> src/20240529/12/006/baz: Executing
[2024-08-02T00:43:09] INFO Link link-dst-timedep/baz-2024-05-29T18 -> src/20240529/12/006/baz: Final state: Ready
[2024-08-02T00:43:09] INFO File links: Final state: Ready
link-dst-timedep
└── baz-2024-05-29T18 -> ../src/20240529/12/006/baz
1 directory, 1 file
The --target-dir option is optional when all linkname paths are absolute, and will never be applied to absolute linkname paths. If any linkname paths are relative, however, it is an error not to provide a target directory:
config:
files:
foo: src/foo
subdir/bar: src/bar
uw file link --config-file link-config.yaml config files
[2024-07-26T21:51:23] ERROR Relative path 'foo' requires the target directory to be specified