summaryrefslogtreecommitdiffstats
path: root/combox/file.py
diff options
context:
space:
mode:
authorSiddharth Ravikumar <sravik@bgsu.edu>2015-02-25 22:36:05 -0500
committerSiddharth Ravikumar <sravik@bgsu.edu>2015-02-25 22:36:05 -0500
commit5a9f2b72399d406e86dadb9cb15ae948e08293cc (patch)
tree6fb521fb53f8fdcabd26c2eee8f4b250eec78ebc /combox/file.py
parenta74c583656f3d9fadf50cf070e58235db1b2de90 (diff)
new function combox.file.node_path.
This function takes the path to the file in the combox and returns the path of its first shard in the node directory. If the the given argument is a directory (inside the combox directory), the function returns the corresponding path of the directory under the first node directory. Test for the function was also written. modified: combox/file.py modified: tests/file_test.py
Diffstat (limited to 'combox/file.py')
-rw-r--r--combox/file.py22
1 files changed, 22 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.