コード例 #1
0
    def save_mapping_data(self,
                          out_mapping_file,
                          crypt,
                          save_json=True,
                          save_plist=True):
        if not out_mapping_file:
            out_mapping_file = os.path.join(
                self.out_res_path, RandomGenerater.generate_words(1, 2))

        if crypt:
            map_data = {}
            for k, v in self.map.items():
                k = PathCrypt.path_md5(k, crypt)
                map_data[k] = v
        else:
            map_data = self.map

        if save_json:
            fp = open(out_mapping_file + ".json", "w+")
            json.dump(map_data, fp)
            fp.close()

        if save_plist:
            plist_file_path = out_mapping_file + ".plist"
            print("save to %s" % plist_file_path)
            plistlib.writePlist(map_data, plist_file_path)
コード例 #2
0
 def __init__(self, max_level, min_dir_counts, max_dir_counts, ignore_root=False):
     # dir deep
     self.max_level = max_level
     self.min_dir_counts = min_dir_counts if isinstance(min_dir_counts, list) else [min_dir_counts]
     self.max_dir_counts = max_dir_counts if isinstance(max_dir_counts, list) else [max_dir_counts]
     self.have_sub_dir_probability = 60
     self.root_dir = DirInfo(True, "" if ignore_root else RandomGenerater.generate_words(1, 1))
     self.dirs = []
コード例 #3
0
 def __init__(self, have_children, name=None):
     self.name = name if name is not None else RandomGenerater.generate_words(1, 3)
     self.level = 0
     self.parent = None
     self.have_children = have_children
     if have_children:
         self.children = []
     else:
         self.children = None
コード例 #4
0
 def parse_file(self, src_file, relative_path):
     out_dir = random.choice(self.dirs)
     out_file_name = RandomGenerater.generate_words(1, 2)
     if self.keep_ext:
         out_file_name += os.path.splitext(src_file)[1]
     out_relative_path = out_dir + "/" + out_file_name
     out_path = os.path.join(self.out_res_path, out_relative_path)
     # copy to out_dir
     if self.remove_source:
         os.rename(src_file, out_path)
     else:
         shutil.copyfile(src_file, out_path)
     self.map[relative_path] = out_relative_path