def import_packages(self, json_data): data = json.loads(json_data) settings = json.loads(load_settings()) translatable_strings = [f["name"] for f in settings["variables"]] group = settings["abf_projects_group"] if data["type"] == "files": values = data["values"] print(values) print(type(values)) return json.dumps({"packages": [full_project_info(group, f, translatable_strings) for f in values]}) elif data["type"] == "dir": values = data["values"] return json.dumps( {"packages": [full_project_info(group, f, translatable_strings) for f in os.listdir(values) if ".rpm" == f[-4:] and ".src.rpm" != f[-8:]]}) elif data["type"] == "custom": with_list = from_file_with_list(data["values"]) return json.dumps( {"packages": [full_project_info(group, f, translatable_strings) for f in with_list if ".rpm" == f[-4:]]}) elif data["type"] == "repo": values_ = data["values"][0] files = mirror_repo_to_tmp(values_) f_ = {"packages": [full_project_info(group, f, translatable_strings) for f in files if ".rpm" == f[-4:] and ".src.rpm" != f[-8:]]} result = json.dumps(f_) return result
def import_packages(self, jsonData): data = json.loads(jsonData) if data["type"] == "files": values = json.loads(data["values"]) print(values) print(type(values)) print(data["values"]) print(json.loads(values)) return [full_project_info("import", f, ["Name", "Comment"]) for f in json.loads(values)]
# 3 из репозитория. # TZ 4.1.3 # Про архитектуру: модули и инструкции по расширению каждого модуля. project_group = "import" inner = "terminology-0.9.0-1-rosa2014.1.x86_64.rpm\ntelegram-0.9.28-2-rosa2014.1.x86_64.rpm\nbackintime-gnome-1.0.40-1-rosa2014.1.noarch.rpm" yandex_api_key = "trnsl.1.1.20160131T164826Z.1cd5efb8cc6af7a6.0d34545e70be2a8bdd261d6cf743ae3df1429d13" assert ( yandex_translate(yandex_api_key, "en-ru", "Lazy cat jumps over talking dog") == "Ленивый кот перепрыгивает через говорящая собака" ) for f in filter_input(inner): print(full_project_info(project_group, f, ["Name", "Comment"])) project_info = [full_project_info(project_group, f, ["Name", "Comment"]) for f in filter_input(inner)] print(json.dumps(project_info)) translated_files = "" for one in project_info: for f in one["desktop_files"]: print(str(f["path"])) translated_files = translated_files + f["path"] + "\n" for i in f["strings"]: translated = str( i["variable_name"] + "[translated_ru]=" + yandex_translate(yandex_api_key, "en-ru", i["value"]["en"]) ) translated_files = translated_files + translated + "\n" print(translated)
parser = argparse.ArgumentParser(description='Translate some packages') parser.add_argument('--git-branch', dest="git_branch", default="master") group = parser.add_mutually_exclusive_group(required=True) group.add_argument('--prepare', dest='target', action='store_const', const='prepare') group.add_argument('--translate', dest='target', action='store_const', const='translate') group.add_argument('--commit', dest='target', action='store_const', const='commit') parser.add_argument('file', metavar='filename.yml', type=str, help='an integer for the accumulator') args = parser.parse_args() settings = json.loads(settings_keeper.load_settings()) project_group = settings["abf_projects_group"] yandex_api_key = settings["yandex_api_key"] assert translate(yandex_api_key, "en-ru", "Lazy cat jumps over talking dog") == "Ленивый кот перепрыгивает через говорящая собака" project_info = [full_project_info(project_group, f, ["Name", "Comment"]) for f in from_file_with_list(args.file)] for one in project_info: random_str = uuid.uuid4().hex.capitalize() for f in one["desktop_files"]: for i in f["strings"]: if args.target in ['translate', 'commit']: i["value"]["ru"] = translate(yandex_api_key, "en-ru", i["value"]["en"]) else: i["value"]["ru"] = " " prepare_patch(random_str, one["git"], one["package_name"], json.dumps(one["desktop_files"]), args.git_branch) if (args.target == 'commit'): push_patch(random_str)