Skip to content

Commit

Permalink
Add verify_opts and sync_opts to Directory class
Browse files Browse the repository at this point in the history
  • Loading branch information
elikoga committed Dec 20, 2023
1 parent 396bfa7 commit a3dcf98
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/batou/lib/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,13 +244,22 @@ class Directory(Component):
source = None
exclude = ()

verify_opts = None
sync_opts = None

def configure(self):
self.path = self.map(self.path)
if self.source:
# XXX The ordering is wrong. SyncDirectory should run *after*.
self += SyncDirectory(
self.path, source=self.source, exclude=self.exclude
)
args = {
"source": self.source,
"exclude": self.exclude,
}
if self.verify_opts:
args["verify_opts"] = self.verify_opts
if self.sync_opts:
args["sync_opts"] = self.sync_opts
self += SyncDirectory(self.path, **args)

def verify(self):
assert os.path.isdir(self.path)
Expand Down
11 changes: 11 additions & 0 deletions src/batou/lib/tests/test_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -1153,3 +1153,14 @@ def test_syncdirectory_needs_update_on_nonexisting_target(root):
with pytest.raises(batou.UpdateNeeded):
sd = SyncDirectory("non_existing_dir", source="existing_dir")
sd.verify()


def test_directory_passes_args_to_syncdirectory(root):
d = Directory(
"target", source="source", verify_opts="-abc", sync_opts="-xyz"
)
d.prepare(root.component)
sd = d._
assert isinstance(sd, SyncDirectory)
assert sd.verify_opts == "-abc"
assert sd.sync_opts == "-xyz"

0 comments on commit a3dcf98

Please sign in to comment.