本文整理汇总了Python中depot.manager.DepotManager.get方法的典型用法代码示例。如果您正苦于以下问题:Python DepotManager.get方法的具体用法?Python DepotManager.get怎么用?Python DepotManager.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类depot.manager.DepotManager
的用法示例。
在下文中一共展示了DepotManager.get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_application_separation
# 需要导入模块: from depot.manager import DepotManager [as 别名]
# 或者: from depot.manager.DepotManager import get [as 别名]
def test_application_separation(app):
app.set_application_id('apps/one')
ensure_correct_depot(app)
transaction.begin()
files = FileCollection(app.session())
first_id = files.add('readme.txt', b'README').id
transaction.commit()
app.set_application_id('apps/two')
ensure_correct_depot(app)
transaction.begin()
files = FileCollection(app.session())
second_id = files.add('readme.txt', b'README').id
transaction.commit()
assert len(DepotManager.get('apps-one').list()) == 1
assert len(DepotManager.get('apps-two').list()) == 1
client = Client(app)
app.set_application_id('apps/one')
assert client.get('/storage/{}'.format(first_id))\
.status_code == 200
assert client.get('/storage/{}'.format(second_id), expect_errors=True)\
.status_code == 404
app.set_application_id('apps/two')
assert client.get('/storage/{}'.format(first_id), expect_errors=True)\
.status_code == 404
assert client.get('/storage/{}'.format(second_id))\
.status_code == 200
示例2: test_configure_filedepot
# 需要导入模块: from depot.manager import DepotManager [as 别名]
# 或者: from depot.manager.DepotManager import get [as 别名]
def test_configure_filedepot(self, no_filedepots):
from depot.manager import DepotManager
from kotti.filedepot import configure_filedepot
from kotti import tests
tests.TFS1 = Mock(return_value=Mock(marker="TFS1"))
tests.TFS2 = Mock(return_value=Mock(marker="TFS2"))
settings = {
'kotti.depot.0.backend': 'kotti.tests.TFS1',
'kotti.depot.0.name': 'localfs',
'kotti.depot.0.location': '/tmp',
'kotti.depot.1.backend': 'kotti.tests.TFS2',
'kotti.depot.1.uri': 'mongo://',
'kotti.depot.1.name': 'mongo',
}
configure_filedepot(settings)
assert DepotManager.get().marker == 'TFS1'
assert DepotManager.get('localfs').marker == 'TFS1'
assert DepotManager.get('mongo').marker == 'TFS2'
tests.TFS1.assert_called_with(location='/tmp')
tests.TFS2.assert_called_with(uri='mongo://')
del tests.TFS1
del tests.TFS2
示例3: test_aliases
# 需要导入模块: from depot.manager import DepotManager [as 别名]
# 或者: from depot.manager.DepotManager import get [as 别名]
def test_aliases(self):
DepotManager.configure('first', {'depot.storage_path': './lfs'})
DepotManager.configure('second', {'depot.storage_path': './lfs2'})
DepotManager.alias('used_storage', 'first')
storage = DepotManager.get('used_storage')
assert storage.storage_path == './lfs', storage
DepotManager.alias('used_storage', 'second')
storage = DepotManager.get('used_storage')
assert storage.storage_path == './lfs2', storage
示例4: test_session_rollback
# 需要导入模块: from depot.manager import DepotManager [as 别名]
# 或者: from depot.manager.DepotManager import get [as 别名]
def test_session_rollback(self, factory, db_session, filedepot):
from depot.manager import DepotManager
f = factory(data='file content', name=u'content', title=u'content')
id = f.data['file_id']
db_session.add(f)
db_session.flush()
assert id in DepotManager.get()._storage.keys()
db_session.rollback()
assert id not in DepotManager.get()._storage.keys()
assert DepotManager.get().delete.called
示例5: index
# 需要导入模块: from depot.manager import DepotManager [as 别名]
# 或者: from depot.manager.DepotManager import get [as 别名]
def index(request):
if request.method == 'POST':
file = request.FILES['file']
if file:
fileid = DepotManager.get().create(file)
UPLOADED_FILES.append(fileid)
return HttpResponseRedirect('/')
files = [DepotManager.get().get(fileid) for fileid in UPLOADED_FILES]
template = loader.get_template('index.html')
return HttpResponse(template.render({
'files': files
}, request))
示例6: take_action
# 需要导入模块: from depot.manager import DepotManager [as 别名]
# 或者: from depot.manager.DepotManager import get [as 别名]
def take_action(self, parsed_args: argparse.Namespace) -> None:
super(DeleteDBCommand, self).take_action(parsed_args)
config_uri = parsed_args.config_file
# setup_logging(config_uri)
settings = get_appsettings(config_uri)
settings.update(settings.global_conf)
if 'sqlalchemy.url' not in settings or not settings['sqlalchemy.url']:
raise InvalidSettingFile('Wrong or empty sqlalchemy database url,'
'check config file')
engine = get_engine(settings)
app_config = CFG(settings)
app_config.configure_filedepot()
if parsed_args.force:
print('Database deletion begin.')
DeclarativeBase.metadata.drop_all(engine)
print('Database deletion done.')
try:
print('Cleaning depot begin.')
depot = DepotManager.get()
depot_files = depot.list()
for file_ in depot_files:
depot.delete(file_)
print('Cleaning depot done.')
except FileNotFoundError:
print(
'Warning! Can delete depots file, is depot path correctly'
' configured?'
)
else:
raise ForceArgumentNeeded(
'Warning, You should use --force if you really want to'
' delete database.'
)
示例7: test_delete
# 需要导入模块: from depot.manager import DepotManager [as 别名]
# 或者: from depot.manager.DepotManager import get [as 别名]
def test_delete(self, factory, db_session, root, filedepot):
from depot.manager import DepotManager
f = factory(data='file content', name=u'content', title=u'content')
id = f.data['file_id']
root[str(id)] = f
db_session.flush()
assert id in DepotManager.get()._storage.keys()
del root[str(id)]
import transaction
transaction.commit()
assert DepotManager.get().delete.called
assert id not in DepotManager.get()._storage.keys()
示例8: upgrade
# 需要导入模块: from depot.manager import DepotManager [as 别名]
# 或者: from depot.manager.DepotManager import get [as 别名]
def upgrade():
from depot.manager import DepotManager
from depot.fields.upload import UploadedFile
from depot.fields.sqlalchemy import UploadedFileField
from kotti import DBSession, metadata
from kotti.resources import File
t = sa.Table('files', metadata)
t.c.data.type = sa.LargeBinary()
dn = DepotManager.get_default()
update = t.update()
conn = DBSession.connection()
for obj in DBSession.query(File):
uploaded_file = UploadedFile({'depot_name': dn, 'files': []})
uploaded_file._thaw()
uploaded_file.process_content(
obj.data, filename=obj.filename, content_type=obj.mimetype)
stored_file = DepotManager.get().get(uploaded_file['file_id'])
stmt = update.where(
t.c.id == obj.id).values(data=uploaded_file.encode())
res = conn.execute(stmt)
assert res.rowcount == 1
stored_file.last_modified = obj.modification_date
log.info("Migrated {} bytes for File with pk {} to {}/{}".format(
len(obj.data), obj.id, dn, uploaded_file['file_id']))
DBSession.flush()
if DBSession.get_bind().name != 'sqlite': # not supported by sqlite
op.alter_column('files', 'data', type_=UploadedFileField())
示例9: get_attachment
# 需要导入模块: from depot.manager import DepotManager [as 别名]
# 或者: from depot.manager.DepotManager import get [as 别名]
def get_attachment(self, workspace_name, vuln_id, attachment_filename):
vuln_workspace_check = db.session.query(VulnerabilityGeneric, Workspace.id).join(
Workspace).filter(VulnerabilityGeneric.id == vuln_id,
Workspace.name == workspace_name).first()
if vuln_workspace_check:
file_obj = db.session.query(File).filter_by(object_type='vulnerability',
object_id=vuln_id,
filename=attachment_filename).first()
if file_obj:
depot = DepotManager.get()
depot_file = depot.get(file_obj.content.get('file_id'))
if depot_file.content_type.startswith('image/'):
# Image content types are safe (they can't be executed like
# html) so we don't have to force the download of the file
as_attachment = False
else:
as_attachment = True
return flask.send_file(
io.BytesIO(depot_file.read()),
attachment_filename=file_obj.filename,
as_attachment=as_attachment,
mimetype=depot_file.content_type
)
else:
flask.abort(404, "File not found")
else:
flask.abort(404, "Vulnerability not found")
示例10: upgrade
# 需要导入模块: from depot.manager import DepotManager [as 别名]
# 或者: from depot.manager.DepotManager import get [as 别名]
def upgrade():
sa.orm.events.MapperEvents._clear() # avoids filedepot magic
from depot.manager import DepotManager
from depot.fields.upload import UploadedFile
from depot.fields.sqlalchemy import UploadedFileField
from kotti import DBSession, metadata
from kotti.resources import File
t = sa.Table("files", metadata)
t.c.data.type = sa.LargeBinary()
dn = DepotManager.get_default()
for obj in DBSession.query(File):
uploaded_file = UploadedFile({"depot_name": dn, "files": []})
uploaded_file._thaw()
uploaded_file.process_content(obj.data, filename=obj.filename, content_type=obj.mimetype)
stored_file = DepotManager.get().get(uploaded_file["file_id"])
obj.data = uploaded_file.encode()
stored_file.last_modified = obj.modification_date
log.info(
"Migrated {} bytes for File with pk {} to {}/{}".format(len(obj.data), obj.id, dn, uploaded_file["file_id"])
)
DBSession.flush()
if DBSession.get_bind().name != "sqlite": # not supported by sqlite
op.alter_column("files", "data", type_=UploadedFileField())
示例11: _flush_object
# 需要导入模块: from depot.manager import DepotManager [as 别名]
# 或者: from depot.manager.DepotManager import get [as 别名]
def _flush_object(self, obj):
history = self.get_depot_history(obj)
for entry in history.deleted:
depot, fileid = entry.split('/', 1)
depot = DepotManager.get(depot)
depot.delete(fileid)
history.clear()
示例12: serialize_node_for_page
# 需要导入模块: from depot.manager import DepotManager [as 别名]
# 或者: from depot.manager.DepotManager import get [as 别名]
def serialize_node_for_page(content: Content, context: Context):
if content.type in (ContentType.Page, ContentType.File) :
data_container = content
# The following properties are overriden by revision values
if content.revision_to_serialize>0:
for revision in content.revisions:
if revision.revision_id==content.revision_to_serialize:
data_container = revision
break
result = DictLikeClass(
id=content.content_id,
parent=context.toDict(content.parent),
workspace=context.toDict(content.workspace),
type=content.type,
is_new=content.has_new_information_for(context.get_user()),
content=data_container.description,
created=data_container.created,
updated=content.last_revision.updated,
label=data_container.label,
icon=ContentType.get_icon(content.type),
owner=context.toDict(content.first_revision.owner),
last_modification_author=context.toDict(content.last_revision.owner),
status=context.toDict(data_container.get_status()),
links=[],
revision_nb = len(content.revisions),
selected_revision='latest' if content.revision_to_serialize<=0 else content.revision_to_serialize,
history=Context(CTX.CONTENT_HISTORY).toDict(content.get_history()),
is_editable=content.is_editable,
is_deleted=content.is_deleted,
is_archived=content.is_archived,
urls = context.toDict({
'mark_read': context.url(Content.format_path('/workspaces/{wid}/folders/{fid}/{ctype}s/{cid}/put_read', content)),
'mark_unread': context.url(Content.format_path('/workspaces/{wid}/folders/{fid}/{ctype}s/{cid}/put_unread', content))
})
)
if content.type == ContentType.File:
depot = DepotManager.get()
depot_stored_file = depot.get(data_container.depot_file)
result.label = content.label
result['file'] = DictLikeClass(
name=data_container.file_name,
size=depot_stored_file.content_length,
mimetype=data_container.file_mimetype)
return result
if content.type==ContentType.Folder:
value = DictLikeClass(
id=content.content_id,
label=content.label,
is_new=content.has_new_information_for(context.get_user()),
)
return value
raise NotImplementedError
示例13: _session_rollback
# 需要导入模块: from depot.manager import DepotManager [as 别名]
# 或者: from depot.manager.DepotManager import get [as 别名]
def _session_rollback(cls, session, previous_transaction):
if hasattr(session, "_depot_old"):
del session._depot_old
if hasattr(session, "_depot_new"):
for entry in session._depot_new:
depot, fileid = entry.split("/", 1)
depot = DepotManager.get(depot)
depot.delete(fileid)
del session._depot_new
示例14: depot
# 需要导入模块: from depot.manager import DepotManager [as 别名]
# 或者: from depot.manager.DepotManager import get [as 别名]
def depot(temporary_directory):
DepotManager.configure('default', {
'depot.backend': 'depot.io.local.LocalFileStorage',
'depot.storage_path': temporary_directory
})
yield DepotManager.get()
DepotManager._clear()
示例15: test_default_filedepot
# 需要导入模块: from depot.manager import DepotManager [as 别名]
# 或者: from depot.manager.DepotManager import get [as 别名]
def test_default_filedepot(self, db_session):
from kotti import main
from depot.manager import DepotManager
settings = self.required_settings()
with patch('kotti.resources.initialize_sql'):
main({}, **settings)
assert DepotManager.get().__class__.__name__ == 'DBFileStorage'