本文整理汇总了Python中cloudrunner_server.api.util.JsonOutput.contents方法的典型用法代码示例。如果您正苦于以下问题:Python JsonOutput.contents方法的具体用法?Python JsonOutput.contents怎么用?Python JsonOutput.contents使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cloudrunner_server.api.util.JsonOutput
的用法示例。
在下文中一共展示了JsonOutput.contents方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: browse
# 需要导入模块: from cloudrunner_server.api.util import JsonOutput [as 别名]
# 或者: from cloudrunner_server.api.util.JsonOutput import contents [as 别名]
def browse(self, repository, *args, **kwargs):
if not repository:
return O.error(msg="No repo selected")
args = list([a for a in args if a])
full_path = "/".join(args)
name = '/'
if args:
args.insert(0, '')
name = "/".join(args)
if not name.endswith('/'):
name = name + "/"
parent, _, __ = name.rstrip("/").rpartition("/")
if parent:
parent = parent + "/"
else:
parent = None
repo = Repository.visible(request).filter(
Repository.name == repository).first()
if not repo:
return O.error(msg="Repo not found")
if repo.linked:
parent_repo = repo
repo = repo.linked
repository = repo.name
root_folder = request.db.query(Folder).filter(
Folder.full_name == name, Folder.repository == repo).one()
else:
root_folder = Folder.visible(
request, repository, parent=parent).filter(
Folder.full_name == name).one()
def order(lst):
return [r.version for r in sorted([item for item in lst],
key=lambda x: x.created_at,
reverse=True)
if not r.draft][-20:] # last 20 versions
def rev(lst):
revs = [r.version for r in sorted([item for item in lst],
key=lambda x: x.created_at,
reverse=True)
if not r.draft]
if revs:
return revs[0]
else:
return None
rels = [('owner.username', 'owner'), ('history', 'version', rev)]
show_versions = (bool(kwargs.get('show_versions'))
and not kwargs.get('show_versions')
in ['0', 'false', 'False'])
if show_versions:
rels.append(('history', 'versions', order))
if repo.type == 'cloudrunner':
subfolders = Folder.visible(
request, repository, parent=name).all()
scripts = request.db.query(Script).join(Folder).join(Revision)
scripts = scripts.filter(
Script.folder == root_folder,
Folder.full_name == name).all()
folders = [f.serialize(
skip=['repository_id', 'parent_id', 'owner_id'],
rel=[('owner.username', 'owner')],
editable=lambda f: repo.editable(request))
for f in subfolders]
scripts = sorted([s.serialize(
skip=['folder_id', 'owner_id'], rel=rels,
editable=lambda s: repo.editable(request))
for s in scripts],
key=lambda s: (s['mime_type'], s['name']))
return O.contents(folders=folders, scripts=scripts,
editable=repo.editable(request),
owner=root_folder.owner.username)
else:
# External repo
plugin = PluginRepoBase.find(repo.type)
if not plugin:
return O.error(msg="Plugin for repo type %s not found!" %
repo.type)
plugin = plugin(parent_repo.credentials.auth_user,
parent_repo.credentials.auth_pass,
parent_repo.credentials.auth_args)
subfolders, scripts = [], []
try:
contents, last_modified, etag = plugin.browse(
repository, name, last_modified=root_folder.etag)
if not contents:
return O.error(msg="Cannot browse %s repo" % repo.type)
root_folder.created_at = last_modified
root_folder.etag = etag
subfolders = root_folder.subfolders
scripts = list(request.db.query(Script).join(Folder).filter(
Script.folder == root_folder,
#.........这里部分代码省略.........
示例2: sorted
# 需要导入模块: from cloudrunner_server.api.util import JsonOutput [as 别名]
# 或者: from cloudrunner_server.api.util.JsonOutput import contents [as 别名]
folders = [f.serialize(
skip=['repository_id', 'parent_id', 'owner_id'],
rel=[('owner.username', 'owner', lambda *args: repo.type),
('created_at', 'created_at', created_at_eval)],
editable=lambda s: False)
for f in subfolders]
rels[0] = ('owner.username', 'owner', lambda *args: repo.type)
scripts = sorted([s.serialize(skip=['folder_id', 'owner_id'],
rel=rels,
editable=lambda s: False)
for s in scripts],
key=lambda s: (s['mime_type'], s['name']))
contents = dict(folders=folders, scripts=scripts)
return O.contents(owner=request.user.username,
editable=repo.editable(request),
**contents)
@expose('json')
@wrap_command(Script)
def revisions(self, repository, *args, **kwargs):
path = "/".join(args)
path.rstrip("/")
if not path.startswith("/"):
path = "/" + path
path, _, script = path.rpartition('/')
path = path + '/'
scr = Script.visible(request,
repository,