本文整理匯總了Python中datamodel.Library.github_from_url方法的典型用法代碼示例。如果您正苦於以下問題:Python Library.github_from_url方法的具體用法?Python Library.github_from_url怎麽用?Python Library.github_from_url使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類datamodel.Library
的用法示例。
在下文中一共展示了Library.github_from_url方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: update_registry_info
# 需要導入模塊: from datamodel import Library [as 別名]
# 或者: from datamodel.Library import github_from_url [as 別名]
def update_registry_info(self):
# Check if there's a NPM scope or the default scope @@npm.
assert self.scope.startswith('@')
response = util.registry_get(self.scope, self.package)
try:
package = json.loads(response.content)
except ValueError:
return self.error('Could not parse registry metadata', ErrorCodes.Library_parse_registry)
if response.status_code == 200:
repository = package.get('repository', {})
repository_string = repository.get('url', '') if isinstance(repository, dict) else repository
self.owner, self.repo = Library.github_from_url(repository_string)
if self.owner == '' or self.repo == '':
return self.error('No github URL associated with package', ErrorCodes.Library_no_github)
new_metadata = json.loads(response.content)
old_metadata = self.library.registry_metadata
if old_metadata is None or new_metadata.get('_rev') != json.loads(old_metadata).get('_rev'):
# The maximum datastore entity size is 1048487 bytes, and this NPM
# registry response can sometimes surpass that limit. Hard fail now if
# we might get close to the limit, or else we'll fail later with an
# uncaught error when we commit, which will cause the task to
# unnecessarily retry (note there is other data in the entity too).
#
# TODO(aomarks) Compress or prune the registry metadata of erroring,
# since this means we are currently skipping some packages.
if len(response.content) > 1000000:
return self.error('Registry metadata is too big', ErrorCodes.Library_registry_too_big)
self.library.registry_metadata = response.content
self.library.registry_metadata_updated = datetime.datetime.now()
self.library_dirty = True
elif response.status_code == 404:
return self.error('Package not found in registry', ErrorCodes.Library_no_package)
else:
return self.retry('Could not update registry info (%d)' % response.status_code)
示例2: test_from_url
# 需要導入模塊: from datamodel import Library [as 別名]
# 或者: from datamodel.Library import github_from_url [as 別名]
def test_from_url(self):
self.assertEqual(Library.github_from_url('owner/repo'), ('owner', 'repo'))
self.assertEqual(Library.github_from_url('git+https://github.com/owner/repo.git'), ('owner', 'repo'))
self.assertEqual(Library.github_from_url('git://github.com/owner/repo.git'), ('owner', 'repo'))