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


Python DepotManager.get_default方法代码示例

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


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

示例1: upgrade

# 需要导入模块: from depot.manager import DepotManager [as 别名]
# 或者: from depot.manager.DepotManager import get_default [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

示例2: upgrade

# 需要导入模块: from depot.manager import DepotManager [as 别名]
# 或者: from depot.manager.DepotManager import get_default [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

示例3: create_file

# 需要导入模块: from depot.manager import DepotManager [as 别名]
# 或者: from depot.manager.DepotManager import get_default [as 别名]
    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,代码行数:12,代码来源:test_wsgi_middleware.py

示例4: __init__

# 需要导入模块: from depot.manager import DepotManager [as 别名]
# 或者: from depot.manager.DepotManager import get_default [as 别名]
    def __init__(self, content, depot_name=None):
        super(DepotFileInfo, self).__init__()
        self._thaw()

        if isinstance(content, dict):
            object.__setattr__(self, 'original_content', None)
            self.update(content)
        else:
            object.__setattr__(self, 'original_content', content)
            if depot_name is None:
                depot_name = DepotManager.get_default()

            self['depot_name'] = depot_name
            self['files'] = []
            self.process_content(content)

        self._freeze()
开发者ID:cdevienne,项目名称:depot,代码行数:19,代码来源:interfaces.py

示例5: __init__

# 需要导入模块: from depot.manager import DepotManager [as 别名]
# 或者: from depot.manager.DepotManager import get_default [as 别名]
    def __init__(self, content, depot_name=None):
        super(DepotFileInfo, self).__init__()
        self._thaw()

        if isinstance(content, dict):
            object.__setattr__(self, 'original_content', None)
            self.update(content)
        else:
            object.__setattr__(self, 'original_content', content)
            if depot_name is None:
                depot_name = DepotManager.get_default()

            depot_name = DepotManager.resolve_alias(depot_name)
            if not depot_name:
                raise ValueError('Storage has not been found in DEPOT')

            self['depot_name'] = depot_name
            self['files'] = []
            self.process_content(content)

        self._freeze()
开发者ID:adamchainz,项目名称:depot,代码行数:23,代码来源:interfaces.py

示例6: create_file

# 需要导入模块: from depot.manager import DepotManager [as 别名]
# 或者: from depot.manager.DepotManager import get_default [as 别名]
 def create_file(self):
     self.UPLOADED_FILES += [DepotManager.get().create(FILE_CONTENT,
                                                       filename='hello.txt')]
     return dict(files=self.UPLOADED_FILES,
                 uploaded_to=DepotManager.get_default(),
                 last=self.UPLOADED_FILES[-1])
开发者ID:dirn,项目名称:depot,代码行数:8,代码来源:test_wsgi_middleware.py

示例7: upgrade

# 需要导入模块: from depot.manager import DepotManager [as 别名]
# 或者: from depot.manager.DepotManager import get_default [as 别名]
def upgrade():
    from depot.manager import DepotManager
    from depot.fields.upload import UploadedFile
    from sqlalchemy import bindparam, Unicode, Column

    from kotti import DBSession, metadata

    files = sa.Table('files', metadata)
    files.c.data.type = sa.LargeBinary()    # this restores to old column type
    dn = DepotManager.get_default()

    _saved = []

    def process(thing):
        id, data, filename, mimetype = thing
        uploaded_file = UploadedFile({'depot_name': dn, 'files': []})
        uploaded_file._thaw()
        uploaded_file.process_content(
            data, filename=filename, content_type=mimetype)
        _saved.append({'nodeid': id, 'data': uploaded_file.encode()})
        log.info("Saved data for node id {}".format(id))

    query = DBSession.query(
        files.c.id, files.c.data, files.c.filename, files.c.mimetype
    ).order_by(files.c.id).yield_per(10)

    window_size = 10
    window_idx = 0

    log.info("Starting migration of blob data")

    now = time.time()
    while True:
        start, stop = window_size * window_idx, window_size * (window_idx + 1)
        things = query.slice(start, stop).all()
        if things is None:
            break
        for thing in things:
            process(thing)
        if len(things) < window_size:
            break
        window_idx += 1

    log.info("Files written on disk, saving information to DB")

    op.drop_column('files', 'data')
    op.add_column('files', Column('data', Unicode(4096)))
    files.c.data.type = Unicode(4096)

    update = files.update().where(files.c.id == bindparam('nodeid')).\
        values({files.c.data: bindparam('data')})

    def chunks(l, n):
        for i in range(0, len(l), n):
            yield l[i:i + n]

    for cdata in chunks(_saved, 10):
        DBSession.execute(update, cdata)

    log.info("Blob migration completed in {} seconds".format(
        int(time.time() - now)))
开发者ID:adamchainz,项目名称:Kotti,代码行数:63,代码来源:413fa5fcc581_add_filedepot.py

示例8: test_first_configured_is_default

# 需要导入模块: from depot.manager import DepotManager [as 别名]
# 或者: from depot.manager.DepotManager import get_default [as 别名]
 def test_first_configured_is_default(self):
     DepotManager.configure('first', {'depot.storage_path': './lfs'})
     DepotManager.configure('second', {'depot.storage_path': './lfs2'})
     assert DepotManager.get_default() == 'first'
开发者ID:adamchainz,项目名称:depot,代码行数:6,代码来源:test_depot_manager.py

示例9: test_no_configured_is_detected

# 需要导入模块: from depot.manager import DepotManager [as 别名]
# 或者: from depot.manager.DepotManager import get_default [as 别名]
 def test_no_configured_is_detected(self):
     DepotManager.get_default()
开发者ID:adamchainz,项目名称:depot,代码行数:4,代码来源:test_depot_manager.py

示例10: test_changing_default_depot_works

# 需要导入模块: from depot.manager import DepotManager [as 别名]
# 或者: from depot.manager.DepotManager import get_default [as 别名]
 def test_changing_default_depot_works(self):
     DepotManager.configure('first', {'depot.storage_path': './lfs'})
     DepotManager.configure('second', {'depot.storage_path': './lfs2'})
     DepotManager.set_default('second')
     assert DepotManager.get_default() == 'second'
开发者ID:adamchainz,项目名称:depot,代码行数:7,代码来源:test_depot_manager.py


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