Ejemplo n.º 1
0
def find_project_in_index(project, ci_index_file, global_manifest_dir, except_message):
    """
    Finds a project in the CiIndexFile and returns the path to it within the global manifest repository.
    Raises and EdkrepoInvalidParametersException if not found"""
    try:
        proj_name = case_insensitive_single_match(project, ci_index_file.project_list)
    except:
        proj_name = None
    if proj_name:
        ci_index_xml_rel_path = os.path.normpath(ci_index_file.get_project_xml(proj_name))
        global_manifest_path = os.path.join(global_manifest_dir, ci_index_xml_rel_path)
    elif os.path.isabs(project):
        global_manifest_path = project
    else:
        if os.path.isfile(os.path.join(os.getcwd(), project)):
            global_manifest_path = os.path.join(os.getcwd(), project)
        elif os.path.isfile(os.path.join(global_manifest_dir, project)):
            global_manifest_path = os.path.join(global_manifest_dir, project)
        elif not os.path.dirname(project):
            for dirpath, _, filenames in os.walk(global_manifest_dir):
                if project in filenames:
                    global_manifest_path = os.path.join(dirpath, project)
                    break
            else:
                raise EdkrepoInvalidParametersException(except_message)
        else:
            raise EdkrepoInvalidParametersException(except_message)

    return global_manifest_path
Ejemplo n.º 2
0
def get_start_and_end_commit(commit_ish, repo):
    #Determine the start and end commit for the upcoming squash
    (commit1, commit2) = split_commit_range(commit_ish)
    try:
        repo.rev_parse(commit1)
    except:
        raise EdkrepoInvalidParametersException(
            COMMIT_NOT_FOUND.format(commit1))
    try:
        repo.rev_parse(commit2)
    except:
        raise EdkrepoInvalidParametersException(
            COMMIT_NOT_FOUND.format(commit2))
    if len(repo.git.rev_list(commit_ish).split()) <= 0:
        raise EdkrepoInvalidParametersException(
            SQUASH_COMMON_ANCESTOR_REQUIRED.format(commit1, commit2))
    if str(repo.commit(commit1)) not in repo.git.rev_list(commit2).split():
        temp_commit = commit1
        commit1 = commit2
        commit2 = temp_commit
        if str(repo.commit(commit1)) not in repo.git.rev_list(commit2).split():
            raise EdkrepoInvalidParametersException(
                SQUASH_COMMON_ANCESTOR_REQUIRED.format(commit1, commit2))
    start_commit = get_oldest_ancestor(commit1, commit2, repo)
    end_commit = str(repo.commit(commit2))
    return (start_commit, end_commit)
    def run_command(self, args, config):
        cfg_repos, user_cfg_repos, conflicts = list_available_manifest_repos(
            config['cfg_file'], config['user_cfg_file'])

        if args.action == 'list':
            for repo in cfg_repos:
                ui_functions.print_info_msg(humble.CFG_LIST_ENTRY.format(repo),
                                            header=False)
            for repo in user_cfg_repos:
                ui_functions.print_info_msg(
                    humble.USER_CFG_LIST_ENTRY.format(repo), header=False)

        elif (args.action == ('add' or 'remove')) and not args.name:
            raise EdkrepoInvalidParametersException(humble.NAME_REQUIRED)
        elif args.action == 'add' and (not args.branch or not args.url
                                       or not args.path):
            raise EdkrepoInvalidParametersException(humble.ADD_REQUIRED)
        elif args.action == 'remove' and args.name and args.name in cfg_repos:
            raise EdkrepoInvalidParametersException(humble.CANNOT_REMOVE_CFG)
        elif args.action == 'remove' and args.name not in config[
                'user_cfg_file'].manifest_repo_list:
            raise EdkrepoInvalidParametersException(humble.REMOVE_NOT_EXIST)
        elif args.action == 'add' and (args.name in cfg_repos
                                       or args.name in user_cfg_repos):
            raise EdkrepoInvalidParametersException(
                humble.ALREADY_EXISTS.format(args.name))

        user_cfg_file_path = config['user_cfg_file'].cfg_filename

        if args.action == 'add' or 'remove':
            user_cfg_file = configparser.ConfigParser(allow_no_value=True)
            user_cfg_file.read(user_cfg_file_path)
            if args.action == 'add':
                if not user_cfg_file.has_section('manifest-repos'):
                    user_cfg_file.add_section('manifest-repos')
                user_cfg_file.set('manifest-repos', args.name, None)
                user_cfg_file.add_section(args.name)
                user_cfg_file.set(args.name, 'URL', args.url)
                user_cfg_file.set(args.name, 'Branch', args.branch)
                user_cfg_file.set(args.name, 'LocalPath', args.path)
            if args.action == 'remove':
                if user_cfg_file.has_section('manifest-repos'):
                    if user_cfg_file.has_option('manifest-repos', args.name):
                        user_cfg_file.remove_option('manifest-repos',
                                                    args.name)
                    else:
                        raise EdkrepoInvalidParametersException(
                            humble.REMOVE_NOT_EXIST)
                else:
                    raise EdkrepoInvalidParametersException(
                        humble.REMOVE_NOT_EXIST)
                if user_cfg_file.has_section(args.name):
                    user_cfg_file.remove_section(args.name)
                else:
                    raise EdkrepoInvalidParametersException(
                        humble.REMOVE_NOT_EXIST)
            with open(user_cfg_file_path, 'w') as cfg_stream:
                user_cfg_file.write(cfg_stream)
def pull_workspace_manifest_repo(project_manifest,
                                 edkrepo_cfg,
                                 edkrepo_user_cfg,
                                 man_repo=None,
                                 reset_hard=False):
    '''
    Pulls only the global manifest repo for the current workspace.
    '''
    src_man_repo = find_source_manifest_repo(project_manifest, edkrepo_cfg,
                                             edkrepo_user_cfg, man_repo)
    config_repos, user_config_repos, conflicts = list_available_manifest_repos(
        edkrepo_cfg, edkrepo_user_cfg)
    if src_man_repo in config_repos:
        pull_single_manifest_repo(
            edkrepo_cfg.get_manifest_repo_url(src_man_repo),
            edkrepo_cfg.get_manifest_repo_branch(src_man_repo),
            edkrepo_cfg.get_manifest_repo_local_path(src_man_repo), reset_hard)
    elif src_man_repo in user_config_repos:
        pull_single_manifest_repo(
            edkrepo_user_cfg.get_manifest_repo_url(src_man_repo),
            edkrepo_user_cfg.get_manifest_repo_branch(src_man_repo),
            edkrepo_user_cfg.get_manifest_repo_local_path(src_man_repo),
            reset_hard)
    elif src_man_repo in conflicts:
        raise EdkrepoInvalidParametersException(
            humble.CONFLICT_NO_CLONE.format(src_man_repo))
Ejemplo n.º 5
0
 def __get_pin_path(self, args, workspace_path, manifest_repo_path,
                    manifest):
     if os.path.isabs(args.pinfile) and os.path.isfile(args.pinfile):
         return os.path.normpath(args.pinfile)
     elif manifest_repo_path is not None and os.path.isfile(
             os.path.join(
                 manifest_repo_path,
                 os.path.normpath(manifest.general_config.pin_path),
                 args.pinfile)):
         return os.path.join(
             manifest_repo_path,
             os.path.normpath(manifest.general_config.pin_path),
             args.pinfile)
     elif manifest_repo_path is not None and os.path.isfile(
             os.path.join(manifest_repo_path, args.pinfile)):
         return os.path.join(manifest_repo_path, args.pinfile)
     elif os.path.isfile(os.path.join(workspace_path, args.pinfile)):
         return os.path.join(workspace_path, args.pinfile)
     elif os.path.isfile(os.path.join(workspace_path, 'repo',
                                      args.pinfile)):
         return os.path.join(workspace_path, 'repo', args.pinfile)
     elif not os.path.isfile(os.path.join(
             workspace_path,
             args.pinfile)) and os.path.dirname(args.pinfile) is None:
         for dirpath, dirnames, filenames in os.walk(workspace_path):
             if args.pinfile in filenames:
                 return os.path.join(dirpath, args.pinfile)
     else:
         raise EdkrepoInvalidParametersException(humble.NOT_FOUND)
Ejemplo n.º 6
0
    def run_command(self, args, config):

        workspace_path = get_workspace_path()
        manifest = get_workspace_manifest()

        # Set the pinname/path == to the file name provided.
        # If a relative paths is provided save the file relative to the current working directory.
        if os.path.isabs(os.path.normpath(args.PinFileName)):
            pin_file_name = os.path.normpath(args.PinFileName)
        else:
            pin_file_name = os.path.abspath(os.path.normpath(args.PinFileName))
        # If the directory that the pin file is saved in does not exist create it and ensure pin file name uniqueness.
        if os.path.isfile(pin_file_name):
            raise EdkrepoInvalidParametersException(PIN_FILE_ALREADY_EXISTS)
        if not os.path.exists(os.path.dirname(pin_file_name)):
            os.mkdir(os.path.dirname(pin_file_name))

        repo_sources = manifest.get_repo_sources(
            manifest.general_config.current_combo)

        # get the repo sources and commit ids for the pin
        ui_functions.print_info_msg(GENERATING_PIN_DATA.format(
            manifest.project_info.codename,
            manifest.general_config.current_combo),
                                    header=False)
        updated_repo_sources = []
        for repo_source in repo_sources:
            local_repo_path = os.path.join(workspace_path, repo_source.root)
            if not os.path.exists(local_repo_path):
                raise EdkrepoWorkspaceCorruptException(
                    MISSING_REPO.format(repo_source.root))
            repo = Repo(local_repo_path)
            commit_id = repo.head.commit.hexsha
            if args.verbose:
                ui_functions.print_info_msg(GENERATING_REPO_DATA.format(
                    repo_source.root),
                                            header=False)
                ui_functions.print_info_msg(BRANCH.format(repo_source.branch),
                                            header=False)
                ui_functions.print_info_msg(COMMIT.format(commit_id),
                                            header=False)
            updated_repo_source = repo_source._replace(commit=commit_id)
            updated_repo_sources.append(updated_repo_source)

        # create the pin
        ui_functions.print_info_msg(WRITING_PIN_FILE.format(pin_file_name),
                                    header=False)
        manifest.generate_pin_xml(args.Description,
                                  manifest.general_config.current_combo,
                                  updated_repo_sources,
                                  filename=pin_file_name)
Ejemplo n.º 7
0
def checkout(combination, verbose=False, override=False, log=None, cache_obj=None):
    workspace_path = get_workspace_path()
    manifest = get_workspace_manifest()

    # Create combo so we have original input and do not introduce any
    # unintended behavior by messing with parameters.
    combo = combination
    submodule_combo = manifest.general_config.current_combo
    try:
        # Try to handle normalize combo name to match the manifest file.
        combo = case_insensitive_single_match(combo, combinations_in_manifest(manifest))
        submodule_combo = combo
    except:
        raise EdkrepoInvalidParametersException(CHECKOUT_INVALID_COMBO)

    repo_sources = manifest.get_repo_sources(combo)
    initial_repo_sources = manifest.get_repo_sources(manifest.general_config.current_combo)

    # Disable sparse checkout
    current_repos = initial_repo_sources
    sparse_enabled = sparse_checkout_enabled(workspace_path, initial_repo_sources)
    sparse_diff = False
    for source in initial_repo_sources:
        for src in repo_sources:
            if source.root == src.root:
                if source.sparse != src.sparse:
                    sparse_diff = True
        if sparse_diff:
            break
    # Sparse checkout only needs to be recomputed if
    # the dynamic sparse list is being used instead of the static sparse list
    # or the sparse settings between two combinations differ
    if sparse_enabled:
        sparse_settings = manifest.sparse_settings
        if sparse_settings is not None:
            sparse_enabled = False
    if sparse_enabled or sparse_diff:
        print(SPARSE_RESET)
        reset_sparse_checkout(workspace_path, current_repos)

    # Deinit all submodules due to the potential for issues when switching
    # branches.
    if combo != manifest.general_config.current_combo:
        try:
            deinit_full(workspace_path, manifest, verbose)
        except Exception as e:
            print(SUBMODULE_DEINIT_FAILED)
            if verbose:
                print(e)

    print(CHECKING_OUT_COMBO.format(combo))

    try:
        checkout_repos(verbose, override, repo_sources, workspace_path, manifest)
        current_repos = repo_sources
        # Update the current checkout combo in the manifest only if this
        # combination exists in the manifest
        if combination_is_in_manifest(combo, manifest):
            manifest.write_current_combo(combo)
    except:
        if verbose:
            traceback.print_exc()
        print (CHECKOUT_COMBO_UNSUCCESSFULL.format(combo))
        # Return to the initial combo, since there was an issue with cheking out the selected combo
        checkout_repos(verbose, override, initial_repo_sources, workspace_path, manifest)
    finally:
        cache_path = None
        if cache_obj is not None:
            cache_path = cache_obj.get_cache_path(SUBMODULE_CACHE_REPO_NAME)
        maintain_submodules(workspace_path, manifest, submodule_combo, verbose, cache_path)
        if sparse_enabled or sparse_diff:
            print(SPARSE_CHECKOUT)
            sparse_checkout(workspace_path, current_repos, manifest)
    def run_command(self, args, config):
        print()
        init_color_console(args.color)

        pull_all_manifest_repos(config['cfg_file'], config['user_cfg_file'])
        print()

        cfg_manifest_repos, user_config_manifest_repos, conflicts = list_available_manifest_repos(config['cfg_file'], config['user_cfg_file'])

        found_manifests = {}
        manifests = {}
        repo_urls = set()
        config_manifest_repos_project_list = []
        user_config_manifest_repos_project_list = []

        for manifest_repo in cfg_manifest_repos:
            # Get path to global manifest file
            global_manifest_directory = config['cfg_file'].manifest_repo_abs_path(manifest_repo)
            if args.verbose:
                print(humble.MANIFEST_DIRECTORY)
                print(global_manifest_directory)
                print()
            #Create a dictionary containing all the manifests listed in the CiIndex.xml file
            index_path = os.path.join(global_manifest_directory, CI_INDEX_FILE_NAME)
            print(index_path)
            ci_index_xml = CiIndexXml(index_path)
            config_manifest_repos_project_list = ci_index_xml.project_list
            if args.archived:
                config_manifest_repos_project_list.extend(ci_index_xml.archived_project_list)
            for project in config_manifest_repos_project_list:
                xml_file = ci_index_xml.get_project_xml(project)
                manifest = ManifestXml(os.path.normpath(os.path.join(global_manifest_directory, xml_file)))
                found_manifests['{}:{}'.format(manifest_repo, project)] = manifest
                combo_list = [c.name for c in manifest.combinations]
                if args.archived:
                    combo_list.extend([c.name for c in manifest.archived_combinations])
                for combo in combo_list:
                    sources = manifest.get_repo_sources(combo)
                    for source in sources:
                        repo_urls.add(self.get_repo_url(source.remote_url))
        for manifest_repo in user_config_manifest_repos:
             # Get path to global manifest file
            global_manifest_directory = config['user_cfg_file'].manifest_repo_abs_path(manifest_repo)
            if args.verbose:
                print(humble.MANIFEST_DIRECTORY)
                print(global_manifest_directory)
                print()
            #Create a dictionary containing all the manifests listed in the CiIndex.xml file
            index_path = os.path.join(global_manifest_directory, CI_INDEX_FILE_NAME)
            ci_index_xml = CiIndexXml(index_path)
            user_config_manifest_repos_project_list = ci_index_xml.project_list
            if args.archived:
                user_config_manifest_repos_project_list.extend(ci_index_xml.archived_project_list)
            for project in user_config_manifest_repos_project_list:
                xml_file = ci_index_xml.get_project_xml(project)
                manifest = ManifestXml(os.path.normpath(os.path.join(global_manifest_directory, xml_file)))
                found_manifests['{}:{}'.format(manifest_repo, project)] = manifest
                combo_list = [c.name for c in manifest.combinations]
                if args.archived:
                    combo_list.extend([c.name for c in manifest.archived_combinations])
                for combo in combo_list:
                    sources = manifest.get_repo_sources(combo)
                    for source in sources:
                        repo_urls.add(self.get_repo_url(source.remote_url))

        #Remove the manifest repo portion of the key is there is not a duplicate project name
        key_list = list(found_manifests)
        for entry in key_list:
            new_key = entry.split(':')[1]
            value = found_manifests[entry]
            del found_manifests[entry]
            for found_manifest in list(found_manifests):
                if found_manifest.split(':')[1] == new_key:
                    new_key = 'Manifest Repository: {} Project: {}'.format(entry.split(':')[0], entry.split(':')[1])
                    break
            if new_key in manifests.keys():
                new_key = 'Manifest Repository: {} Project: {}'.format(entry.split(':'[0]), entry.split(':')[1])
            manifests[new_key] = value

        #Sort the manifests so projects will be displayed alphabetically
        manifests = collections.OrderedDict(sorted(manifests.items()))
        project_justify = len(max(manifests.keys(), key=len))

        #Determine the names of the repositories
        self.generate_repo_names(repo_urls, manifests, args.archived)
        print(humble.REPOSITORIES)

        #If the user provided a list of repositories to view, check to make sure
        #at least one repository will be shown, if not provide an error
        if args.repos and len([x for x in self.repo_names if x in args.repos]) <= 0:
            raise EdkrepoInvalidParametersException(humble.REPO_NOT_FOUND_IN_MANIFEST.format(','.join(args.repos)))

        #For each each git repository...
        for repo_name in self.repo_names:
            if args.repos and repo_name not in args.repos:
                continue
            repo = self.repo_names[repo_name][0]
            print(humble.REPO_NAME_AND_URL.format(repo_name, repo))
            print(humble.BRANCHES)

            #Determine the list of branches that used by any branch combination in any manifest
            branches = set()
            for project_name in manifests:
                combo_list = [c.name for c in manifests[project_name].combinations]
                if args.archived:
                    combo_list.extend([c.name for c in manifests[project_name].archived_combinations])
                for combo in combo_list:
                    sources = manifests[project_name].get_repo_sources(combo)
                    for source in sources:
                        if self.get_repo_url(source.remote_url) == repo:
                            branches.add(source.branch)

            #Sort the branch names so they will be displayed alphabetically
            #with the exception that if a branch named "master" exists, then it
            #will be displayed first
            branches = sorted(branches, key=str.casefold)
            if 'master' in branches:
                branches.remove('master')
                branches.insert(0, 'master')

            #For each interesting branch in the current git repository...
            for branch in branches:
                print(humble.BRANCH_FORMAT_STRING.format(branch))

                #Determine the branch combinations that use that branch
                for project_name in manifests:
                    combos = []
                    combo_list = [c.name for c in manifests[project_name].combinations]
                    if args.archived:
                        combo_list.extend([c.name for c in manifests[project_name].archived_combinations])
                    for combo in combo_list:
                        sources = manifests[project_name].get_repo_sources(combo)
                        for source in sources:
                            if self.get_repo_url(source.remote_url) == repo and source.branch == branch:
                                combos.append(combo)
                                break
                    if len(combos) > 0:
                        #Sort the branch combinations so they will be displayed alphabetically
                        #with the exception that the default branch combination for the manifest
                        #file will be displayed first
                        combos = sorted(combos, key=str.casefold)
                        default_combo = manifests[project_name].general_config.default_combo
                        if default_combo in combos:
                            combos.remove(default_combo)
                            combos.insert(0, default_combo)
                        first_combo = True
                        for combo in combos:
                            #Print the project name
                            if first_combo:
                                project_name_print = humble.PROJECT_NAME_FORMAT_STRING.format(project_name.ljust(project_justify))
                                first_combo = False
                            else:
                                project_name_print = '{} '.format((' ' * len(project_name)).ljust(project_justify))
                            #Print the branch combination name, if this is the default branch combination,
                            #then print it in green color with *'s around it
                            if default_combo == combo:
                                print(humble.DEFAULT_COMBO_FORMAT_STRING.format(project_name_print, combo))
                            else:
                                print(humble.COMBO_FORMAT_STRING.format(project_name_print, combo))
 def get_repo_name(self, repo_url, manifests):
     for name in self.repo_names:
         if self.repo_names[name][0] == repo_url:
             return name
     raise EdkrepoInvalidParametersException(humble.REPO_NAME_NOT_FOUND)
Ejemplo n.º 10
0
 def run_command(self, args, config):
     less_path, use_less = find_less()
     if use_less:
         output_string = ''
         separator = '\n'
     cfg, user_cfg, conflicts = list_available_manifest_repos(
         config['cfg_file'], config['user_cfg_file'])
     try:
         manifest = get_workspace_manifest()
         pull_workspace_manifest_repo(manifest, config['cfg_file'],
                                      config['user_cfg_file'],
                                      args.source_manifest_repo, False)
         src_manifest_repo = find_source_manifest_repo(
             manifest, config['cfg_file'], config['user_cfg_file'],
             args.source_manifest_repo)
         if src_manifest_repo in cfg:
             manifest_directory = config['cfg_file'].manifest_repo_abs_path(
                 src_manifest_repo)
         elif src_manifest_repo in user_cfg:
             manifest_directory = config[
                 'user_cfg_file'].manifest_repo_abs_path(src_manifest_repo)
         else:
             raise EdkrepoManifestNotFoundException(
                 SOURCE_MANIFEST_REPO_NOT_FOUND.format(
                     manifest.project_info.codename))
     except EdkrepoWorkspaceInvalidException:
         if not args.project:
             raise EdkrepoInvalidParametersException(humble.NOT_IN_WKSPCE)
         else:
             #arg parse provides a list so only use the first item since we are limiting users to one project
             manifest_repo, src_cfg, manifest_path = find_project_in_all_indices(
                 args.project[0], config['cfg_file'],
                 config['user_cfg_file'],
                 PROJ_NOT_IN_REPO.format(args.project[0]),
                 SOURCE_MANIFEST_REPO_NOT_FOUND.format(args.project[0]))
             if manifest_repo in cfg:
                 manifest_directory = config[
                     'cfg_file'].manifest_repo_abs_path(manifest_repo)
             elif manifest_repo in user_cfg:
                 manifest_directory = config[
                     'user_cfg_file'].manifest_repo_abs_path(manifest_repo)
             manifest = ManifestXml(manifest_path)
     if manifest.general_config.pin_path is None:
         print(humble.NO_PIN_FOLDER)
         return
     pin_folder = os.path.normpath(
         os.path.join(manifest_directory, manifest.general_config.pin_path))
     if args.verbose:
         if not use_less:
             print(humble.PIN_FOLDER.format(pin_folder))
         else:
             output_string = (humble.PIN_FOLDER.format(pin_folder))
     for dirpath, _, filenames in os.walk(pin_folder):
         for file in filenames:
             pin_file = os.path.join(dirpath, file)
             # Capture error output from manifest parser stdout to properly interleave with other pin data
             stdout = sys.stdout
             sys.stdout = io.StringIO()
             try:
                 pin = ManifestXml(pin_file)
             except TypeError:
                 continue
             parse_output = sys.stdout.getvalue()
             sys.stdout = stdout
             if pin.project_info.codename == manifest.project_info.codename:
                 if not use_less:
                     print('Pin File: {}'.format(file))
                     if args.verbose and not args.description:
                         print('Parsing Errors: {}\n'.format(
                             parse_output.strip()))
                     elif args.verbose and args.description:
                         print('Parsing Errors: {}'.format(
                             parse_output.strip()))
                     if args.description:
                         print('Description: {}\n'.format(
                             pin.project_info.description))
                 elif use_less:
                     output_string = separator.join(
                         (output_string, 'Pin File: {}'.format(file)))
                     if args.verbose and not args.description:
                         output_string = separator.join(
                             (output_string, 'Parsing Errors: {}\n'.format(
                                 parse_output.strip())))
                     elif args.verbose and args.description:
                         output_string = separator.join(
                             (output_string, 'Parsing Errors: {}'.format(
                                 parse_output.strip())))
                     if args.description:
                         output_string = separator.join(
                             (output_string, 'Description: {}\n'.format(
                                 pin.project_info.description)))
     if less_path:
         less_output = subprocess.Popen(
             [str(less_path), '-F', '-R', '-S', '-X', '-K'],
             stdin=subprocess.PIPE,
             stdout=sys.stdout,
             universal_newlines=True)
         less_output.communicate(input=output_string)
def find_project_in_all_indices(project,
                                edkrepo_cfg,
                                edkrepo_user_cfg,
                                except_msg_man_repo,
                                except_msg_not_found,
                                man_repo=None):
    '''
    Finds the project in all manifest repositories listed in the edkrepo.efg and
    edkrepo_user.cfg. If a project with the same name is found uses man_repo to select
    the correct entry
    '''

    cfg_man_repos, user_cfg_man_repos, conflicts = list_available_manifest_repos(
        edkrepo_cfg, edkrepo_user_cfg)
    projects = {}
    for repo in cfg_man_repos:
        manifest_dir = edkrepo_cfg.manifest_repo_abs_path(repo)
        # If the manifest directory does not exist clone it.
        if not os.path.exists(manifest_dir):
            pull_single_manifest_repo(
                edkrepo_cfg.get_manifest_repo_url(repo),
                edkrepo_cfg.get_manifest_repo_branch(repo),
                edkrepo_cfg.get_manifest_repo_local_path(repo),
                reset_hard=False)

        index_file = CiIndexXml(os.path.join(manifest_dir, CI_INDEX_FILE_NAME))
        found, man_path = find_project_in_single_index(project, index_file,
                                                       manifest_dir)
        if found:
            projects[repo] = ('edkrepo_cfg', man_path)
    for repo in user_cfg_man_repos:
        manifest_dir = edkrepo_user_cfg.manifest_repo_abs_path(repo)
        if not os.path.exists(manifest_dir):
            pull_single_manifest_repo(
                edkrepo_user_cfg.get_manifest_repo_url(repo),
                edkrepo_user_cfg.get_manifest_repo_branch(repo),
                edkrepo_user_cfg.get_manifest_repo_local_path(repo),
                reset_hard=False)
        index_file = CiIndexXml(os.path.join(manifest_dir, CI_INDEX_FILE_NAME))
        found, man_path = find_project_in_single_index(project, index_file,
                                                       manifest_dir)
        if found:
            projects[repo] = ('edkrepo_user_cfg', man_path)
    if len(projects.keys()) == 1:
        repo = list(projects.keys())[0]
        return repo, projects[repo][0], projects[repo][1]
    elif len(projects.keys()) > 1 and man_repo:
        try:
            return man_repo, projects[man_repo][0], projects[man_repo][1]
        except KeyError:
            raise EdkrepoInvalidParametersException(except_msg_man_repo)
    elif os.path.isabs(project):
        manifest = ManifestXml(project)
        try:
            found_manifest_repo, found_cfg, found_project = find_project_in_all_indices(
                manifest.project_info.codename, edkrepo_cfg, edkrepo_user_cfg,
                except_msg_man_repo, except_msg_not_found, man_repo)
            return found_manifest_repo, found_cfg, project
        except EdkrepoManifestNotFoundException:
            return None, None, project
    elif os.path.isfile(os.path.join(os.getcwd(), project)):
        manifest = ManifestXml(os.path.join(os.getcwd(), project))
        try:
            found_manifest_repo, found_cfg, found_project = find_project_in_all_indices(
                manifest.project_info.codename, edkrepo_cfg, edkrepo_user_cfg,
                except_msg_man_repo, except_msg_not_found, man_repo)
            return found_manifest_repo, found_cfg, project
        except EdkrepoManifestNotFoundException:
            return None, None, os.path.join(os.getcwd(), project)
    elif not os.path.dirname(project):
        for repo in cfg_man_repos:
            if (man_repo and (repo == man_repo)) or not man_repo:
                for dirpath, dirname, filenames in os.walk(
                        edkrepo_cfg.manifest_repo_abs_path(repo)):
                    if project in filenames:
                        return repo, 'edkrepo_cfg', os.path.join(
                            dirpath, project)
        for repo in user_cfg_man_repos:
            if (man_repo and (repo == man_repo)) or not man_repo:
                for dirpath, dirname, filenames in os.walk(
                        edkrepo_user_cfg.manifest_repo_abs_path(repo)):
                    if project in filenames:
                        return repo, 'edkrepo_user_cfg', os.path.join(
                            dirpath, project)
        raise EdkrepoManifestNotFoundException(
            humble.PROJ_NOT_IN_REPO.format(project))
    else:
        raise EdkrepoManifestNotFoundException(
            humble.PROJ_NOT_IN_REPO.format(project))
Ejemplo n.º 12
0
    def run_command(self, args, config):
        pull_all_manifest_repos(config['cfg_file'], config['user_cfg_file'],
                                False)

        name_or_manifest = args.ProjectNameOrManifestFile
        workspace_dir = args.Workspace
        # Check to see if requested workspace exists. If not create it. If so check for empty
        if workspace_dir == '.':
            # User has selected the directory they are running edkrepo from
            workspace_dir = os.getcwd()
        else:
            workspace_dir = os.path.abspath(workspace_dir)
        if sys.platform == "win32":
            subst = get_subst_drive_dict()
            drive = os.path.splitdrive(workspace_dir)[0][0].upper()
            if drive in subst:
                workspace_dir = os.path.join(
                    subst[drive],
                    os.path.splitdrive(workspace_dir)[1][1:])
                workspace_dir = os.path.normpath(workspace_dir)
        if os.path.isdir(workspace_dir) and os.listdir(workspace_dir):
            raise EdkrepoInvalidParametersException(CLONE_INVALID_WORKSPACE)
        if not os.path.isdir(workspace_dir):
            os.makedirs(workspace_dir)

        cfg, user_cfg, conflicts = list_available_manifest_repos(
            config['cfg_file'], config['user_cfg_file'])
        try:
            manifest_repo, source_cfg, global_manifest_path = find_project_in_all_indices(
                args.ProjectNameOrManifestFile, config['cfg_file'],
                config['user_cfg_file'],
                PROJ_NOT_IN_REPO.format(args.ProjectNameOrManifestFile),
                SOURCE_MANIFEST_REPO_NOT_FOUND.format(
                    args.ProjectNameOrManifestFile), args.source_manifest_repo)
        except EdkrepoManifestNotFoundException:
            raise EdkrepoInvalidParametersException(CLONE_INVALID_PROJECT_ARG)

        # If this manifest is in a defined manifest repository validate the manifest within the manifest repo
        if manifest_repo in cfg:
            verify_single_manifest(config['cfg_file'], manifest_repo,
                                   global_manifest_path)
            update_editor_config(
                config,
                config['cfg_file'].manifest_repo_abs_path(manifest_repo))
        elif manifest_repo in user_cfg:
            verify_single_manifest(config['user_cfg_file'], manifest_repo,
                                   global_manifest_path)
            update_editor_config(
                config,
                config['user_cfg_file'].manifest_repo_abs_path(manifest_repo))

        # Copy project manifest to local manifest dir and rename it Manifest.xml.
        local_manifest_dir = os.path.join(workspace_dir, "repo")
        os.makedirs(local_manifest_dir)
        local_manifest_path = os.path.join(local_manifest_dir, "Manifest.xml")
        shutil.copy(global_manifest_path, local_manifest_path)
        manifest = ManifestXml(local_manifest_path)

        # Update the source manifest repository tag in the local copy of the manifest XML
        try:
            if 'source_manifest_repo' in vars(args).keys():
                find_source_manifest_repo(manifest, config['cfg_file'],
                                          config['user_cfg_file'],
                                          args.source_manifest_repo)
            else:
                find_source_manifest_repo(manifest, config['cfg_file'],
                                          config['user_cfg_file'], None)
        except EdkrepoManifestNotFoundException:
            pass

        # Process the combination name and make sure it can be found in the manifest
        if args.Combination is not None:
            try:
                combo_name = case_insensitive_single_match(
                    args.Combination, combinations_in_manifest(manifest))
            except:
                #remove the repo directory and Manifest.xml from the workspace so the next time the user trys to clone
                #they will have an empty workspace and then raise an exception
                shutil.rmtree(local_manifest_dir)
                raise EdkrepoInvalidParametersException(
                    CLONE_INVALID_COMBO_ARG)
            manifest.write_current_combo(combo_name)
        elif manifest.is_pin_file():
            # Since pin files are subset of manifest files they do not have a "default combo" it is set to None. In this
            # case use the current_combo instead.
            combo_name = manifest.general_config.current_combo
        else:
            # If a combo was not specified or a pin file used the default combo should be cloned.  Also ensure that the
            # current combo is updated to match.
            combo_name = manifest.general_config.default_combo
            manifest.write_current_combo(combo_name)

        # Get the list of repos to clone and clone them
        repo_sources_to_clone = manifest.get_repo_sources(combo_name)

        #check that the repo sources do not contain duplicated local roots
        local_roots = [r.root for r in repo_sources_to_clone]
        for root in local_roots:
            if local_roots.count(root) > 1:
                #remove the repo dir and manifest.xml so the next time the user trys to clone they will have an empty
                #workspace
                shutil.rmtree(local_manifest_dir)
                raise EdkrepoManifestInvalidException(
                    CLONE_INVALID_LOCAL_ROOTS)
        project_client_side_hooks = manifest.repo_hooks
        # Set up submodule alt url config settings prior to cloning any repos
        submodule_included_configs = write_included_config(
            manifest.remotes, manifest.submodule_alternate_remotes,
            local_manifest_dir)
        write_conditional_include(workspace_dir, repo_sources_to_clone,
                                  submodule_included_configs)

        # Determine if caching is going to be used and then clone
        cache_obj = get_repo_cache_obj(config)
        if cache_obj is not None:
            add_missing_cache_repos(cache_obj, manifest, args.verbose)
        clone_repos(args, workspace_dir, repo_sources_to_clone,
                    project_client_side_hooks, config, manifest, cache_obj)

        # Init submodules
        if not args.skip_submodule:
            cache_path = None
            if cache_obj is not None:
                cache_path = cache_obj.get_cache_path(
                    SUBMODULE_CACHE_REPO_NAME)
            maintain_submodules(workspace_dir, manifest, combo_name,
                                args.verbose, cache_path)

        # Perform a sparse checkout if requested.
        use_sparse = args.sparse
        sparse_settings = manifest.sparse_settings
        if sparse_settings is None:
            # No SparseCheckout information in manifest so skip sparse checkout
            use_sparse = False
        elif sparse_settings.sparse_by_default:
            # Sparse settings enabled by default for the project
            use_sparse = True
        if args.nosparse:
            # Command line disables sparse checkout
            use_sparse = False
        if use_sparse:
            ui_functions.print_info_msg(SPARSE_CHECKOUT)
            sparse_checkout(workspace_dir, repo_sources_to_clone, manifest)