Ejemplo n.º 1
0
    def generate_icon(my, search_key):

        sobject = Search.get_by_search_key(search_key)
        search_code = sobject.get_code()
        search_type = sobject.get_search_type()
        base_search_type = sobject.get_base_search_type()


        if base_search_type == 'sthpw/snapshot':
            snapshot_code = sobject.get_code()

            file_type = "main"
            path = sobject.get_lib_path_by_type(file_type)

            icon_creator = IconCreator(path)
            icon_creator.execute()

            web_path = icon_creator.get_web_path()
            icon_path = icon_creator.get_icon_path()
            if web_path:
                sub_file_paths = [web_path, icon_path]
                sub_file_types = ['web', 'icon']

            from pyasm.checkin import FileAppendCheckin
            checkin = FileAppendCheckin(snapshot_code, sub_file_paths, sub_file_types, mode="inplace")
            checkin.execute()
            snapshot = checkin.get_snapshot()


        else:

            snapshot = Snapshot.get_snapshot(search_type, search_code, process=['publish',''])

            if not snapshot:
                return

            file_type = "main"
            path = snapshot.get_lib_path_by_type(file_type)


            # use api
            from tactic_client_lib import TacticServerStub
            server = TacticServerStub.get()
            snapshot = server.simple_checkin(search_key, "icon", path, mode="copy")


            # need the actual sobject to get the path to replace the icon
            # in the ui
            snapshot = Search.get_by_search_key(snapshot.get("__search_key__"))


        my.path = snapshot.get_web_path_by_type("icon")
Ejemplo n.º 2
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')
Ejemplo n.º 3
0
    def generate_icon(my, search_key):

        sobject = Search.get_by_search_key(search_key)
        search_code = sobject.get_code()
        search_type = sobject.get_search_type()
        base_search_type = sobject.get_base_search_type()


        if base_search_type == 'sthpw/snapshot':
            snapshot_code = sobject.get_code()

            file_type = "main"
            path = sobject.get_lib_path_by_type(file_type)

            #To check if it is a sequence checkin
            all_snapshots=sobject.get_all_file_objects()
            for single_snapshot in all_snapshots:
                if single_snapshot.get('base_type') == 'sequence':
                    return

            icon_creator = IconCreator(path)
            icon_creator.execute()

            web_path = icon_creator.get_web_path()
            icon_path = icon_creator.get_icon_path()
            if web_path:
                sub_file_paths = [web_path, icon_path]
                sub_file_types = ['web', 'icon']

                from pyasm.checkin import FileAppendCheckin
                checkin = FileAppendCheckin(snapshot_code, sub_file_paths, sub_file_types, mode="inplace")
                checkin.execute()
                snapshot = checkin.get_snapshot()
            else:
                snapshot = sobject


        else:

            snapshot = Snapshot.get_snapshot(search_type, search_code, process=['publish',''])

            if not snapshot:
                return

            #To check if it is a sequence checkin
            all_snapshots=snapshot.get_all_file_objects()
            for single_snapshot in all_snapshots:
                if single_snapshot.get('base_type') == 'sequence':
                    return

            file_type = "main"
            path = snapshot.get_lib_path_by_type(file_type)
            ext = File.get_extension(path)
            ext = ext.lower()
            if ext in File.NORMAL_EXT:

                return

            # use api
            """
            from tactic_client_lib import TacticServerStub
            server = TacticServerStub.get()
            snapshot = server.simple_checkin(search_key, "icon", path, mode="copy")
            """

            icon_creator = IconCreator(path)
            icon_creator.execute()

            web_path = icon_creator.get_web_path()
            icon_path = icon_creator.get_icon_path()
            if web_path and icon_path:
                sub_file_paths = [path, web_path, icon_path]
                sub_file_types = [path, 'web', 'icon']

                from pyasm.checkin import FileCheckin
                checkin = FileCheckin(sobject, sub_file_paths, sub_file_types, context='icon', mode="copy")
                checkin.execute()
                snapshot = checkin.get_snapshot()

            # need the actual sobject to get the path to replace the icon
            # in the ui
            #snapshot = Search.get_by_search_key(snapshot.get("__search_key__"))


        my.path = snapshot.get_web_path_by_type("icon")
Ejemplo n.º 4
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')
Ejemplo n.º 5
0
    def generate_icon(my, search_key):

        sobject = Search.get_by_search_key(search_key)
        search_code = sobject.get_code()
        search_type = sobject.get_search_type()
        base_search_type = sobject.get_base_search_type()


        if base_search_type == 'sthpw/snapshot':
            snapshot_code = sobject.get_code()

            file_type = "main"
            path = sobject.get_lib_path_by_type(file_type)

            #To check if it is a sequence checkin
            all_snapshots=sobject.get_all_file_objects()
            for single_snapshot in all_snapshots:
                if single_snapshot.get('base_type') == 'sequence':
                    return

            icon_creator = IconCreator(path)
            icon_creator.execute()

            web_path = icon_creator.get_web_path()
            icon_path = icon_creator.get_icon_path()
            if web_path:
                sub_file_paths = [web_path, icon_path]
                sub_file_types = ['web', 'icon']

                from pyasm.checkin import FileAppendCheckin
                checkin = FileAppendCheckin(snapshot_code, sub_file_paths, sub_file_types, mode="inplace")
                checkin.execute()
                snapshot = checkin.get_snapshot()
            else:
                snapshot = sobject


        else:

            snapshot = Snapshot.get_snapshot(search_type, search_code, process=['publish',''])

            if not snapshot:
                return

            #To check if it is a sequence checkin
            all_snapshots=snapshot.get_all_file_objects()
            for single_snapshot in all_snapshots:
                if single_snapshot.get('base_type') == 'sequence':
                    return

            file_type = "main"
            path = snapshot.get_lib_path_by_type(file_type)
            ext = File.get_extension(path)
            ext = ext.lower()
            if ext in File.NORMAL_EXT:

                return

            # use api
            """
            from tactic_client_lib import TacticServerStub
            server = TacticServerStub.get()
            snapshot = server.simple_checkin(search_key, "icon", path, mode="copy")
            """

            icon_creator = IconCreator(path)
            icon_creator.execute()

            web_path = icon_creator.get_web_path()
            icon_path = icon_creator.get_icon_path()
            if web_path and icon_path:
                sub_file_paths = [path, web_path, icon_path]
                sub_file_types = ['main', 'web', 'icon']

                from pyasm.checkin import FileCheckin
                checkin = FileCheckin(sobject, sub_file_paths, sub_file_types, context='icon', mode="copy")
                checkin.execute()
                snapshot = checkin.get_snapshot()

            # need the actual sobject to get the path to replace the icon
            # in the ui
            #snapshot = Search.get_by_search_key(snapshot.get("__search_key__"))


        my.path = snapshot.get_web_path_by_type("icon")