当前位置: 首页>>代码示例>>Python>>正文


Python DepotManager.get方法代码示例

本文整理汇总了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
开发者ID:OneGov,项目名称:onegov.file,代码行数:37,代码来源:test_integration.py

示例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
开发者ID:IonicaBizauKitchen,项目名称:Kotti,代码行数:30,代码来源:test_app.py

示例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
开发者ID:adamchainz,项目名称:depot,代码行数:13,代码来源:test_depot_manager.py

示例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
开发者ID:altereg0,项目名称:Kotti,代码行数:15,代码来源:test_file.py

示例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))
开发者ID:amol-,项目名称:depot,代码行数:16,代码来源:views.py

示例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.'
            )
开发者ID:tracim,项目名称:tracim,代码行数:36,代码来源:database.py

示例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()
开发者ID:altereg0,项目名称:Kotti,代码行数:18,代码来源:test_file.py

示例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())
开发者ID:nightmarebadger,项目名称:Kotti,代码行数:35,代码来源:413fa5fcc581_add_filedepot.py

示例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")
开发者ID:infobyte,项目名称:faraday,代码行数:29,代码来源:vulns.py

示例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())
开发者ID:teixas,项目名称:Kotti,代码行数:31,代码来源:413fa5fcc581_add_filedepot.py

示例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()
开发者ID:chatid,项目名称:depot,代码行数:9,代码来源:ming.py

示例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
开发者ID:lebouquetin,项目名称:tracim,代码行数:60,代码来源:serializers.py

示例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
开发者ID:rlam3,项目名称:depot,代码行数:11,代码来源:sqlalchemy.py

示例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()
开发者ID:OneGov,项目名称:onegov.file,代码行数:11,代码来源:conftest.py

示例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'
开发者ID:umeboshi2,项目名称:Kotti,代码行数:11,代码来源:test_app.py


注:本文中的depot.manager.DepotManager.get方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。