Skip to content

Commit

Permalink
Merge pull request #165 from epics-containers/fix-extract-assets
Browse files Browse the repository at this point in the history
allow globbed extras
  • Loading branch information
gilesknap authored Jan 19, 2024
2 parents 0ba257f + 996b3b1 commit 8cf6e50
Show file tree
Hide file tree
Showing 11 changed files with 31 additions and 15 deletions.
18 changes: 15 additions & 3 deletions src/ibek/ioc_cmds/assets.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,13 @@ def move_file(src: Path, dest: Path, binary: List[str]):
subprocess.call(["bash", "-c", cmd])


def extract_assets(destination: Path, source: Path, extras: List[Path], defaults: bool):
def extract_assets(
destination: Path,
source: Path,
extras: List[Path],
defaults: bool,
dry_run: bool = False,
):
"""
extract and copy runtime assets from a completed developer stage container
"""
Expand Down Expand Up @@ -82,13 +88,19 @@ def extract_assets(destination: Path, source: Path, extras: List[Path], defaults
src = module / asset
if src.exists():
dest_file = destination_module / asset.relative_to(module)
move_file(src, dest_file, binary)
if dry_run:
typer.echo(f"Would move {src} to {dest_file} with {binary}")
else:
move_file(src, dest_file, binary)

extra_files = default_assets + extras
for asset in extra_files:
src = source / asset
if src.exists():
dest_file = destination / asset.relative_to("/")
move_file(src, dest_file, binary)
if dry_run:
typer.echo(f"Would move extra asset {src} to {dest_file} with {binary}")
else:
move_file(src, dest_file, binary)
else:
raise RuntimeError(f"extra runtime asset {src} missing")
5 changes: 3 additions & 2 deletions src/ibek/ioc_cmds/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,13 @@ def extract_runtime_assets(
...,
help="The root folder to extract assets into",
),
extras: List[Path] = typer.Argument(None, help="list of files to also extract"),
source: Path = typer.Option(
Path("/epics"),
help="The root folder to extract assets from",
),
extras: List[Path] = typer.Option(None, help="list of files to also extract"),
defaults: bool = typer.Option(True, help="copy the default assets"),
dry_run: bool = typer.Option(False, help="show what would happen"),
):
"""
Find all the runtime assets in an EPICS installation and copy them to a
Expand All @@ -97,4 +98,4 @@ def extract_runtime_assets(
This should be performed in a throw away container stage (runtime_prep)
as it is destructive of the source folder, because it uses move for speed.
"""
extract_assets(destination, source, extras, defaults)
extract_assets(destination, source, extras, defaults, dry_run)
4 changes: 3 additions & 1 deletion src/ibek/runtime_cmds/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,9 @@ def generate_pvi(ioc: IOC) -> Tuple[List[IndexEntry], List[Tuple[Database, Entit
formatted_pvi_devices.append(device_name)

if entity_pvi.index:
index_entries.append(IndexEntry(device_name, device_bob.name, macros))
index_entries.append(
IndexEntry(label=device_name, ui=device_bob.name, macros=macros)
)

return index_entries, databases

Expand Down
3 changes: 2 additions & 1 deletion src/ibek/support_cmds/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,8 @@ def generate_links(
support_globals = folder / ".." / IBEK_GLOBALS

symlink_files(folder, SUPPORT_YAML_PATTERN, IBEK_DEFS)
symlink_files(support_globals, SUPPORT_YAML_PATTERN, IBEK_DEFS)
if support_globals.exists():
symlink_files(support_globals, SUPPORT_YAML_PATTERN, IBEK_DEFS)
symlink_files(folder, PVI_YAML_PATTERN, PVI_DEFS)


Expand Down
2 changes: 1 addition & 1 deletion tests/generate_samples.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ mkdir -p outputs
set -ex

mkdir -p epics/pvi-defs
cp support/simple.pvi.device.yaml epics/pvi-defs/simple.pvi.device.yaml
cp support/simple.pvi.device.yaml epics/pvi-defs/Simple.pvi.device.yaml

echo making the support yaml schema
ibek support generate-schema --output schemas/ibek.support.schema.json
Expand Down
File renamed without changes.
6 changes: 3 additions & 3 deletions tests/samples/outputs/index.bob
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
</widget>
<widget type="label" version="2.0.0">
<name>Label</name>
<text>imple</text>
<text>Simple</text>
<x>23</x>
<y>30</y>
<width>115</width>
Expand All @@ -37,15 +37,15 @@
<name>OpenDisplay</name>
<actions>
<action type="open_display">
<file>simple.pvi.bob</file>
<file>Simple.pvi.bob</file>
<target>tab</target>
<description>Open Display</description>
<macros>
<prefix>IBEK-MO-TST-01::</prefix>
</macros>
</action>
</actions>
<text>imple</text>
<text>Simple</text>
<x>143</x>
<y>30</y>
<width>125</width>
Expand Down
2 changes: 1 addition & 1 deletion tests/samples/outputs/motorSim.ioc.subst
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pattern
{ "IBEK-MO-TST-01:", "3", "asynMotor", "controllerOne", "2", "CS Motor 2", "degrees", "0", "10.0", "10.0", ".01", "20000", "-20000", "" }
}

file "simple.pvi.template" {
file "Simple.pvi.template" {
pattern
{ "prefix" }
{ "IBEK-MO-TST-01::" }
Expand Down
2 changes: 1 addition & 1 deletion tests/samples/support/motorSim.ibek.support.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ defs:
DESC:

pvi:
yaml_path: simple.pvi.device.yaml
yaml_path: Simple.pvi.device.yaml
prefix: "{{P}}:"
pva_template: true
index: true
Expand Down
4 changes: 2 additions & 2 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ def test_build_runtime_motorSim(tmp_path: Path, samples: Path):
actual_index = (samples / "epics" / "opi" / "index.bob").read_text()
assert example_index == actual_index

example_pvi = (samples / "outputs" / "simple.pvi.bob").read_text()
actual_pvi = (samples / "epics" / "opi" / "simple.pvi.bob").read_text()
example_pvi = (samples / "outputs" / "Simple.pvi.bob").read_text()
actual_pvi = (samples / "epics" / "opi" / "Simple.pvi.bob").read_text()
assert example_pvi == actual_pvi


Expand Down

0 comments on commit 8cf6e50

Please sign in to comment.