本文整理汇总了Python中mediacrush.objects.File类的典型用法代码示例。如果您正苦于以下问题:Python File类的具体用法?Python File怎么用?Python File使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了File类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: frame
def frame(self, id):
send = self._send_file(id)
if send:
return send
# We only want to maintain one page for mobile, not a dozen
if (
request.user_agent.platform in ["android", "iphone", "ipad"]
or "windows phone" in request.user_agent.string.lower()
):
return redirect("/" + id, code=302)
klass = RedisObject.klass(id)
if klass is Album:
album = klass.from_hash(id)
v = _album_params(album)
v["embedded"] = True
v["filename"] = id
return render_template("album-embedded.html", **v)
if klass is not File:
abort(404)
f = File.from_hash(id)
template_params = _template_params(f)
template_params["embedded"] = True
return render_template("direct.html", **template_params)
示例2: process_file
def process_file(path, h, ignore_limit):
f = File.from_hash(h)
result = detect(path)
processor = result['type'] if result else 'default'
if processor == 'default': # Unrecognised file type
failed = FailedFile(hash=h, status="unrecognised")
failed.save()
delete_file(f)
return
metadata = result['metadata'] if result else {}
processor_state = result['processor_state'] if result else {}
f.processor = processor
setattr(f.flags, 'nsfw', False)
if result and result['flags']:
for flag, value in result['flags'].items():
setattr(f.flags, flag, value)
f.save()
task = convert_file.s(h, path, processor, metadata, processor_state, ignore_limit)
task_result = task.freeze() # This sets the taskid, so we can pass it to the UI
# This chord will execute `syncstep` and `asyncstep`, and `cleanup` after both of them have finished.
c = chord(task, cleanup.s(path, h))
c.apply_async()
f.taskid = task_result.id
f.save()
示例3: report
def report(self, id):
rate_limit_update(1, section="report")
if not current_app.debug and rate_limit_exceeded(section="report"):
return {'error': 413}, 413
f = File.from_hash(id)
f.add_report()
return render_template("report.html")
示例4: process_file
def process_file(path, h):
f = File.from_hash(h)
result = detect(path)
processor = result['type'] if result else 'default'
metadata = result['metadata'] if result else {}
processor_state = result['processor_state'] if result else {}
f.processor = processor
if result and result['flags']:
for flag, value in result['flags'].items():
setattr(f.flags, flag, value)
f.save()
task = convert_file.s(h, path, processor, metadata, processor_state)
task_result = task.freeze() # This sets the taskid, so we can pass it to the UI
# This chord will execute `syncstep` and `asyncstep`, and `cleanup` after both of them have finished.
c = chord(task, cleanup.s(path, h))
c.apply_async()
f.taskid = task_result.id
f.save()
示例5: fragment
def fragment(self, id):
klass = RedisObject.klass(id)
if klass is not File:
abort(404)
f = File.from_hash(id)
params = _template_params(f)
params['album'] = True
return render_template(params['fragment'], **params)
示例6: cleanup
def cleanup(results, path, h):
f = File.from_hash(h)
os.unlink(path)
if f.status in ["internal_error", "error", "timeout", "unrecognised"]:
failed = FailedFile(hash=h, status=f.status) # Create a "failed file" record
failed.save()
delete_file(f)
示例7: status
def status(self, id):
klass = RedisObject.klass(id)
if klass is not File:
abort(404)
f = File.from_hash(id)
template_params = _template_params(f)
if f.status in ['done', 'ready']:
return tor_redirect('/' + f.hash)
return render_template("status.html", **_template_params(f))
示例8: _upload_object
def _upload_object(result, status):
if status == 200:
return {'hash': result}
else:
resp = {'error': status}
if status == 409:
f = _file_object(File.from_hash(result))
resp[result] = f
resp['hash'] = result
return resp, status
示例9: convert_file
def convert_file(self, h, path, p, extra):
f = File.from_hash(h)
if p not in processor_table:
p = 'default'
processor = processor_table[p](path, f, extra)
# Execute the synchronous step.
processor.sync()
# Save compression information
f = File.from_hash(h) # Reload file; user might have changed the config vector while processing
f.compression = compression_rate(path, f)
f.save()
# Notify frontend: sync step is done.
self.update_state(state="READY")
# Execute the asynchronous step.
processor.important = False
processor.async()
示例10: _upload_f
def _upload_f(f, filename):
result = upload(f, filename)
if not isinstance(result, tuple):
return {'hash': result}
else:
h, status = result
resp = {'error': status}
if status == 409:
f = _file_object(File.from_hash(h))
resp[h] = f
resp['hash'] = h
return resp, status
示例11: process_file
def process_file(path, h):
f = File.from_hash(h)
p, extra = detect(path)
f.processor = p
f.save()
task = convert_file.s(h, path, p, extra)
task_result = task.freeze() # This sets the taskid, so we can pass it to the UI
# This chord will execute `syncstep` and `asyncstep`, and `cleanup` after both of them have finished.
c = task | cleanup.s(path, h)
c.apply_async()
f.taskid = task_result.id
f.save()
示例12: get
def get(self, id, layout):
send = self._send_file(id)
if send:
return send
klass = RedisObject.klass(id)
if klass is Album:
album = klass.from_hash(id)
v = _album_params(album)
return render_template("albums/%s.html" % layout, **v)
if klass is not File:
abort(404)
f = File.from_hash(id)
return render_template("view.html", **_template_params(f))
示例13: status
def status(self, h):
klass = RedisObject.klass(h)
if not klass:
return {'error': 404}, 404
if klass is not File:
return {'error': 415}, 415
f = File.from_hash(h)
ret = {'status': f.status}
if ret['status'] == 'done':
ret[h] = _file_object(f)
ret['hash'] = h
return ret
示例14: direct
def direct(self, id):
send = self._send_file(id)
if send:
return send
klass = RedisObject.klass(id)
if klass is Album:
album = klass.from_hash(id)
v = _album_params(album)
return render_template("album.html", **v)
if klass is not File:
abort(404)
f = File.from_hash(id)
template_params = _template_params(f)
return render_template("direct.html", **template_params)
示例15: process_file
def process_file(path, h, ignore_limit):
t = time.time() + 2
while True:
f = File.from_hash(h)
if f or time.time() > t:
break
time.sleep(0.05) # Wait for Redis to catch up
try:
result = detect(path)
processor = result['type'] if result else 'default'
except:
processor = 'default'
finally:
if processor == 'default': # Unrecognised file type
failed = FailedFile(hash=h, status="unrecognised")
failed.save()
delete_file(f)
return
metadata = result['metadata'] if result else {}
processor_state = result['processor_state'] if result else {}
f.processor = processor
queue = "priority" if processor.startswith("image") else "celery"
setattr(f.flags, 'nsfw', False)
if result and result['flags']:
for flag, value in result['flags'].items():
setattr(f.flags, flag, value)
f.save()
args = [h, path, processor, metadata, processor_state, ignore_limit]
task = signature("mediacrush.tasks.convert_file", args=args, options={'queue': queue})
task_result = task.freeze() # This sets the taskid, so we can pass it to the UI
# This chord will execute `syncstep` and `asyncstep`, and `cleanup` after both of them have finished.
c = chord(task, cleanup.s(path, h))
c.apply_async()
f.taskid = task_result.id
f.save()