当前位置: 首页>>代码示例>>Python>>正文


Python Project.get_chosen_resources方法代码示例

本文整理汇总了Python中txclib.project.Project.get_chosen_resources方法的典型用法代码示例。如果您正苦于以下问题:Python Project.get_chosen_resources方法的具体用法?Python Project.get_chosen_resources怎么用?Python Project.get_chosen_resources使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在txclib.project.Project的用法示例。


在下文中一共展示了Project.get_chosen_resources方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_specifying_resources

# 需要导入模块: from txclib.project import Project [as 别名]
# 或者: from txclib.project.Project import get_chosen_resources [as 别名]
    def test_specifying_resources(self):
        """Test the various ways to specify resources in a project."""
        p = Project(init=False)
        resources = [
            'proj1.res1',
            'proj2.res2',
            'transifex.txn',
            'transifex.txo',
        ]
        with patch.object(p, 'get_resource_list') as mock:
            mock.return_value = resources
            cmd_args = [
                'proj1.res1', '*1*', 'transifex*', '*r*',
                '*o', 'transifex.tx?', 'transifex.txn',
            ]
            results = [
                ['proj1.res1', ],
                ['proj1.res1', ],
                ['transifex.txn', 'transifex.txo', ],
                ['proj1.res1', 'proj2.res2', 'transifex.txn', 'transifex.txo', ],  # noqa
                ['transifex.txo', ],
                ['transifex.txn', 'transifex.txo', ],
                ['transifex.txn', ],
                [],
            ]

            for i, arg in enumerate(cmd_args):
                resources = [arg]
                self.assertEqual(p.get_chosen_resources(resources), results[i])

            # wrong argument
            resources = ['*trasnifex*', ]
            self.assertRaises(Exception, p.get_chosen_resources, resources)
开发者ID:TASERAxon,项目名称:transifex-client,代码行数:35,代码来源:test_project.py

示例2: test_specifying_resources

# 需要导入模块: from txclib.project import Project [as 别名]
# 或者: from txclib.project.Project import get_chosen_resources [as 别名]
    def test_specifying_resources(self):
        """Test the various ways to specify resources in a project."""
        p = Project(init=False)
        resources = ["proj1.res1", "proj2.res2", "transifex.txn", "transifex.txo"]
        with patch.object(p, "get_resource_list") as mock:
            mock.return_value = resources
            cmd_args = ["proj1.res1", "*1*", "transifex*", "*r*", "*o", "transifex.tx?", "transifex.txn"]
            results = [
                ["proj1.res1"],
                ["proj1.res1"],
                ["transifex.txn", "transifex.txo"],
                ["proj1.res1", "proj2.res2", "transifex.txn", "transifex.txo"],
                ["transifex.txo"],
                ["transifex.txn", "transifex.txo"],
                ["transifex.txn"],
                [],
            ]

            for i, arg in enumerate(cmd_args):
                resources = [arg]
                self.assertEqual(p.get_chosen_resources(resources), results[i])

            # wrong argument
            resources = ["*trasnifex*"]
            self.assertRaises(Exception, p.get_chosen_resources, resources)
开发者ID:keiji,项目名称:android,代码行数:27,代码来源:test_project.py

示例3: Project

# 需要导入模块: from txclib.project import Project [as 别名]
# 或者: from txclib.project.Project import get_chosen_resources [as 别名]

prj = Project(find_dot_tx())

api_auth = prj.getset_host_credentials('https://api.transifex.com')

offset = 0
remote_resources = []
while True:
  r = requests.get('https://api.transifex.com/organizations/{}/projects/{}/resources/?offset={}'.format(organization_slug, project_slug, offset), auth=api_auth)
  results = r.json()
  if len(results) == 0:
    break
  remote_resources.extend(results)
  offset += 100

remote_resources_set = set([res['slug'] for res in remote_resources])

local_resources_set = set([res.split('.')[1] for res in prj.get_chosen_resources([])])

print "remote resources count: {}".format(len(remote_resources_set))
print "local resources count: {}".format(len(local_resources_set))

outdated_resources = remote_resources_set - local_resources_set

for res_slug in outdated_resources:
    print "deleting outdated resource {}".format(res_slug)
    # it seems delete is currently not working on the new api
    # r = requests.delete('https://api.transifex.com/organizations/{}/projects/{}/resources/{}/'.format(organization_slug, project_slug, res_slug), auth=api_auth)
    r = requests.delete('https://www.transifex.com/api/2/project/{}/resource/{}/'.format(project_slug, res_slug), auth=api_auth)
开发者ID:opendatasoft,项目名称:ods-documentation,代码行数:31,代码来源:clean_remote_resources.py


注:本文中的txclib.project.Project.get_chosen_resources方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。