def fetch_dependencies(repo_path):
    cprint.bold('\n- Looking for dependencies..')

    dependencies_path = repo_path + '/' + DEPENDENCY_FILE

    # List containing only the target_path(s), i.e: 'vendor/google'
    syncable_repos = []
    if os.path.exists(dependencies_path):
        # Load up *.dependencies
        dependencies = None
        with open(dependencies_path, 'r') as dep_file:
            dependencies = json.loads(dep_file.read())
            dep_file.close()

        if len(dependencies) == 0:
            color_exit('%s exists but it is empty.' % DEPENDENCY_FILE)

        # List containing the repositories to be added inside LOCAL_MANIFEST
        fetch_list = []
        for dep in dependencies:
            org, name, remote = process_repo(dep['repository'])

            # If it's not a valid entry (regex fails)
            if not org:
                cprint.warn(
                    "Skipping %s as it's not valid.\nPlease check its syntax in %s."
                    % (dep['repository'], DEPENDENCY_FILE))
                continue

            # If the dependency is not inside the LOCAL_MANIFEST
            if not is_in_manifest(org + '/' + name, dep['branch']):
                fetch_list.append(dep)

            # If the repository doesn't exist, append it to the syncable repos
            if not os.path.exists(dep['target_path']):
                syncable_repos.append(dep['target_path'])

        # If new manifest entries have to be added
        if fetch_list:
            cprint.bold('\n- Adding dependencies to local manifest..')
            add_to_manifest(fetch_list)

        # Synchronise repos
        if syncable_repos:
            cprint.bold('\n- Syncing dependencies..')
            sync_repos(syncable_repos)

    else:
        color_exit('Dependencies file not found, bailing out.')
            except (IndexError, ValueError):
                args.quiet or cprint.warn(
                    'The patch set {0}/{1} could not be found, using CURRENT_REVISION instead.'
                    .format(change, patchset))

    for item in mergables:
        args.quiet or cprint.success('Applying change number {0}...'.format(
            item['id']))
        # Check if change is open and exit if it's not, unless -f is specified
        if (item['status'] != 'OPEN' and item['status'] != 'NEW'
                and item['status'] != 'DRAFT') and not args.query:
            if args.force:
                cprint.warn('!! Force-picking a closed change !!\n')
            else:
                cprint.bold(
                    'Change status is ' + item['status'] +
                    '. Skipping the cherry pick.\nUse -f to force this pick.')
                continue

        # Convert the project name to a project path
        #   - check that the project path exists
        project_path = None

        if item['project'] == "android_manifest" :
            project_path=".repo/manifests/"
        else:
            if item['project'] in project_name_to_data and item[
                    'branch'] in project_name_to_data[item['project']]:
                project_path = project_name_to_data[item['project']][
                    item['branch']]
            elif args.path:
示例#3
0
def sync_repos(repos):
    try:
        # If it's a list, we need to unpack it
        if type(repos) == list:
            p = Popen(['repo', 'sync', '--force-sync'] + repos)
        else:
            p = Popen(['repo', 'sync', '--force-sync', repos])

        out, err = p.communicate()
    except KeyboardInterrupt:
        cprint._exit(USER_ABORT_MSG)


if __name__ == "__main__":
    cprint.bold('\n~ Welcome to roomservice, setting up device\n')

    # Target to build
    product = sys.argv[1]

    # If the target is i.e du_taimen, we just need to get taimen
    try:
        device = product[product.index("_") + 1:]
    except ValueError:
        exit("The target you entered wouldn't work, use instead du_{0}\n".
             format(product))

    # Whether we need to just fetch dependencies or not
    if len(sys.argv) > 2:
        depsonly = sys.argv[2]
    else:
                    if removable_project.get('name') == upstream_name:
                        found_remove_element = True
                        break
                for removable_project in upstream_manifest.findall('remove-project'):
                    if removable_project.get('name') == upstream_name:
                        found_remove_element = True
                        break
                if not found_remove_element:
                    modified_project = True
                    roomservice_manifest.insert(0, ET.Element('remove-project', attrib = {
                        'name': upstream_name
                    }))

        # In case anything has changed, set the project as syncable.
        if modified_project:
            syncable_projects.append(path)

    # Output our manifest.
    indent(roomservice_manifest)
    open(roomservice_manifest_path, 'w').write('\n'.join([
        '<?xml version="1.0" encoding="UTF-8"?>',
        '<!-- You should probably let Roomservice deal with this unless you know what you are doing. -->',
        ET.tostring(roomservice_manifest).decode()
    ]))

    # Sync the project that have changed and should be synced.
    if len(syncable_projects) > 0:
        cprint.bold('\nSyncing the dependencies.')
        if os.system('repo sync --force-sync --quiet --no-clone-bundle --no-tags %s' % ' '.join(syncable_projects)) != 0:
            raise ValueError('Got an unexpected exit status from the sync process.')