diff options
author | Siddharth Ravikumar <sravik@bgsu.edu> | 2015-02-19 20:55:37 -0500 |
---|---|---|
committer | Siddharth Ravikumar <sravik@bgsu.edu> | 2015-02-19 20:55:37 -0500 |
commit | a7fb2c3b3cc9eeea820abfe6579d87617855baef (patch) | |
tree | b1cc9323f9bec75b4a3adf3fa86de34074e08c24 | |
parent | 201e0938a2e0f1f7e747fa6e809e0e5886b90d11 (diff) |
Defined new function in combox.file.cb_path
This function, given the path of a file shard, returns the
corresponding path of the file in the combox directory.
The test for this function is at tests.file_test.TestFile.test_cbpath
modified: combox/file.py
modified: tests/file_test.py
-rw-r--r-- | combox/file.py | 10 | ||||
-rw-r--r-- | tests/file_test.py | 10 |
2 files changed, 20 insertions, 0 deletions
diff --git a/combox/file.py b/combox/file.py index e6d4000..f5b38f5 100644 --- a/combox/file.py +++ b/combox/file.py @@ -49,6 +49,16 @@ def relative_path(p, config, comboxd=True): return p.partition(directory)[2] +def cb_path(shard_path, config): + """ + Returns abs. path of file (in combox dir.) corresponding to the shard with path `shard_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) + + def mk_nodedir(directory, config): """ Creates directory `directory' inside the nodes. diff --git a/tests/file_test.py b/tests/file_test.py index 50bf261..5cbd371 100644 --- a/tests/file_test.py +++ b/tests/file_test.py @@ -112,6 +112,16 @@ class TestFile(object): self.config, False) + def test_cbpath(self): + """Tests the get_cbpath function""" + split_and_encrypt(self.TEST_FILE, self.config) + test_file_shard_0 = '%s.shard.0' % path.basename(self.TEST_FILE) + test_file_shard_0_abspath = path.join(get_nodedirs(self.config)[0], + test_file_shard_0) + + assert self.TEST_FILE == cb_path(test_file_shard_0_abspath, + self.config) + @classmethod def teardown_class(self): """Purge the mess created by this test.""" |