Skip to content

Commit 424aa6b

Browse files
committed
mainly, adding the append command
1 parent 8750fd0 commit 424aa6b

File tree

4 files changed

+46
-3
lines changed

4 files changed

+46
-3
lines changed

paths_cli/cli.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
import os
88

99
import click
10+
# import click_completion
11+
# click_completion.init()
1012

1113
CONTEXT_SETTINGS = dict(help_option_names=['-h', '--help'])
1214

paths_cli/commands/append.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import click
2+
from paths_cli.parameters import (
3+
INPUT_FILE, APPEND_FILE, MULTI_CV, MULTI_ENGINE, MULTI_VOLUME,
4+
MULTI_NETWORK, MULTI_SCHEME, MULTI_TAG
5+
)
6+
7+
@click.command(
8+
'append',
9+
short_help="add objects from INPUT_FILE to another file"
10+
)
11+
@INPUT_FILE.clicked(required=True)
12+
@APPEND_FILE.clicked(required=True)
13+
@MULTI_ENGINE.clicked(required=False)
14+
@MULTI_CV.clicked(required=False)
15+
@MULTI_VOLUME.clicked(required=False)
16+
@MULTI_NETWORK.clicked(required=False)
17+
@MULTI_SCHEME.clicked(required=False)
18+
@MULTI_TAG.clicked(required=False)
19+
def append(input_file, append_file, engine, cv, volume, network, scheme,
20+
tag):
21+
"""Append objects from INPUT_FILE to another file.
22+
"""
23+
storage = INPUT_FILE.get(input_file)
24+
output_storage = APPEND_FILE.get(append_file)
25+
params = [MULTI_ENGINE, MULTI_CV, MULTI_VOLUME, MULTI_NETWORK,
26+
MULTI_SCHEME, MULTI_TAG]
27+
args = [engine, cv, volume, network, scheme, tag]
28+
to_save = []
29+
for arg, param in zip(args, params):
30+
to_save.extend(param.get(storage, arg))
31+
32+
for obj in to_save:
33+
output_storage.save(obj)
34+
35+
output_storage.close()
36+
37+
38+
CLI = append
39+
SECTION = "Miscellaneous"
40+
REQUIRES_OPS = (1, 0)

paths_cli/parameters.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def __init__(self, param, mode):
4343
super(StorageLoader, self).__init__(param)
4444
self.mode = mode
4545

46-
def workaround(self, name):
46+
def _workaround(self, name):
4747
# this is messed up... for some reason, storage doesn't create a new
4848
# file in append mode. That may be a bug
4949
import openpathsampling as paths
@@ -53,7 +53,7 @@ def workaround(self, name):
5353

5454
def get(self, name):
5555
import openpathsampling as paths
56-
self.workaround(name)
56+
self._workaround(name)
5757
return paths.Storage(name, mode=self.mode)
5858

5959

@@ -257,3 +257,5 @@ def init_snap_fallback(parameter, storage, name):
257257

258258
N_STEPS_MC = click.option('-n', '--nsteps', type=int,
259259
help="number of Monte Carlo trials to run")
260+
261+
MULTI_CV = CVS

paths_cli/tests/test_parameters.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,4 +338,3 @@ def test_APPEND_FILE():
338338
storage.close()
339339
os.remove(filename)
340340
os.rmdir(tempdir)
341-

0 commit comments

Comments
 (0)