本文整理汇总了Python中apps.web.bundles.BundleService类的典型用法代码示例。如果您正苦于以下问题:Python BundleService类的具体用法?Python BundleService怎么用?Python BundleService使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了BundleService类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_context_data
def get_context_data(self, **kwargs):
context = super(BundleListView, self).get_context_data(**kwargs)
service = BundleService()
results = service.items()
context["bundles"] = results
bundles = results
items = []
for bundle in bundles:
item = {
"uuid": bundle["uuid"],
"details_url": "/bundles/{0}".format(bundle["uuid"]),
"name": "",
"title": "<title not specified>",
"creator": "<creator not specified>",
"description": "<description not specified>",
}
if "metadata" in bundle:
metadata = bundle["metadata"]
for (key1, key2) in [("title", "name"), ("creator", None), ("description", None)]:
if key2 is None:
key2 = key1
if key2 in metadata:
item[key1] = metadata[key2]
items.append(item)
context["items"] = items
context["items_label"] = "bundles"
return context
示例2: get
def get(self, request):
user_id = self.request.user.id
logger.debug("WorksheetsListApi: user_id=%s.", user_id)
service = BundleService(self.request.user)
try:
worksheets = service.worksheets()
user_ids = []
user_id_to_worksheets = {}
for worksheet in worksheets:
owner_id = worksheet["owner_id"]
if owner_id in user_id_to_worksheets:
user_id_to_worksheets[owner_id].append(worksheet)
else:
user_id_to_worksheets[owner_id] = [worksheet]
user_ids.append(owner_id)
if len(user_ids) > 0:
users = ClUser.objects.filter(id__in=user_ids)
for user in users:
for worksheet in user_id_to_worksheets[user.id]:
worksheet["owner"] = user.username
return Response(worksheets)
except Exception as e:
logging.error(self.__str__())
logging.error(smart_str(e))
logging.error("")
logging.debug("-------------------------")
tb = traceback.format_exc()
logging.error(tb)
logging.debug("-------------------------")
return Response(status=service.http_status_from_exception(e))
示例3: get
def get(self, request, uuid):
user_id = self.request.user.id
logger.debug("BundleInfo: user_id=%s; uuid=%s.", user_id, uuid)
service = BundleService(self.request.user)
try:
bundle_info = service.get_bundle_info(uuid)
target = (uuid, '')
info = service.get_target_info(target, 2) # 2 is the depth to retrieve
bundle_info['stdout'] = None
bundle_info['stderr'] = None
#if we have std out or err update it.
contents = info.get('contents')
if contents:
for item in contents:
if item['name'] in ['stdout', 'stderr']:
lines = service.head_target((uuid, item['name']), 100)
if lines:
lines = ' '.join(lines)
bundle_info[item['name']] = lines
bundle_info['edit_permission'] = False
if bundle_info['owner_id'] == str(self.request.user.id):
bundle_info['edit_permission'] = True
return Response(bundle_info, content_type="application/json")
except Exception as e:
logging.error(self.__str__())
logging.error(smart_str(e))
logging.error('')
logging.debug('-------------------------')
tb = traceback.format_exc()
logging.error(tb)
logging.debug('-------------------------')
return Response(status=service.http_status_from_exception(e))
示例4: get
def get(self, request, uuid):
user_id = self.request.user.id
logger.debug("BundleInfo: user_id=%s; uuid=%s.", user_id, uuid)
service = BundleService(self.request.user)
try:
bundle_info = service.get_bundle_info(uuid)
target = (uuid, '')
info = service.get_target_info(target, 2) # 2 is the depth to retrieve
bundle_info['stdout'] = None
bundle_info['stderr'] = None
#if we have std out or err update it.
contents = info.get('contents')
if contents:
for item in contents:
if item['name'] in ['stdout', 'stderr']:
lines = service.head_target((uuid, item['name']), 100)
if lines:
import base64
lines = ' '.join(map(base64.b64decode, lines))
bundle_info[item['name']] = lines
bundle_info['edit_permission'] = False
if bundle_info['owner_id'] == str(self.request.user.id):
bundle_info['edit_permission'] = True
return Response(bundle_info, content_type="application/json")
except Exception as e:
tb = traceback.format_exc()
log_exception(self, e, tb)
return Response({"error": smart_str(e)}, status=500)
示例5: post
def post(self, request, uuid):
user = self.request.user
if not user.id:
return Response(None, status=401)
data = json.loads(request.body)
worksheet_name = data['name']
worksheet_uuid = data['uuid']
owner_id = data['owner_id']
lines = data['lines']
if not (worksheet_uuid == uuid):
return Response(None, status=403)
logger.debug("WorksheetUpdate: owner=%s; name=%s; uuid=%s", owner_id, worksheet_name, uuid)
service = BundleService(self.request.user)
try:
service.parse_and_update_worksheet(worksheet_uuid, lines)
return Response({})
except Exception as e:
logging.error(self.__str__())
logging.error('ERROR')
logging.error(smart_str(e))
logging.error('-------------------------')
tb = traceback.format_exc()
logging.error(tb)
logging.error('-------------------------')
return Response({'error': smart_str(e)})
示例6: get_context_data
def get_context_data(self, **kwargs):
context = super(BundleDetailView, self).get_context_data(**kwargs)
uuid = kwargs.get('uuid')
service = BundleService(self.request.user)
bundle_info = service.get_bundle_info(uuid)
context['bundle'] = bundle_info
return context
示例7: post
def post(self, request):
user_id = self.request.user.id
postdata = json.loads(request.body)
# logger.debug("BundleSearch: user_id=%s; search_string=%s.", user_id, search_string)
service = BundleService(self.request.user)
try:
#TODO CHECKING
command = postdata['data'][-1].strip("'")
items = postdata['data'][:-1]
targets = {}
for item in items:
(key, target) = item.split(':', 1)
if key == '':
key = target # Set default key to be same as target
targets[key] = [target, ''] # TODO PATH
# targets[key] = self.parse_target(client, worksheet_uuid, target)
new_bundle_uuid = service.derive_bundle('run', targets, postdata['worksheet_uuid'], command)
return Response({'uuid': new_bundle_uuid}, content_type="application/json")
except Exception as e:
logging.error(self.__str__())
logging.error(smart_str(e))
logging.error('')
logging.debug('-------------------------')
tb = traceback.format_exc()
logging.error(tb)
logging.debug('-------------------------')
return Response(status=service.http_status_from_exception(e))
示例8: get
def get(self, request, uuid, path):
user_id = self.request.user.id
service = BundleService()
try:
content_type = BundleFileContentApi._content_type(path)
return StreamingHttpResponse(service.read_file(uuid, path), content_type=content_type)
except Exception as e:
return Response(status=service.http_status_from_exception(e))
示例9: get
def get(self, request):
user_id = self.request.user.id
logger.debug("WorksheetsListApi: user_id=%s.", user_id)
service = BundleService()
try:
worksheets = service.worksheets()
return Response(worksheets)
except Exception as e:
return Response(status=service.http_status_from_exception(e))
示例10: BundleDownload
def BundleDownload(request, uuid):
service = BundleService(request.user)
local_path, temp_path = service.download_target(uuid, return_zip=True)
item = service.get_bundle_info(uuid)
response = StreamingHttpResponse(service.read_file(uuid, local_path), content_type="zip")
response['Content-Disposition'] = 'attachment; filename="%s.zip"' % item['metadata']['name']
return response
示例11: BundleDownload
def BundleDownload(request, uuid):
"""
Return a stream with the contents of the bundle (zip file if necessary).
This is the same code as BundleFileContentApi.
"""
service = BundleService(request.user)
stream, name, content_type = service.read_target((uuid, ""))
response = StreamingHttpResponse(stream, content_type=content_type)
response["Content-Disposition"] = 'filename="%s"' % name
return response
示例12: get
def get(self, request, uuid):
user_id = self.request.user.id
logger.debug("WorksheetContent: user_id=%s; uuid=%s.", user_id, uuid)
service = BundleService(self.request.user)
try:
worksheet = service.worksheet(uuid)
owner = ClUser.objects.filter(id=worksheet['owner_id'])[0]
worksheet['owner'] = owner.username
return Response(worksheet)
except Exception as e:
return Response(status=service.http_status_from_exception(e))
示例13: get
def get(self, request):
user_id = self.request.user.id
logger.debug("WorksheetsListApi: user_id=%s.", user_id)
service = BundleService(self.request.user)
try:
worksheets = service.worksheets()
return Response(worksheets)
except Exception as e:
tb = traceback.format_exc()
log_exception(self, e, tb)
return Response({"error": smart_str(e)}, status=500)
示例14: get_context_data
def get_context_data(self, **kwargs):
context = super(BundleDetailView, self).get_context_data(**kwargs)
uuid = kwargs.get("uuid")
service = BundleService(self.request.user)
bundle_info = service.get_bundle_info(uuid)
if bundle_info:
context["bundle"] = bundle_info
context["bundle_title"] = bundle_info.get("metadata", {}).get("name", "")
else:
context["error"] = "Invalid or inaccessible bundle uuid: " + uuid
return context
示例15: recent_worksheets
def recent_worksheets(request_user, limit=3):
"""Used for worksheets in competitions. Issue 1014"""
service = BundleService(request_user)
unsorted_worksheets = service.worksheets()
#if not worksheets:
# return worksheets # just incase the list is empty
sorted_worksheets = sorted(unsorted_worksheets, key=lambda k: k['id'], reverse=True)
worksheets = [(val['uuid'], val['name'], val['owner_name']) for val in sorted_worksheets]
return worksheets[0:limit]