本文整理汇总了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)
示例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)
示例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)