本文整理汇总了Python中pyshop.models.Release类的典型用法代码示例。如果您正苦于以下问题:Python Release类的具体用法?Python Release怎么用?Python Release使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Release类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: show_external_release_file
def show_external_release_file(root, request):
"""
Download a release from a download url from its package information.
Must be used with :func:`pyshop.helpers.download.renderer_factory`
to download the release file.
:return: download informations
:rtype: dict
"""
session = DBSession()
settings = request.registry.settings
whlify = asbool(settings.get('pyshop.mirror.wheelify', '0'))
release = Release.by_id(session, int(request.matchdict['release_id']))
filename = (release.whlify_download_url_file if whlify else
release.download_url_file)
rv = {'url': release.download_url,
'filename': filename,
'original': release.download_url_file,
'whlify': whlify
}
release.downloads += 1
release.package.downloads += 1
session.add(release.package)
session.add(release)
request.response.date = datetime.datetime.utcnow()
return rv
示例2: test_by_classifiers
def test_by_classifiers(self):
from pyshop.models import Release
releases = Release.by_classifiers(self.session,
[u'Intended Audience :: Developers'])
self.assertIsInstance(releases, list)
releases = [(r.package.name, r.version) for r in releases]
self.assertEqual(releases, [(u'local_package1', u'0.1')])
示例3: test_by_version
def test_by_version(self):
from pyshop.models import Release
release = Release.by_version(
self.session, u'mirrored_package2', u'1.0')
self.assertIsInstance(release, Release)
self.assertEqual(release.package.name, u'mirrored_package2')
self.assertEqual(release.version, u'1.0')
示例4: _create_release
def _create_release(self, package, data):
release = Release(package=package,
summary=data.get('summary'),
version=data.get('version'),
stable_version=data.get('stable_version'),
home_page=data.get('home_page'),
license=data.get('license'),
description=data.get('description'),
keywords=data.get('keywords'),
platform=data.get('platform'),
download_url=data.get('download_url'),
bugtrack_url=data.get('bugtrack_url'),
docs_url=data.get('docs_url'),
)
if data.get('author'):
author = User.by_login(self.session, data['author'], local=False)
if not author:
author = User(login=data['author'],
local=False,
email=data.get('author_email'))
self.session.add(author)
release.author = author
self.session.flush()
if data.get('maintainer'):
maintainer = User.by_login(self.session, data['maintainer'],
local=False)
if not maintainer:
maintainer = User(login=data['maintainer'],
local=False,
email=data.get('maintainer_email'))
self.session.add(maintainer)
release.maintainer = maintainer
self.session.flush()
for name in data.get('classifiers', []):
classifier = Classifier.by_name(self.session, name)
while classifier:
release.classifiers.append(classifier)
if classifier not in package.classifiers:
package.classifiers.append(classifier)
classifier = classifier.parent
self.session.flush()
return release
示例5: package_releases
def package_releases(self, package_name, show_hidden=False):
"""
Retrieve a list of the releases registered for the given package_name.
Returns a list with all version strings if show_hidden is True or
only the non-hidden ones otherwise."""
session = DBSession()
releases = Release.by_package_name(session, package_name, show_hidden)
session.rollback()
return releases
示例6: render
def render(self):
package = Package.by_name(self.session, self.request.matchdict["package_name"])
if not package:
raise HTTPNotFound()
if "form.refresh_package" in self.request.params:
package.update_at = None
self.session.add(package)
owners = dict((usr.login, usr) for usr in package.owners)
can_edit_role = self.login in owners.keys() and package.local
if "form.add_role" in self.request.params:
if not can_edit_role:
raise HTTPForbidden()
user = User.by_login(self.session, self.request.params["login"])
if user and user.has_permission("upload_releasefile"):
if self.request.params["role"] == "owner":
if user.login not in owners:
package.owners.append(user)
else:
maintainers = [usr.login for usr in package.owners]
if user.login not in maintainers:
package.maintainers.append(user)
self.session.add(package)
if "form.remove_maintainer" in self.request.params:
if not can_edit_role:
raise HTTPForbidden()
user = User.by_login(self.session, self.request.params["login"])
if user:
maintainers = dict((usr.login, usr) for usr in package.maintainers)
if user.login in maintainers:
package.maintainers.remove(maintainers[user.login])
self.session.add(package)
if "form.remove_owner" in self.request.params:
if not can_edit_role:
raise HTTPForbidden()
user = User.by_login(self.session, self.request.params["login"])
if user:
if user.login in owners:
package.owners.remove(owners[user.login])
self.session.add(package)
if "release_version" in self.request.matchdict:
release = Release.by_version(self.session, package.name, self.request.matchdict["release_version"])
else:
release = package.sorted_releases[0]
return {u"package": package, u"release": release, u"can_edit_role": can_edit_role}
示例7: render
def render(self):
package = Package.by_name(self.session, self.request.matchdict["package_name"])
if not package:
raise HTTPNotFound()
if "release_version" in self.request.matchdict:
release = Release.by_version(self.session, package.name, self.request.matchdict["release_version"])
else:
release = package.sorted_releases[0]
return {u"package": package, u"release": release}
示例8: search
def search(self, spec, operator='and'):
"""
Search the package database using the indicated search spec.
The spec may include any of the keywords described in the above list
(except 'stable_version' and 'classifiers'),
for example: {'description': 'spam'} will search description fields.
Within the spec, a field's value can be a string or a list of strings
(the values within the list are combined with an OR),
for example: {'name': ['foo', 'bar']}.
Valid keys for the spec dict are listed here. Invalid keys are ignored:
name
version
author
author_email
maintainer
maintainer_email
home_page
license
summary
description
keywords
platform
download_url
Arguments for different fields are combined using either "and"
(the default) or "or".
Example: search({'name': 'foo', 'description': 'bar'}, 'or').
The results are returned as a list of dicts
{'name': package name,
'version': package release version,
'summary': package release summary}
"""
api = pypi.proxy
rv = []
# search in proxy
for k, v in spec.items():
rv += api.search({k: v}, True)
# search in local
session = DBSession()
release = Release.search(session, spec, operator)
session.rollback()
rv += [{'name': r.package.name,
'version': r.version,
'summary': r.summary,
# hack https://mail.python.org/pipermail/catalog-sig/2012-October/004633.html
'_pypi_ordering':'',
} for r in release]
return rv
示例9: browse
def browse(self, classifiers):
"""
Retrieve a list of (name, version) pairs of all releases classified
with all of the given classifiers. 'classifiers' must be a list of
Trove classifier strings.
changelog(since)
Retrieve a list of four-tuples (name, version, timestamp, action)
since the given timestamp. All timestamps are UTC values.
The argument is a UTC integer seconds since the epoch.
"""
session = DBSession()
release = Release.by_classifiers(session, classifiers)
rv = [(r.package.name, r.version) for r in release]
return rv
示例10: render
def render(self):
package = Package.by_name(self.session,
self.request.matchdict['package_name'])
if not package:
raise HTTPNotFound()
if 'release_version' in self.request.matchdict:
release = Release.by_version(self.session, package.name,
self.request.matchdict['release_version'])
else:
release = package.sorted_releases[0]
return {u'package': package,
u'release': release,
}
示例11: render
def render(self):
package = Package.by_name(self.session,
self.request.matchdict['package_name'])
if not package:
raise HTTPNotFound()
if 'form.refresh_package' in self.request.params:
package.update_at = None
self.session.add(package)
if 'release_version' in self.request.matchdict:
release = Release.by_version(self.session, package.name,
self.request.matchdict['release_version'])
else:
release = package.sorted_releases[0]
return {u'package': package,
u'release': release,
}
示例12: search
def search(self, spec, operator='and'):
"""
Search the package database using the indicated search spec.
The spec may include any of the keywords described in the above list
(except 'stable_version' and 'classifiers'),
for example: {'description': 'spam'} will search description fields.
Within the spec, a field's value can be a string or a list of strings
(the values within the list are combined with an OR),
for example: {'name': ['foo', 'bar']}.
Valid keys for the spec dict are listed here. Invalid keys are ignored:
name
version
author
author_email
maintainer
maintainer_email
home_page
license
summary
description
keywords
platform
download_url
Arguments for different fields are combined using either "and"
(the default) or "or".
Example: search({'name': 'foo', 'description': 'bar'}, 'or').
The results are returned as a list of dicts
{'name': package name,
'version': package release version,
'summary': package release summary}
"""
session = DBSession()
release = Release.search(session, spec, operator)
session.rollback()
rv = [{'name': r.package.name,
'version': r.version,
'summary': r.summary} for r in release]
return rv
示例13: show_external_release_file
def show_external_release_file(root, request):
"""
Download a release from a download url from its package information.
Must be used with :func:`pyshop.helpers.download.renderer_factory`
to download the release file.
:return: download informations
:rtype: dict
"""
session = DBSession()
release = Release.by_id(session, int(request.matchdict['release_id']))
rv = {'url': release.download_url,
'filename': release.download_url_file,
}
release.downloads += 1
release.package.downloads += 1
session.add(release.package)
session.add(release)
return rv
示例14: render
def render(self):
settings = self.request.registry.settings
if not self.user:
raise exc.HTTPForbidden()
params = self.request.params
if (asbool(settings['pyshop.upload.sanitize'])
and not re.match(settings['pyshop.upload.sanitize.regex'],
params['version']
)):
raise exc.HTTPForbidden()
pkg = Package.by_name(self.session, params['name'])
if pkg and pkg.local:
auth = [user for user in pkg.owners + pkg.maintainers
if user == self.user]
if not auth:
raise exc.HTTPForbidden()
elif not pkg:
pkg = Package(name=params['name'], local=True)
pkg.owners.append(self.user)
content = self.request.POST['content']
input_file = content.file
if asbool(settings.get('pyshop.upload.rewrite_filename', '1')):
# rewrite the filename, do not use the posted one for security
filename = self._guess_filename(params, content.filename)
else:
filename = content.filename
dir_ = os.path.join(settings['pyshop.repository'],
filename[0].lower())
if not os.path.exists(dir_):
os.makedirs(dir_, 0o750)
filepath = os.path.join(dir_, filename)
while os.path.exists(filepath):
log.warning('File %s exists but new upload self.request, deleting'
% filepath)
os.unlink(filepath)
size = 0
with open(filepath, 'wb') as output_file:
input_file.seek(0)
while True:
data = input_file.read(2 << 16)
if not data:
break
size += len(data)
output_file.write(data)
release = Release.by_version(self.session, pkg.name,
params['version'])
if not release:
release = Release(package=pkg,
version=params['version'],
summary=params.get('summary'),
author=self.user,
home_page=params.get('home_page'),
license=params.get('license'),
description=params.get('description'),
keywords=params.get('keywords'),
platform=params.get('platform'),
download_url=params.get('download_url'),
docs_url=params.get('docs_url'),
)
classifiers = params.getall('classifiers')
for name in classifiers:
classifier = Classifier.by_name(self.session, name)
while classifier:
if classifier not in release.classifiers:
release.classifiers.append(classifier)
if classifier not in pkg.classifiers:
pkg.classifiers.append(classifier)
classifier = classifier.parent
rfile = ReleaseFile.by_filename(self.session, release, filename)
if not rfile:
rfile = ReleaseFile(release=release,
filename=filename,
size=size,
md5_digest=params.get('md5_digest'),
package_type=params['filetype'],
python_version=params.get('pyversion'),
comment_text=params.get('comment'),
)
self.session.add(rfile)
self.session.add(release)
pkg.update_at = func.now()
self.session.add(pkg)
return {'release_file': rfile}
示例15: render
def render(self):
package = Package.by_name(self.session,
self.request.matchdict['package_name'])
if not package:
raise HTTPNotFound()
if 'form.refresh_package' in self.request.params:
package.update_at = None
self.session.add(package)
owners = dict((usr.login, usr) for usr in package.owners)
can_edit_role = self.login in owners.keys() and package.local
if 'form.add_role' in self.request.params:
if not can_edit_role:
raise HTTPForbidden()
user = User.by_login(self.session, self.request.params['login'])
if user and user.has_permission('upload_releasefile'):
if self.request.params['role'] == 'owner':
if user.login not in owners:
package.owners.append(user)
else:
maintainers = [usr.login for usr in package.owners]
if user.login not in maintainers:
package.maintainers.append(user)
self.session.add(package)
if 'form.remove_maintainer' in self.request.params:
if not can_edit_role:
raise HTTPForbidden()
user = User.by_login(self.session, self.request.params['login'])
if user:
maintainers = dict((usr.login, usr)
for usr in package.maintainers)
if user.login in maintainers:
package.maintainers.remove(maintainers[user.login])
self.session.add(package)
if 'form.remove_owner' in self.request.params:
if not can_edit_role:
raise HTTPForbidden()
user = User.by_login(self.session, self.request.params['login'])
if user:
if user.login in owners:
package.owners.remove(owners[user.login])
self.session.add(package)
if 'release_version' in self.request.matchdict:
release = Release.by_version(
self.session, package.name,
self.request.matchdict['release_version'])
else:
release = package.sorted_releases[0]
return {u'package': package,
u'release': release,
u'can_edit_role': can_edit_role,
}