Esempio n. 1
0
 def fill_dir_tree(dirs, byte_size, file_nums, file_ext_list):
     tree = []
     total_dirs = len(dirs)
     chose_flag = True
     copy_ext_list = file_ext_list[:]
     for i in range(total_dirs):
         ext_list = []
         if chose_flag:
             if (len(copy_ext_list) > 0):
                 ext = random.choice(copy_ext_list)
                 ext_list.append(ext)
                 copy_ext_list.remove(ext)
             else:
                 chose_flag = False
                 copy_ext_list = file_ext_list[:]
                 ext_list.append(JRand.chose_nearest(copy_ext_list))
         else:
             ext_list.append(JRand.chose_nearest(copy_ext_list))
         dir_size = JRand.rand_lave(byte_size, total_dirs, i)
         dir_sons = JRand.rand_lave(file_nums, total_dirs, i)
         byte_size -= dir_size
         file_nums -= dir_sons
         tree.append(JFillerFolder(dirs[i], dir_size, dir_sons, ext_list))
     return tree
Esempio n. 2
0
    def save_to_disk(self):
        files = []
        byte_size = self._dir_size
        for i in range(self._children):
            file_path = self.rand_child_path()
            file_size = JRand.rand_lave(byte_size, self._children, i)
            byte_size -= file_size
            stream = JFillerFile.get_bytes(file_size)

            f = open(file_path, 'wb')
            f.write(stream)
            f.flush()
            f.close()

            files.append(file_path)
        return files