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


Python manager.DepotManager类代码示例

本文整理汇总了Python中depot.manager.DepotManager的典型用法代码示例。如果您正苦于以下问题:Python DepotManager类的具体用法?Python DepotManager怎么用?Python DepotManager使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了DepotManager类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_configure_filedepot

    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:Kotti,项目名称:Kotti,代码行数:28,代码来源:test_app.py

示例2: configure_filedepot

def configure_filedepot(settings):

    config = extract_depot_settings('kotti.depot.', settings)
    for conf in config:
        name = conf.pop('name')
        if name not in DepotManager._depots:
            DepotManager.configure(name, conf, prefix='')
开发者ID:gitter-badger,项目名称:Kotti,代码行数:7,代码来源:filedepot.py

示例3: test_invalid_mountpoint

 def test_invalid_mountpoint(self):
     try:
         DepotManager.make_middleware(self.wsgi_app, mountpoint='hello')
     except ValueError as err:
         assert 'mountpoint must be an absolute path' in str(err)
     else:
         assert False, 'Should have raised ValueError'
开发者ID:amol-,项目名称:depot,代码行数:7,代码来源:test_wsgi_middleware.py

示例4: test_application_separation

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,代码行数:35,代码来源:test_integration.py

示例5: upgrade

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,代码行数:29,代码来源:413fa5fcc581_add_filedepot.py

示例6: configure_filedepot

def configure_filedepot(settings: Dict[str, str]) -> None:

    config = extract_depot_settings("kotti.depot.", settings)
    for conf in config:
        name = conf.pop("name")
        if name not in DepotManager._depots:
            DepotManager.configure(name, conf, prefix="")
开发者ID:Kotti,项目名称:Kotti,代码行数:7,代码来源:filedepot.py

示例7: test_public_url_gets_redirect

    def test_public_url_gets_redirect(self):
        try:
            global S3Storage
            from depot.io.awss3 import S3Storage
        except ImportError:
            raise SkipTest('Boto not installed')

        env = os.environ
        access_key_id = env.get('AWS_ACCESS_KEY_ID')
        secret_access_key = env.get('AWS_SECRET_ACCESS_KEY')
        if access_key_id is None or secret_access_key is None:
            raise SkipTest('Amazon S3 credentials not available')

        PID = os.getpid()
        NODE = str(uuid.uuid1()).rsplit('-', 1)[-1]  # Travis runs multiple tests concurrently
        default_bucket_name = 'filedepot-%s' % (access_key_id.lower(), )
        cred = (access_key_id, secret_access_key)
        bucket_name = 'filedepot-testfs-%s-%s-%s' % (access_key_id.lower(), NODE, PID)

        DepotManager.configure('awss3', {'depot.backend': 'depot.io.awss3.S3Storage',
                                         'depot.access_key_id': access_key_id,
                                         'depot.secret_access_key': secret_access_key,
                                         'depot.bucket': bucket_name})
        DepotManager.set_default('awss3')

        app = self.make_app()
        new_file = app.post('/create_file').json

        file_path = DepotManager.url_for('%(uploaded_to)s/%(last)s' % new_file)
        uploaded_file = app.get(file_path)
        assert uploaded_file.body == FILE_CONTENT, uploaded_file
开发者ID:dirn,项目名称:depot,代码行数:31,代码来源:test_wsgi_middleware.py

示例8: upgrade

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,代码行数:33,代码来源:413fa5fcc581_add_filedepot.py

示例9: setup

def setup():
    setup_database()

    DepotManager._clear()
    DepotManager.configure('default', {'depot.storage_path': './lfs'})
    DepotManager.configure('another', {'depot.storage_path': './lfs'})
    DepotManager.alias('another_alias', 'another')
    DepotManager.make_middleware(None)
开发者ID:chatid,项目名称:depot,代码行数:8,代码来源:test_fields_sqlalchemy.py

示例10: configure_filedepot

def configure_filedepot(settings):
    from kotti.util import extract_depot_settings
    from depot.manager import DepotManager

    config = extract_depot_settings("kotti.depot.", settings)
    for conf in config:
        name = conf.pop("name")
        if name not in DepotManager._depots:
            DepotManager.configure(name, conf, prefix="")
开发者ID:altereg0,项目名称:Kotti,代码行数:9,代码来源:filedepot.py

示例11: test_prevent_configuring_two_storages_with_same_name

    def test_prevent_configuring_two_storages_with_same_name(self):
        DepotManager.configure('first', {'depot.storage_path': './lfs'})

        try:
            DepotManager.configure('first', {'depot.storage_path': './lfs2'})
        except RuntimeError:
            pass
        else:
            assert False, 'Should have raised RunetimeError here'
开发者ID:adamchainz,项目名称:depot,代码行数:9,代码来源:test_depot_manager.py

示例12: configure_depot

def configure_depot():
    """Configure Depot."""
    depot_storage_name = context.config.get_main_option('depot_storage_name')
    depot_storage_path = context.config.get_main_option('depot_storage_dir')
    depot_storage_settings = {'depot.storage_path': depot_storage_path}
    DepotManager.configure(
        depot_storage_name,
        depot_storage_settings,
    )
开发者ID:lebouquetin,项目名称:tracim,代码行数:9,代码来源:f3852e1349c4_all_files_only_on_disk.py

示例13: depot

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,代码行数:9,代码来源:conftest.py

示例14: configure_depot

def configure_depot():
    """Configure Depot."""
    depot_storage_name = CFG.get_instance().DEPOT_STORAGE_NAME
    depot_storage_path = CFG.get_instance().DEPOT_STORAGE_DIR
    depot_storage_settings = {'depot.storage_path': depot_storage_path}
    DepotManager.configure(
        depot_storage_name,
        depot_storage_settings,
    )
开发者ID:lebouquetin,项目名称:tracim,代码行数:9,代码来源:app_cfg.py

示例15: create_file

    def create_file(self, lang='en'):
        fname = {'en': 'hello.txt',
                 'ru': u_('Крупный'),
                 'it': u_('àèìòù')}.get(lang, 'unknown')

        self.UPLOADED_FILES += [DepotManager.get().create(FILE_CONTENT,
                                                          filename=fname)]
        return dict(files=self.UPLOADED_FILES,
                    uploaded_to=DepotManager.get_default(),
                    last=self.UPLOADED_FILES[-1])
开发者ID:adamchainz,项目名称:depot,代码行数:10,代码来源:test_wsgi_middleware.py


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