Skip to content

Commit

Permalink
Merge pull request #36 from LSSTDESC/yanza/command_update_packages
Browse files Browse the repository at this point in the history
command-update
  • Loading branch information
eacharles authored Aug 3, 2023
2 parents 0c27549 + 476de5b commit 4a78ef0
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/rail/cli/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,18 @@ def clone_source(outdir, git_mode, dry_run, package_file, **kwargs):
"""Install packages from source"""
scripts.clone_source(outdir, git_mode, dry_run, package_file)
return 0


@cli.command()
@options.outdir(default='..')
@options.dry_run()
@options.package_file()
def update_source(outdir, dry_run, package_file, **kwargs):
"""Update packages from source"""
scripts.update_source(outdir, dry_run, package_file)
return 0



@cli.command()
@options.outdir(default='..')
@options.dry_run()
Expand Down
21 changes: 21 additions & 0 deletions src/rail/cli/scripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,27 @@ def clone_source(outdir, git_mode, dry_run, package_file):
else:
os.system(com_line)


def update_source(outdir, dry_run, package_file):

with open(package_file) as pfile:
package_dict = yaml.safe_load(pfile)

currentpath = os.path.abspath('.')
for key, val in package_dict.items():
abspath = os.path.abspath(f"{outdir}/{key}")

if os.path.exists(f"{outdir}/{key}") is not True:
print(f"Package {outdir}/{key} does not exist!")
continue

com_line = f"cd {abspath} && git pull && cd {currentpath}"

if dry_run:
print(com_line)
else:
os.system(com_line)


def install(outdir, from_source, dry_run, package_file):

Expand Down
4 changes: 4 additions & 0 deletions tests/cli/test_scripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ def test_clone_source():
scripts.clone_source('..', GitMode.https, True, 'rail_packages.yml')
scripts.clone_source('..', GitMode.cli, True, 'rail_packages.yml')


def test_update_source():
scripts.update_source('..', True, 'rail_packages.yml')


def test_install():
scripts.install('..', False, True, 'rail_packages.yml')
Expand Down

0 comments on commit 4a78ef0

Please sign in to comment.