diff options
author | Siddharth Ravikumar <sravik@bgsu.edu> | 2015-02-20 08:37:24 -0500 |
---|---|---|
committer | Siddharth Ravikumar <sravik@bgsu.edu> | 2015-02-20 08:37:24 -0500 |
commit | 79bc74432d42006ac0cedebc2291e8f6b6d1cddb (patch) | |
tree | f357e5df9f2c697105c3380a5c6c61782bce3102 /combox/file.py | |
parent | 8a670ce3642d84cda9a4657d133da2b06b12ef3f (diff) |
Refactored combox.file.cb_path to accept a file or a directory under a node directory.
It returns the path of the respective file or directory in the combox directory.
Also updated the test for this function at tests.file_test.TestFile.test_cbpath
modified: combox/file.py
modified: tests/file_test.py
Diffstat (limited to 'combox/file.py')
-rw-r--r-- | combox/file.py | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/combox/file.py b/combox/file.py index f5b38f5..3b3219e 100644 --- a/combox/file.py +++ b/combox/file.py @@ -49,14 +49,24 @@ def relative_path(p, config, comboxd=True): return p.partition(directory)[2] -def cb_path(shard_path, config): +def cb_path(node_path, config): """ - Returns abs. path of file (in combox dir.) corresponding to the shard with path `shard_path' + Returns abs. path of file (in combox dir.) given the node_path. """ - rel_shard_path = relative_path(shard_path, config, False) - rel_file_path = rel_shard_path.partition('.shard')[0] - return path.join(config['combox_dir'], rel_file_path) + if path.isfile(node_path): + # partition function is used to remove the `.shard.N' from the + # file name. + rel_file_path = relative_path(node_path, + config, + False).partition('.shard')[0] + file_cb_path = path.join(config['combox_dir'], + rel_file_path) + else: + file_cb_path = path.join(config['combox_dir'], + relative_path(node_path, config, False)) + + return file_cb_path def mk_nodedir(directory, config): |