コード例 #1
0
def get_dirs_with_naming(search_key=None, process_list=None):
    import json
    from pyasm.biz import Snapshot
    from pyasm.biz import Project
    from pyasm.search import SearchType

    dir_naming = Project.get_dir_naming()

    dirs_dict = {
        'versions': [],
        'versionless': [],
    }

    if process_list:
        processes = process_list
    else:
        from pyasm.biz import Pipeline
        sobjects = server.server._get_sobjects(search_key)
        sobject = sobjects[0]
        pipelines = Pipeline.get_by_search_type(sobject.get_base_search_type())
        processes = pipelines[0].get_process_names()

    search_type, search_code = server.split_search_key(search_key)
    search_type = search_type.split('?')[0]

    for process in processes:
        # querying sobjects every time because we need to refresh naming
        sobject = server.query(search_type,
                               filters=[('code', search_code)],
                               return_sobjects=True,
                               single=True)
        dir_naming.set_sobject(sobject)
        file_object = SearchType.create('sthpw/file')
        dir_naming.set_file_object(file_object)
        snapshot = Snapshot.create(sobject,
                                   snapshot_type='file',
                                   context=process,
                                   commit=False)
        dir_naming.set_snapshot(snapshot)
        dirs_dict['versions'].append(dir_naming.get_dir('relative'))

        snapshot_versionless = Snapshot.create(sobject,
                                               snapshot_type='file',
                                               context=process,
                                               process=process,
                                               commit=False,
                                               version=-1)
        dir_naming.set_snapshot(snapshot_versionless)
        dirs_dict['versionless'].append(dir_naming.get_dir('relative'))

    return json.dumps(dirs_dict, separators=(',', ':'))
コード例 #2
0
def get_dirs_with_naming(search_key=None):
    from pyasm.biz import Snapshot
    from pyasm.biz import Project
    from pyasm.search import SearchType
    sobjects = server.server._get_sobjects(search_key)
    sobject = sobjects[0]
    file_object = SearchType.create('sthpw/file')
    from pyasm.biz import Pipeline
    pipelines = Pipeline.get_by_search_type(sobject.get_base_search_type())
    processes = pipelines[0].get_process_names()
    dir_naming = Project.get_dir_naming()
    dir_naming.set_sobject(sobject)
    dir_naming.set_file_object(file_object)
    dirs_list = []
    for process in processes:
        snapshot = Snapshot.create(sobject,
                                   snapshot_type='file',
                                   context=process,
                                   commit=False,
                                   version=-1)
        dir_naming.set_snapshot(snapshot)
        dirs_list.append(dir_naming.get_dir('relative'))
    return dirs_list
コード例 #3
0
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,
                             keep_file_name=True,
                             repo_name=None,
                             files_info=None,
                             mode=None,
                             create_icon=False):
    import os
    import json
    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 not version:
        ver = server.eval(
            "@MAX(sthpw/snapshot['context', '{0}'].version)".format(context),
            search_keys=[search_key])
        if ver:
            if is_revision:
                version = int(ver)
            else:
                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)

    if is_revision:
        snapshot_code = server.eval(
            "@GET(sthpw/snapshot['version', {0}].code)".format(version),
            search_keys=[search_key],
            single=True)
        revision = server.eval(
            "@MAX(sthpw/snapshot.revision)",
            search_keys=['sthpw/snapshot?code={0}'.format(snapshot_code)])

        snapshot.set_value('version', version)
        snapshot.set_value('revision', revision + 1)

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

    dir_naming = None
    file_naming = None

    checkin = FileAppendCheckin(snapshot.get_code(),
                                files_info['version_files'],
                                files_info['files_types'],
                                keep_file_name=keep_file_name,
                                mode=mode,
                                source_paths=files_info['version_files'],
                                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=files_info['file_sizes'][i])
        fl.set_value(name='relative_dir',
                     value=files_info['version_files_paths'][i])
        fl.set_value(name='metadata',
                     value=json.dumps(files_info['version_metadata'][i],
                                      separators=(',', ':')))
        fl.commit()

    # update_versionless = False

    if update_versionless:
        snapshot.update_versionless('latest',
                                    sobject=sobject,
                                    checkin_type='auto')
        # 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:
        #     snapshot.update_versionless('latest')
        # 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)]

        # 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/>')
        if repo_name:
            versionless_snapshot[0].set_value('repo', repo_name)
        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(), files_info['versionless_files'], files_info['files_types'], keep_file_name=keep_file_name, mode=mode,
        #                             source_paths=files_info['versionless_files'], dir_naming=dir_naming, file_naming=file_naming,
        #                             checkin_type='strict', do_update_versionless=False)
        # checkin_versionless.execute()
        #
        # versionless_files_list = checkin_versionless.get_file_objects()
        # for i, fl_versionless in enumerate(versionless_files_list):
        #     fl_versionless.set_value(name='st_size', value=files_info['file_sizes'][i])
        #     fl_versionless.set_value(name='relative_dir', value=files_info['versionless_files_paths'][i])
        #     fl_versionless.commit()

        search = Search('sthpw/file')
        search.add_op_filters([('snapshot_code',
                                versionless_snapshot[0].get_code())])
        file_objects = search.get_sobjects()

        for i, file_object in enumerate(file_objects):
            file_object.set_value(name='st_size',
                                  value=files_info['file_sizes'][i])
            file_object.set_value(name='project_code',
                                  value=snapshot.get_project_code())
            file_object.set_value(
                name='relative_dir',
                value=files_info['versionless_files_paths'][i])
            file_object.set_value(name='metadata',
                                  value=json.dumps(
                                      files_info['versionless_metadata'][i],
                                      separators=(',', ':')))
            file_object.set_value(name='source_path',
                                  value=files_info['versionless_files'][i])
            file_object.set_value(name='file_name',
                                  value=os.path.basename(
                                      files_info['versionless_files'][i]))
            file_object.commit()

    return str('OKEEDOKEE')
コード例 #4
0
def get_virtual_snapshot_extended(search_key,
                                  context,
                                  files_dict,
                                  snapshot_type="file",
                                  is_revision=False,
                                  level_key=None,
                                  keep_file_name=False,
                                  version=None,
                                  update_versionless=True,
                                  ignore_keep_file_name=False,
                                  checkin_type='file'):
    '''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.biz import File, FileGroup, FileRange
    from pyasm.search import SearchType
    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

    description = "No description"

    # this is only to avoid naming intersection
    if len(files_dict) > 1 and not ignore_keep_file_name:
        keep_file_name = True

    if checkin_type == 'multi_file':
        keep_file_name = False

    # if len(set(file_type)) != 1:
    #     keep_file_name = False

    if not version:
        ver = server.eval(
            "@MAX(sthpw/snapshot['context', '{0}'].version)".format(context),
            search_keys=[search_key])
        if ver:
            if is_revision:
                version = int(ver)
            else:
                version = int(ver) + 1
        else:
            version = 1

    file_naming = Project.get_file_naming()
    file_naming.set_sobject(sobject)

    snapshot_versioned = Snapshot.create(sobject,
                                         snapshot_type=snapshot_type,
                                         context=context,
                                         description=description,
                                         is_revision=is_revision,
                                         level_type=level_type,
                                         level_id=level_id,
                                         commit=False,
                                         version=version)

    if is_revision:
        snapshot_versioned.set_value('version', version)

    if update_versionless:
        snapshot_versionless = Snapshot.create(sobject,
                                               snapshot_type=snapshot_type,
                                               context=context,
                                               description=description,
                                               is_revision=False,
                                               level_type=level_type,
                                               level_id=level_id,
                                               commit=False,
                                               version=-1)

    file_object = SearchType.create("sthpw/file")

    def prepare_filename(filenaming, f_l, ext, postfix, metadata):

        if keep_file_name:
            file_type = filenaming.get_file_type()
            if file_type in ['web', 'icon']:
                postfix = file_type
            if postfix:
                result_file_name = f_l + '_' + postfix + '.' + ext
            else:
                if ext:
                    result_file_name = f_l + '.' + ext
                else:
                    result_file_name = f_l
        else:
            name_ext = filenaming.get_file_name()

            # filenaming.get_file_name()
            if postfix:
                result_file_name = name_ext.replace(
                    filenaming.get_ext(), '_{0}.{1}'.format(postfix, ext))
            else:
                result_file_name = name_ext

        first_part = result_file_name.replace(filenaming.get_ext(), '')
        # second_part = ''
        #
        # if metadata:
        #     if metadata.get('type') in ['udim', 'layer_udim', 'udim_sequence', 'layer_udim_sequence']:
        #         result_file_name = result_file_name.replace(filenaming.get_ext(), '_[UUVV].{0}'.format(ext))
        #
        #     if metadata.get('type') in ['uv', 'layer_uv', 'uv_sequence', 'layer_uv_sequence']:
        #         result_file_name = result_file_name.replace(filenaming.get_ext(), '_[u<>_v<>].{0}'.format(ext))
        #
        #     if metadata.get('type') in ['sequence', 'layer_sequence', 'layer_uv_sequence', 'layer_udim_sequence', 'uv_sequence', 'udim_sequence']:
        #         padding = int(metadata['padding'])
        #         result_file_name = result_file_name.replace(filenaming.get_ext(), '.[{0}].{1}'.format('#' * padding, ext))
        #
        #     second_part = result_file_name.replace(first_part, '').replace(filenaming.get_ext(), '')

        # from pyasm.biz import Naming
        # b = Naming.get(filenaming.sobject, filenaming.snapshot, file_path=filenaming.file_object.get_full_file_name())

        if metadata:
            return first_part, metadata.get('name_part'), filenaming.get_ext()
        else:
            return first_part, '', filenaming.get_ext()

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

    result_list = []
    # fl::file, t::type, e::extension, s::sub-folder, p::postfix, m::metadata
    for fl, val in files_dict:

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

        if not fl:
            fl = sobject.get_code()
        elif not fl:
            fl = sobject.get_name()
        elif not fl:
            fl = "unknown"
        for t, e, s, p in zip(val['t'], val['e'], val['s'], val['p']):
            file_object.set_value("file_name", fl)
            file_object.set_value("type", t)
            if val['m']:
                file_object.set_value(
                    "metadata", json.dumps(val['m'], separators=(',', ':')))

            file_naming.set_snapshot(snapshot_versioned)
            file_naming.set_ext(e)
            file_naming.set_file_object(file_object)
            result_dict['versioned']['paths'].append(
                prepare_folder(
                    snapshot_versioned.get_dir('relative', file_type=t), s))
            result_dict['versioned']['names'].append(
                prepare_filename(file_naming, fl, e, p, val['m']))

            if update_versionless:
                file_naming.set_snapshot(snapshot_versionless)
                file_naming.set_ext(e)
                file_naming.set_file_object(file_object)
                result_dict['versionless']['paths'].append(
                    prepare_folder(
                        snapshot_versionless.get_dir('relative', file_type=t),
                        s))
                result_dict['versionless']['names'].append(
                    prepare_filename(file_naming, fl, e, p, val['m']))

        result_list.append((fl, result_dict))

    return json.dumps(result_list, separators=(',', ':'))
コード例 #5
0
ファイル: checkin_test.py プロジェクト: zieglerm/TACTIC
    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))
コード例 #6
0
ファイル: checkin_test.py プロジェクト: mincau/TACTIC
    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)) 
コード例 #7
0
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)
        checkin_versionless.execute()

        versionless_files_list = checkin_versionless.get_file_objects()
        for i, fl_versionless in enumerate(versionless_files_list):
            fl_versionless.set_value(name='st_size', value=file_sizes[i])
            fl_versionless.set_value(name='relative_dir', value=versionless_relative_paths[i])
            fl_versionless.commit()

    return str('OKEEDOKEE')
コード例 #8
0
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()
        file_naming.set_sobject(sobject)
        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_versioned = Snapshot.create(sobject, snapshot_type=snapshot_type, context=context, description=description, is_revision=is_revision, level_type=level_type, level_id=level_id, commit=False, version=version)
        file_naming.set_snapshot(snapshot_versioned)
        file_naming.set_ext(ext[i])
        file_naming.set_file_object(file_object)
        result_dict['versioned']['paths'].append(prepare_folder(snapshot_versioned.get_dir('relative', file_type=file_type[i]), subfolders[i]))
        result_dict['versioned']['names'].append(prepare_filename(file_naming, fl, ext[i], postfixes[i]))

        snapshot_versionless = Snapshot.create(sobject, snapshot_type=snapshot_type, context=context, description=description, is_revision=False, level_type=level_type, level_id=level_id, commit=False, version=-1)
        file_naming.set_snapshot(snapshot_versionless)
        file_naming.set_file_object(file_object)
        file_naming.set_ext(ext[i])
        result_dict['versionless']['paths'].append(prepare_folder(snapshot_versionless.get_dir('relative', file_type=file_type[i]), subfolders[i]))
        result_dict['versionless']['names'].append(prepare_filename(file_naming, fl, ext[i], postfixes[i]))

    return json.dumps(result_dict, separators=(',', ':'))