diff options
author | Siddharth Ravikumar <sravik@bgsu.edu> | 2015-04-01 22:00:18 -0400 |
---|---|---|
committer | Siddharth Ravikumar <sravik@bgsu.edu> | 2015-04-01 22:00:18 -0400 |
commit | a7327e72060fbb4dac783f1af41bcb9b4ea6da76 (patch) | |
tree | f6f82fc1ce79972008737f281b16a05dd72ccb01 | |
parent | 4095aa4caf8021a6b8f44c2c4ca3b76a9c26a91f (diff) |
updated combox.file.relative_path.
This method now returns relative paths w. r. t all node directories. Before it used to return relative paths only w. r. t the first node directory.
Also updated the tests for it :~(
modified: combox/file.py
modified: tests/file_test.py
-rw-r--r-- | combox/file.py | 9 | ||||
-rw-r--r-- | tests/file_test.py | 12 |
2 files changed, 18 insertions, 3 deletions
diff --git a/combox/file.py b/combox/file.py index 2f18823..81d15fe 100644 --- a/combox/file.py +++ b/combox/file.py @@ -41,10 +41,17 @@ def relative_path(p, config, comboxd=True): combox. """ + directory = None if comboxd: directory = '%s/' % config['combox_dir'] else: - directory = '%s/' % get_nodedirs(config)[0] + for node in get_nodedirs(config): + if p.startswith(node): + directory = '%s/' % node + + if directory is None: + err_msg = "invalid path %s" % p + raise ValueError, err_msg return p.partition(directory)[2] diff --git a/tests/file_test.py b/tests/file_test.py index bd81fd7..d8a77ca 100644 --- a/tests/file_test.py +++ b/tests/file_test.py @@ -114,10 +114,14 @@ class TestFile(object): test_file_shard_0 = '%s.shard.0' % test_file_basename test_file_shard_0_abspath = path.join(get_nodedirs(self.config)[0], test_file_shard_0) + test_file_shard_1 = '%s.shard.1' % test_file_basename + test_file_shard_1_abspath = path.join(get_nodedirs(self.config)[1], + test_file_shard_1) assert test_file_shard_0 == relative_path(test_file_shard_0_abspath, self.config, False) - + assert test_file_shard_1 == relative_path(test_file_shard_1_abspath, + self.config, False) def test_cbpath(self): """Tests the cb_path function""" @@ -125,9 +129,13 @@ class TestFile(object): 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) - + test_file_shard_1 = '%s.shard1' % path.basename(self.TEST_FILE) + test_file_shard_1_abspath = path.join(get_nodedirs(self.config)[1], + test_file_shard_1) assert self.TEST_FILE == cb_path(test_file_shard_0_abspath, self.config) + assert self.TEST_FILE == cb_path(test_file_shard_1_abspath, + self.config) # a directory inside combox dir. foo_dir = path.join(self.config['combox_dir'], 'foo') |