예제 #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
파일: project.py 프로젝트: hellios78/TACTIC
                 file_type=None,
                 create=False,
                 file_object=None,
                 dir_naming=None):

        dir_naming_expr = dir_naming

        from snapshot import Snapshot, SObjectNotFoundException
        if isinstance(sobject, Snapshot):
            snapshot = sobject
            try:
                sobject = snapshot.get_sobject()
            except SObjectNotFoundException, e:
                pass

        dir_naming = Project.get_dir_naming(sobject)
        dir_naming.set_sobject(sobject)
        dir_naming.set_snapshot(snapshot)
        dir_naming.set_file_type(file_type)
        dir_naming.set_file_object(file_object)
        dir_naming.set_naming(dir_naming_expr)
        dir_naming.set_create(create)
        dir_naming.set_protocol(protocol)
        dirname = dir_naming.get_dir()
        return dirname

    _get_dir = staticmethod(_get_dir)

    def _get_base_dir(protocol, sobject, decrement=0):
        '''decrement is the number of levels it tries to go up the directory'''
        snapshot = None
예제 #4
0
    def handle_system_commands(my, snapshot, files, file_objects):
        '''check into perforce'''
        transaction = PerforceTransaction()

        current_file_paths = snapshot.get_all_lib_paths()

        prev_snapshot = snapshot.get_previous()
        if prev_snapshot:

            prev_file_paths = prev_snapshot.get_all_lib_paths()

            # check if new files already exist in the repo
            for current_file_path in current_file_paths:
                if current_file_path not in prev_file_paths and \
                        os.path.exists(current_file_path):
                    raise CommandException(
                        "File '%s' already exists in another asset" %
                        current_file_path)

            # delete all file not in new the snapshot
            for prev_file_path in prev_file_paths:
                if prev_file_path not in current_file_paths:
                    transaction.get_perforce().delete(prev_file_path)

        else:
            # check if new files already exist in the repo
            for current_file_path in current_file_paths:
                if os.path.exists(current_file_path):
                    raise CommandException(
                        "File '%s' already exists in another asset" %
                        current_file_path)

        # match perforce sub_dir with tactic sub_dir for the asset
        from pyasm.biz import Project
        project = Project.get()
        naming = Project.get_dir_naming()
        base_lib_dir = naming.get_base_dir("file")[0]
        lib_dir = snapshot.get_lib_dir()

        sub_dir = lib_dir.replace(base_lib_dir, "")
        for i in range(0, len(files)):
            transaction.checkin(files[i], sub_dir)

        # add a description
        version = snapshot.get_value("version")
        sobject = snapshot.get_sobject()
        transaction.set_description("Checked in asset '%s', version '%s'" % \
            (sobject.get_code(),version) )

        result = transaction.commit()

        print result

        # get the version of the first file
        files = result.get("files")
        if not files:
            raise PerforceException("No files checked in")

        version = files[0]['version']
        print "setting snapshot to version: %s" % version

        snapshot.set_value("version", version)
        snapshot.commit()
예제 #5
0


    def _get_dir(protocol,sobject,snapshot,file_type=None, create=False, file_object=None, dir_naming=None):

        dir_naming_expr = dir_naming

        from snapshot import Snapshot, SObjectNotFoundException
        if isinstance(sobject,Snapshot):
            snapshot = sobject
            try:
                sobject = snapshot.get_sobject()
            except SObjectNotFoundException, e:
                pass

        dir_naming = Project.get_dir_naming(sobject)
        dir_naming.set_sobject(sobject)
        dir_naming.set_snapshot(snapshot)
        dir_naming.set_file_type(file_type)
        dir_naming.set_file_object(file_object)
        dir_naming.set_naming(dir_naming_expr)
        dir_naming.set_create(create)
        dir_naming.set_protocol(protocol)
        dirname = dir_naming.get_dir()
        return dirname
    _get_dir = staticmethod(_get_dir)


    def _get_base_dir(protocol, sobject, decrement=0):
        '''decrement is the number of levels it tries to go up the directory'''
        snapshot = None
예제 #6
0
파일: perforce.py 프로젝트: mincau/TACTIC
    def handle_system_commands(self, snapshot, files, file_objects):
        '''check into perforce'''
        transaction = PerforceTransaction()


        current_file_paths = snapshot.get_all_lib_paths()

        prev_snapshot = snapshot.get_previous()
        if prev_snapshot:

            prev_file_paths = prev_snapshot.get_all_lib_paths()

            # check if new files already exist in the repo
            for current_file_path in current_file_paths:
                if current_file_path not in prev_file_paths and \
                        os.path.exists(current_file_path):
                    raise CommandException("File '%s' already exists in another asset" % current_file_path)

            # delete all file not in new the snapshot
            for prev_file_path in prev_file_paths:
                if prev_file_path not in current_file_paths:
                    transaction.get_perforce().delete(prev_file_path)


        else:
            # check if new files already exist in the repo
            for current_file_path in current_file_paths:
                if os.path.exists(current_file_path):
                    raise CommandException("File '%s' already exists in another asset" % current_file_path)



        # match perforce sub_dir with tactic sub_dir for the asset
        from pyasm.biz import Project
        project = Project.get()
        naming = Project.get_dir_naming()
        base_lib_dir = naming.get_base_dir("file")[0]
        lib_dir = snapshot.get_lib_dir()


        sub_dir = lib_dir.replace(base_lib_dir, "")
        for i in range( 0, len(files) ):
            transaction.checkin( files[i], sub_dir )


        # add a description
        version = snapshot.get_value("version")
        sobject = snapshot.get_sobject()
        transaction.set_description("Checked in asset '%s', version '%s'" % \
            (sobject.get_code(),version) )

        result = transaction.commit()

        print result

        # get the version of the first file
        files = result.get("files")
        if not files:
            raise PerforceException("No files checked in")

        version = files[0]['version']
        print "setting snapshot to version: %s" % version

        snapshot.set_value("version", version)
        snapshot.commit()