def _generate_platform_yaml(api_path, product_info, tag_info, output): prefix = "%s_%s" % (product_info["cloud_full_name"], product_info["service_type"]) config = {"ansible": {}, "terraform": {}} for tag, info in tag_info.items(): custom_configs = read_yaml(api_path + tag + ".yaml") rn = get_resource_name(info, custom_configs) v = custom_configs.get("ansible") if v: config["ansible"][rn] = { "config": v, } v = custom_configs.get("terraform") if v: config["terraform"][rn] = { "config": v, "config_dir": api_path, "terraform_resource_name": "%s_%s" % (prefix, rn.lower()) } m = { "ansible": build_ansible_yaml, "terraform": build_terraform_yaml } for k, v in config.items(): m[k](v, output)
def convert_images_to_jpg(project_root_path, jpg_quality, image_paths): old_size = 0 new_size = 0 for image_path in image_paths: old_size += os.path.getsize(image_path) file_name = os.path.splitext(image_path)[0] jpg_file_name = file_name + '.jpg' print('Converting %s ----> %s' % (image_path, jpg_file_name)) convert_image_to_jpg(image_path, jpg_quality, jpg_file_name) swap_image_in_pbxproj(project_root_path, image_path, jpg_file_name) os.remove(image_path) new_size += os.path.getsize(jpg_file_name) file_names = [ os.path.splitext(get_resource_name( img_path[img_path.rfind('/') + 1:]))[0] for img_path in image_paths ] sources = get_sources(get_subdirectory_paths(project_root_path)) for source in sources: print(source) source_file = open(source.get_path()) source_file_lines = source_file.readlines() source_file.close() resource_in_this_source = False for line in source_file_lines: for image_name in file_names: if image_name in line: resource_in_this_source = True break if resource_in_this_source: os.remove(source.get_path()) source_file = open(source.get_path(), 'w') for line in source_file_lines: fixed_line = line for image_name in file_names: fixed_line = fixed_line.replace('@"%s"' % image_name, '@"%s.jpg"' % image_name) fixed_line = fixed_line.replace('@"%s.png"' % image_name, '@"%s.jpg"' % image_name) fixed_line = fixed_line.replace('>%s<' % image_name, '>%s.jpg<' % image_name) fixed_line = fixed_line.replace('>%s.png<' % image_name, '>%s.jpg<' % image_name) source_file.write(fixed_line) old_size = old_size / 1024.0 / 1024.0 new_size = new_size / 1024.0 / 1024.0 if old_size != 0: print('\n') print('Old size: %f MiB' % old_size) print('New size: %f MiB' % new_size) print('Difference: %f MiB' % (old_size - new_size)) print('New size is %f%% of old size.' % (100 * new_size / old_size)) print('\n')
def get_resources(subdirectory_paths): resources = set() for path in subdirectory_paths: resource_file_names = get_file_names(path, Resource.proper_extensions) resource_names = set() for resource_file_name in resource_file_names: resource_names.add(get_resource_name(resource_file_name)) for resource_name in resource_names: resources.add(Resource(path, resource_name)) return resources
def convert_images_to_jpg(project_root_path, jpg_quality, image_paths): old_size = 0 new_size = 0 for image_path in image_paths: old_size += os.path.getsize(image_path) file_name = os.path.splitext(image_path)[0] jpg_file_name = file_name + '.jpg' print('Converting %s ----> %s' % (image_path, jpg_file_name)) convert_image_to_jpg(image_path, jpg_quality, jpg_file_name) swap_image_in_pbxproj(project_root_path, image_path, jpg_file_name) os.remove(image_path) new_size += os.path.getsize(jpg_file_name) file_names = [os.path.splitext(get_resource_name(img_path[img_path.rfind('/') + 1:]))[0] for img_path in image_paths] sources = get_sources(get_subdirectory_paths(project_root_path)) for source in sources: print(source) source_file = open(source.get_path()) source_file_lines = source_file.readlines() source_file.close() resource_in_this_source = False for line in source_file_lines: for image_name in file_names: if image_name in line: resource_in_this_source = True break if resource_in_this_source: os.remove(source.get_path()) source_file = open(source.get_path(), 'w') for line in source_file_lines: fixed_line = line for image_name in file_names: fixed_line = fixed_line.replace('@"%s"' % image_name, '@"%s.jpg"' % image_name) fixed_line = fixed_line.replace('@"%s.png"' % image_name, '@"%s.jpg"' % image_name) fixed_line = fixed_line.replace('>%s<' % image_name, '>%s.jpg<' % image_name) fixed_line = fixed_line.replace('>%s.png<' % image_name, '>%s.jpg<' % image_name) source_file.write(fixed_line) old_size = old_size / 1024.0 / 1024.0 new_size = new_size / 1024.0 / 1024.0 if old_size != 0: print('\n') print('Old size: %f MiB' % old_size) print('New size: %f MiB' % new_size) print('Difference: %f MiB' % (old_size - new_size)) print('New size is %f%% of old size.' % (100 * new_size / old_size)) print('\n')