本文整理汇总了Python中cloudrunner_server.api.util.JsonOutput.script方法的典型用法代码示例。如果您正苦于以下问题:Python JsonOutput.script方法的具体用法?Python JsonOutput.script怎么用?Python JsonOutput.script使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cloudrunner_server.api.util.JsonOutput
的用法示例。
在下文中一共展示了JsonOutput.script方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: script
# 需要导入模块: from cloudrunner_server.api.util import JsonOutput [as 别名]
# 或者: from cloudrunner_server.api.util.JsonOutput import script [as 别名]
def script(self, repository, *args, **kwargs):
path = "/".join(args)
full_path = "/".join([repository] + list(args))
repo_path, name, script, rev = Script.parse(full_path)
parent, _, __ = name.rstrip("/").rpartition("/")
if parent:
parent = parent + "/"
else:
parent = None
repo = Repository.visible(request).filter(
Repository.name == repo_path).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()
editable = repo.editable(request)
scr = [s for s in root_folder.scripts if s.name == script]
if not scr:
return O.error(msg="Not found")
scr = scr[0]
repo = scr.folder.repository
if repo.type == "cloudrunner":
rev = scr.contents(request, **kwargs)
if rev:
if request.if_modified_since:
req_modified = request.if_modified_since
script_modified = pytz.utc.localize(rev.created_at)
if req_modified == script_modified:
return redirect(code=304)
else:
response.last_modified = rev.created_at.strftime('%c')
response.cache_control.private = True
response.cache_control.max_age = 1
revisions = sorted([r.serialize(
skip=['id', 'script_id', 'draft', 'content', 'meta'],
rel=[("created_at", "created_at", lambda d: d)])
for r in scr.history
if not r.draft], key=lambda r: r["created_at"],
reverse=True)
else:
plugin = PluginRepoBase.find(repo.type)
if not plugin:
return O.error("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)
last_rev = scr.contents(request)
try:
contents, last_modified, rev, etag = plugin.contents(
repo.name, path, last_modified=last_rev.created_at
if last_rev else None)
exists = scr.contents(request, rev=rev)
if not exists:
exists = Revision(created_at=last_modified,
version=rev, script=scr,
content=contents)
else:
exists.content = contents
exists.created_at = last_modified
request.db.add(exists)
rev = exists
revisions = [dict(version="HEAD", created_at=None)]
except NotModified:
revisions = [dict(version="HEAD", created_at=None)]
rev = last_rev
except NotFound:
return O.error(msg="The specified repository was not found")
except NotAccessible:
return O.error(msg="Cannot connect to %s API" %
plugin.type)
if request.if_modified_since:
req_modified = request.if_modified_since
script_modified = pytz.utc.localize(rev.created_at)
if req_modified == script_modified:
return redirect(code=304)
response.last_modified = rev.created_at.strftime('%c')
response.cache_control.private = True
response.cache_control.max_age = 1
meta = {}
if scr.mime_type == 'text/script':
meta_data = rev.meta
#.........这里部分代码省略.........