Esempio n. 1
0
 def test1(self):
     fs = FileSystem(TEST_DIR)
     
     dirs = fs.listdirs()
     
     self.assertIn('lvl_1_a', dirs)
     self.assertIn('lvl_1_b', dirs)
     self.assertEqual(len(dirs), 2)
Esempio n. 2
0
 def test2(self):
     fs = FileSystem(TEST_DIR)
     
     dirs = fs.listdirs(1)
     
     self.assertIn('lvl_1_a/lvl_2_aa', dirs)
     self.assertIn('lvl_1_a/lvl_2_ab', dirs)
     self.assertIn('lvl_1_b/lvl_2_ba', dirs)
     self.assertIn('lvl_1_b/lvl_2_bb', dirs)
     
     self.assertNotIn( 'lvl_1_a', dirs)
     self.assertNotIn( 'lvl_1_b', dirs)
Esempio n. 3
0
class Collection(object):
    
    def __init__(self, dir_path, merge_subdirectories = 0, entry_cls = BasicEntry):
        
        self.dir_path = dir_path
        self.merge_subdirectories = merge_subdirectories
        
        if not issubclass(entry_cls, BaseEntry):
            raise ValueError("entry_generator must be subclass of BaseEntryGenerator")
            
        self.entry_cls = entry_cls
        
        self.fs = FileSystem(self.dir_path)



    def keys(self):
        dirs = self.fs.listdirs(self.merge_subdirectories)
        return dirs
        
    
    def list(self):
        keys = self.keys()
        return EntryList(self, keys)
        
        
    def has(self, key):
        return key in self.keys()
        
        
    def get(self, key = None):
        if key is None:
            raise NotImplementedError("Creation of entries is not supported yet")
            
        entry = self.entry_cls(self, key)
        
        return entry
        

    def clear(self, key):
            raise NotImplementedError("Modification of entries is not supported yet")
        
        
    def fill_entry(self, entry):
        entry_path = self.fs.get_full_path(entry.key())
        fs = FileSystem(entry_path)
        entry.decode(fs)
        
        
    def save_entry(self, entry):
        entry_path = self.fs.get_full_path(entry.key())
        fs = FileSystem(entry_path)
        entry.encode(fs)
Esempio n. 4
0
 def test3(self):
     fs = FileSystem(TEST_DIR)
     
     dirs = fs.listdirs(2)
     
     self.assertEqual(len(dirs), 0)