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


Python Snapshot.create方法代码示例

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


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

示例1: create_snapshot_extended

# 需要导入模块: from pyasm.biz import Snapshot [as 别名]
# 或者: from pyasm.biz.Snapshot import create [as 别名]
def create_snapshot_extended(search_key, context, snapshot_type=None, is_revision=False, is_latest=True, is_current=False, description=None, version=None, level_key=None, update_versionless=True, file_types=None, file_names=None, file_paths=None, relative_paths=None, source_paths=None, file_sizes=None, exts=None, keep_file_name=True, repo_name=None, virtual_snapshot=None, mode=None, create_icon=False):
    from pyasm.biz import Snapshot
    from pyasm.checkin import FileAppendCheckin
    from pyasm.search import Search

    api = server.server

    sobjects = api._get_sobjects(search_key)
    sobject = sobjects[0]

    # get the level object
    if level_key:
        levels = api._get_sobjects(level_key)
        level = levels[0]
        level_type = level.get_search_type()
        level_id = level.get_id()
    else:
        level_type = None
        level_id = None

    if not description:
        description = 'No description'
    if not snapshot_type:
        snapshot_type = 'file'

    if mode == 'inplace':
        version_file_paths = []
        versionless_file_paths = []
        version_relative_paths = []
        versionless_relative_paths = []
        for p, fn in zip(virtual_snapshot['versioned']['paths'], virtual_snapshot['versioned']['names']):
            version_file_paths.append('{0}/{1}'.format(p, fn))
            version_relative_paths.append(p)
        for p, fn in zip(virtual_snapshot['versionless']['paths'], virtual_snapshot['versionless']['names']):
            versionless_file_paths.append('{0}/{1}'.format(p, fn))
            versionless_relative_paths.append(p)
    if not version:
        ver = server.eval("@MAX(sthpw/snapshot['context', '{0}'].version)".format(context), search_keys=[search_key])
        if ver:
            version = int(ver) + 1
        else:
            version = 1
    snapshot = Snapshot.create(sobject, snapshot_type=snapshot_type, context=context, description=description, is_revision=is_revision, is_latest=is_latest, is_current=is_current, level_type=level_type, level_id=level_id, commit=False, version=version)

    if repo_name:
        snapshot.set_value('repo', repo_name)
    if is_latest:
        snapshot.set_value('is_latest', 1)
    if is_current:
        snapshot.set_value('is_current', 1)

    snapshot.commit(triggers=True, log_transaction=True)

    dir_naming = None
    file_naming = None

    checkin = FileAppendCheckin(snapshot.get_code(), version_file_paths, file_types, keep_file_name=keep_file_name, mode=mode,
                                source_paths=source_paths, dir_naming=dir_naming, file_naming=file_naming,
                                checkin_type='auto', do_update_versionless=False)
    checkin.execute()

    files_list = checkin.get_file_objects()
    for i, fl in enumerate(files_list):
        fl.set_value(name='st_size', value=file_sizes[i])
        fl.set_value(name='relative_dir', value=version_relative_paths[i])
        fl.commit()

    # update_versionless = False

    if update_versionless:
        # snapshot.update_versionless(snapshot_mode='latest', sobject=sobject, checkin_type='auto')
        versionless_snapshot = snapshot.get_by_sobjects([sobject], context, version=-1)
        if not versionless_snapshot:
            versionless_snapshot = [
                Snapshot.create(sobject, snapshot_type=snapshot_type, context=context, description=description,
                                is_revision=False, is_latest=is_latest, level_type=level_type, level_id=level_id,
                                commit=False, version=-1)]
        if repo_name:
            versionless_snapshot[0].set_value('repo', repo_name)

        # file_objects = versionless_snapshot[0].get_all_file_objects()
        # for file_object in file_objects:
        #     file_object.delete(triggers=False)

        search = Search('sthpw/file')
        search.add_op_filters([('snapshot_code', versionless_snapshot[0].get_code())])
        file_objects = search.get_sobjects()
        for file_object in file_objects:
            file_object.delete(triggers=False)

        versionless_snapshot[0].set_value('snapshot', '<snapshot/>')
        versionless_snapshot[0].set_value('login', snapshot.get_attr_value('login'))
        versionless_snapshot[0].set_value('timestamp', snapshot.get_attr_value('timestamp'))
        versionless_snapshot[0].set_value('description', description)
        versionless_snapshot[0].commit(triggers=True, log_transaction=True)
        #snapshot.update_versionless(snapshot_mode='latest', sobject=sobject, checkin_type='auto')

        checkin_versionless = FileAppendCheckin(versionless_snapshot[0].get_code(), versionless_file_paths, file_types, keep_file_name=keep_file_name, mode=mode,
                                    source_paths=source_paths, dir_naming=dir_naming, file_naming=file_naming,
                                    checkin_type='auto', do_update_versionless=False)
#.........这里部分代码省略.........
开发者ID:listyque,项目名称:TACTIC-Handler,代码行数:103,代码来源:tactic_query.py

示例2: _test_preallocation_checkin

# 需要导入模块: from pyasm.biz import Snapshot [as 别名]
# 或者: from pyasm.biz.Snapshot import create [as 别名]
    def _test_preallocation_checkin(self):

        snapshot_type="file"
        context="preallocation"
        file_name = 'whatever.jpg'
        file_type = 'jpg'


        # create an empty snapshot
        snapshot = Snapshot.create(self.person, snapshot_type=snapshot_type, context=context)

        # preallocate with no name or type
        path = snapshot.get_preallocated_path()
        server = Config.get_value("install", "server")
        if server:
            expected = "%s_preallocation_%s_v001" % (self.person.get_code(), server)
        else:
            expected = "%s_preallocation_v001" % (self.person.get_code())

        self.assertEquals(True, path.endswith( expected ) )

        # preallocate with a file name and file type
        # since it's meant for FileAppendCheckin, the checkin_type should be 'strict'
        path = snapshot.get_preallocated_path(file_type, file_name, checkin_type='strict')
        if server:
            self.assertEquals(True, None != re.search('unittest/person/\w+/preallocation/whatever_preallocation_\w+_v001.jpg$', path) )
        else:
            self.assertEquals(True, None != re.search('unittest/person/\w+/preallocation/whatever_preallocation_v001.jpg$', path) )

        # create a file directly in the path location and register in
        # transaction
        f = open(path, 'wb')
        f.write("wowow")
        f.close()

        # add this file to the snapshot and force the name
        snapshot_code = snapshot.get_code()
        checkin = FileAppendCheckin(snapshot_code, [path], [file_type], keep_file_name=True, mode='preallocate')
        checkin.execute()

        # check that it worked
        snapshot = checkin.get_snapshot()
        lib_dir = snapshot.get_lib_dir()
        file_name = snapshot.get_file_name_by_type(file_type)
        self.assertEquals(True, os.path.exists("%s/%s" % (lib_dir, file_name) ) )


        # test preallocation on a sequence
        file_name = "images_%0.4d.png"
        file_type = 'sequence'
        file_range = FileRange(1, 5)

        # should specify strict checkin_type for Append checkin after
        path = snapshot.get_preallocated_path(file_type=file_type, file_name=file_name, checkin_type='strict')
        # imitate a render by building files directly to the path
        for i in range(1,6):
            cur_path = path % i
            f = open(cur_path, 'wb')
            f.write("wowow")
            f.close()

        # register these files
        snapshot_code = snapshot.get_code()

        # should specify strict checkin_type for Append checkin
        checkin = FileGroupAppendCheckin(snapshot_code, [path], [file_type], file_range, \
                keep_file_name=True, mode='preallocate', checkin_type='strict')
        checkin.execute()

        snapshot = checkin.get_snapshot()

        # get the file paths
        file_names = snapshot.get_expanded_file_names(file_type)
        lib_dir = snapshot.get_lib_dir()
        for file_name in file_names:
            path = "%s/%s" % (lib_dir, file_name)
            self.assertEquals(True, os.path.exists(path)) 
开发者ID:mincau,项目名称:TACTIC,代码行数:79,代码来源:checkin_test.py

示例3: get_virtual_snapshot_extended

# 需要导入模块: from pyasm.biz import Snapshot [as 别名]
# 或者: from pyasm.biz.Snapshot import create [as 别名]
def get_virtual_snapshot_extended(search_key, context, snapshot_type="file", is_revision=False, level_key=None, file_type=['main'], file_name=[''], postfixes=None, subfolders=None, keep_file_name=False, ext=[''], version=None):
    '''creates a virtual snapshot and returns a path that this snapshot
    would generate through the naming conventions''

    @params
    snapshot creation:
    -----------------
    search_key - a unique identifier key representing an sobject
    context - the context of the checkin
    snapshot_type - [optional] descibes what kind of a snapshot this is.
        More information about a snapshot type can be found in the
        prod/snapshot_type sobject
    level_key - the unique identifier of the level that this
        is to be checked into

    path creation:
    --------------
    file_type: the type of file that will be checked in.  Some naming
        conventions make use of this information to separate directories
        for different file types
    file_name: the desired file name of the preallocation.  This information
        may be ignored by the naming convention or it may use this as a
        base for the final file name
    ext: force the extension of the file name returned

    @return
    path as determined by the naming conventions
    '''

    # getting virtual snapshots
    import json
    from pyasm.biz import Snapshot
    from pyasm.biz import Project
    from pyasm.search import SearchType
    api = server.server

    sobjects = api._get_sobjects(search_key)
    sobject = sobjects[0]

    result_dict = {'versionless': {'paths': [], 'names': []}, 'versioned': {'paths': [], 'names': []}}

    # get the level object
    if level_key:
        levels = api._get_sobjects(level_key)
        level = levels[0]
        level_type = level.get_search_type()
        level_id = level.get_id()
    else:
        level_type = None
        level_id = None

    description = "No description"

    if len(file_name) > 1:
        keep_file_name = True
    if len(set(file_type)) != 1:
        keep_file_name = False

    if not postfixes:
        postfixes = []
        for fn in range(len(file_name)):
            postfixes.append('')

    if not subfolders:
        subfolders = []
        for fn in range(len(file_name)):
            subfolders.append('')

    def prepare_filename(filenaming, f_l, ex, postfix):
        if keep_file_name:
            if postfix:
                result_file_name = f_l + '_' + postfix + '.' + ex
            else:
                result_file_name = f_l + '.' + ex
        else:
            name_ext = filenaming.get_file_name()
            if postfix:
                result_file_name = name_ext.replace('.' + ex, '_' + postfix + '.' + ex)
            else:
                result_file_name = name_ext
        return result_file_name

    def prepare_folder(d, sub):
        if sub:
            return d + '/' + sub
        else:
            return d

    for i, fl in enumerate(file_name):
        if not fl:
            fl = sobject.get_code()
            if not fl:
                fl = sobject.get_name()
            if not fl:
                fl = "unknown"

        file_object = SearchType.create("sthpw/file")
        file_object.set_value("file_name", fl)
        file_object.set_value("type", file_type[i])
        file_naming = Project.get_file_naming()
#.........这里部分代码省略.........
开发者ID:listyque,项目名称:TACTIC-Handler,代码行数:103,代码来源:tactic_query.py


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