combox

split and encrypted files between online file storage providers
git clone git://git.ricketyspace.net/combox.git
Log | Files | Refs

commit 7dbd4907a7b351bcc022a55068449c987d1754df
parent 1f5e33f6607f44419935715fdd8b87cefede2950
Author: Siddharth Ravikumar <sravik@bgsu.edu>
Date:   Thu, 19 Mar 2015 22:42:26 -0400

new function combox.file.node_paths: returns the abs. path of shards/directories in node directories.

	modified:   combox/file.py
	modified:   tests/file_test.py

Diffstat:
combox/file.py | 28++++++++++++++++++++++++++++
tests/file_test.py | 29+++++++++++++++++++++++++++++
2 files changed, 57 insertions(+), 0 deletions(-)

diff --git a/combox/file.py b/combox/file.py @@ -93,6 +93,34 @@ def node_path(cb_path, config, isfile): return file_node_path +def node_paths(cb_path, config, isfile): + """Returns list of abs. path of file (in node dir.) the cb_path. + + If cb_path is a file, it returns a list of abs. path names of + shards of the file in the node directories. + + isfile: True if cb_path is a file + """ + + n_paths = [] + nodes = get_nodedirs(config) + rel_path = relative_path(cb_path, config) + + if isfile: + shard_no = 0 + for node in nodes: + file_shard = '%s.shard%d' % (rel_path, shard_no) + n_path = path.join(node, file_shard) + n_paths.append(n_path) + shard_no += 1 + else: + for node in nodes: + n_path = path.join(node, rel_path) + n_paths.append(n_path) + + return n_paths + + def mk_nodedir(directory, config): """ Creates directory `directory' inside the nodes. diff --git a/tests/file_test.py b/tests/file_test.py @@ -157,6 +157,35 @@ class TestFile(object): isfile=False) + def test_nodepaths(self): + """Tests the node_paths function.""" + nodes = get_nodedirs(self.config) + node_iter = iter(nodes) + + # test for file shards + foo = path.join(self.config['combox_dir'], 'foo.txt') + foo_rel_path = relative_path(foo, self.config) + foo_shards = node_paths(foo, self.config, True) + + shard_no = 0 + for foo_shard in foo_shards: + file_shard = '%s.shard%d' % (foo_rel_path, shard_no) + n_path = path.join(node_iter.next(), file_shard) + assert_equal(n_path, foo_shard) + shard_no += 1 + + # test for directory inside node_directories + bar = path.join(self.config['combox_dir'], 'bar') + bar_rel_path = relative_path(bar, self.config) + bar_n_paths = node_paths(bar, self.config, False) + + + node_iter = iter(nodes) + for bar_n_path in bar_n_paths: + b_n_path = path.join(node_iter.next(), bar_rel_path) + assert_equal(b_n_path, bar_n_path) + + def test_rmpath(self): """Tests rm_path function""" new_dir = path.join(self.config['combox_dir'], 'fooius')