summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--combox/file.py22
-rw-r--r--tests/file_test.py19
2 files changed, 41 insertions, 0 deletions
diff --git a/combox/file.py b/combox/file.py
index 3b3219e..959954a 100644
--- a/combox/file.py
+++ b/combox/file.py
@@ -69,6 +69,28 @@ def cb_path(node_path, config):
return file_cb_path
+def node_path(cb_path, config):
+ """Returns abs. path of file (in node dir.) given the cb_path (combox dir. path).
+
+ If cb_path is a file, it returns the path to its first shard in
+ the first node directory.
+
+ """
+
+ if path.isfile(cb_path):
+ # partition function is used to remove the `.shard.N' from the
+ # file name.
+ rel_file_path = relative_path(cb_path, config)
+ file_node_path = path.join(get_nodedirs(config)[0],
+ rel_file_path)
+ file_node_path = "%s.shard0" % file_node_path
+ else:
+ file_node_path = path.join(get_nodedirs(config)[0],
+ relative_path(cb_path, config))
+
+ return file_node_path
+
+
def mk_nodedir(directory, config):
"""
Creates directory `directory' inside the nodes.
diff --git a/tests/file_test.py b/tests/file_test.py
index 3e14343..0ee75d4 100644
--- a/tests/file_test.py
+++ b/tests/file_test.py
@@ -129,6 +129,25 @@ class TestFile(object):
'foo')
assert foo_dir == cb_path(foo_nodedir, self.config)
+
+ def test_nodepath(self):
+ """Tests the node_path function"""
+ split_and_encrypt(self.TEST_FILE, self.config)
+ test_file_shard_0 = '%s.shard0' % path.basename(self.TEST_FILE)
+ test_file_shard_0_abspath = path.join(get_nodedirs(self.config)[0],
+ test_file_shard_0)
+
+ assert test_file_shard_0_abspath == node_path(self.TEST_FILE,
+ self.config)
+
+
+ foo_dir = path.join(self.config['combox_dir'], 'foo')
+ foo_nodedir = path.join(get_nodedirs(self.config)[0],
+ 'foo')
+
+ assert foo_nodedir == node_path(foo_dir, self.config)
+
+
@classmethod
def teardown_class(self):
"""Purge the mess created by this test."""