Esempio n. 1
0
    def execute(self, options, *args, **kws):  # pylint: disable=R0915
        SubCommandWithThread.execute(self, options, *args, **kws)

        RaiseExceptionIfOptionMissed(len(args),
                                     "No directories specified to import")

        RaiseExceptionIfOptionMissed(
            options.config_file, "No config file specified for the import")

        if not options.offsite:
            self.init_and_sync(options, update=False)

        options.filter_out_sccs = True

        if not options.keep_order:
            args = sorted(args, key=key_compare(FileVersion.cmp))

        cfg = RepoImportXmlConfigFile(
            SubCommandWithThread.get_absolute_running_file_name(
                options, options.config_file))

        self.run_with_thread(  # pylint: disable=E1101
            options.job,
            RepoSubcmd.fetch_projects_in_manifest(options),
            RepoImportSubcmd.push,
            options,
            cfg,
            Logger.get_logger(),  # pylint: disable=E1101
            args)

        return 0
Esempio n. 2
0
    def options(self, optparse):
        SubCommandWithThread.options(self, optparse)

        options = optparse.add_option_group('File options')
        options.add_option('-f',
                           '--file',
                           '--batch-file',
                           dest='batch_file',
                           action='append',
                           metavar='FILE',
                           help='Set the batch config file')
        options.add_option('-u',
                           '--group',
                           dest='group',
                           metavar='GROUP1,GROUP2,...',
                           help='Set the handling groups')
        options.add_option('--list',
                           dest='list',
                           action='store_true',
                           help='List the selected projects')

        options = optparse.add_option_group('Error handling options')
        options.add_option(
            '--ierror',
            '--ignore-errors',
            dest='ignore_errors',
            action='store_true',
            help='Ignore the running error and continue for next command')
Esempio n. 3
0
    def execute(self, options, *args, **kws):
        SubCommandWithThread.execute(self, options, *args, **kws)

        if options.convert_manifest_file:
            return RepoSubcmd.do_convert_manifest(options)

        RaiseExceptionIfOptionMissed(options.remote,
                                     'remote (--remote) is not set')

        if options.prefix and not options.prefix.endswith('/'):
            options.prefix += '/'

        repo = self.init_and_sync(options, options.offsite)

        ulp = urlparse(options.remote)
        if not ulp.scheme:
            remote = options.remote
            options.remote = 'git://%s' % options.remote
        else:
            remote = ulp.netloc.strip('/')

        gerrit = Gerrit(remote, options)
        projects = self.fetch_projects_in_manifest(options)

        if options.print_new_projects or options.dump_projects or \
                not options.repo_create:

            new_projects = list()
            for p in projects:
                if not gerrit.has_project(p.source) and \
                        not gerrit.has_project(p.uri):
                    new_projects.append(p)

            if options.dump_projects or options.print_new_projects or \
                    not options.repo_create and len(new_projects) > 0:
                if RepoSubcmd.dump_projects(options, projects, new_projects,
                                            options.ignore_new_project):
                    return

            # remove the new projects if option is set
            if options.ignore_new_project:
                for project in new_projects:
                    projects.remove(project)

        if options.output_xml_file or options.map_file:
            if options.output_xml_file:
                RepoSubcmd.build_xml_file(options, projects, True)
            else:
                RepoSubcmd.build_map_file(options, projects)

            return

        return self.run_with_thread(  # pylint: disable=E1101
            options.job, projects, RepoSubcmd.push, gerrit, options, remote)
Esempio n. 4
0
    def options(self, optparse, inherited=False):
        SubCommandWithThread.options(self, optparse, option_remote=True,
                                     option_import=True, modules=globals())

        options = optparse.add_option_group('Repo tool options')
        options.add_option(
            '-u', '--manifest-url',
            dest='manifest', metavar='URL',
            help='Set the git-repo manifest url')
        options.add_option(
            '-b', '--branch', '--manifest-branch',
            dest='manifest_branch', metavar='REVISION',
            help='Set the project branch or revision')
        options.add_option(
            '-m', '--manifest-name',
            dest='manifest_name', metavar='NAME.xml',
            help='initialize the manifest name')
        options.add_option(
            '--mirror',
            dest='mirror', action='store_true', default=False,
            help='Create a replica of the remote repositories')

        if not inherited:
            options = optparse.get_option_group('--refs') or \
                optparse.add_option_group('Remote options')
            options.add_option(
                '--prefix',
                dest='prefix', action='store', metavar='PREFIX',
                help='prefix on the remote location')
            options.add_option(
                '--sha1-tag',
                dest='sha1_tag', action='store', metavar='TAG',
                help='Push named tag for the SHA-1 to the remote. It works '
                     'without the option "--all"')

            options = optparse.add_option_group('Debug options')
            options.add_option(
                '--dump-projects',
                dest='dump_projects', action='store_true',
                help='Print the info of imported project')
            options.add_option(
                '--print-new-projects',
                dest='print_new_projects', action='store_true',
                help='Print the new projects which isn\'t managed by Gerrit')

            options = optparse.get_option_group('--hook-dir') or \
                optparse.add_option_group('File options')
            options.add_option(
                '--output-xml-file',
                dest='output_xml_file', action='store', metavar='FILE',
                help='Set the output XML filename')
Esempio n. 5
0
    def execute(self, options, *args, **kws):
        SubCommandWithThread.execute(self, options, *args, **kws)

        RaiseExceptionIfOptionMissed(
            options.remote, 'remote (--remote) is not set')

        if options.prefix and not options.endswith('/'):
            options.prefix += '/'

        if not options.offsite:
            self.init_and_sync(options)

        # handle the schema of the remote
        ulp = urlparse.urlparse(options.remote)
        if not ulp.scheme:
            remote = options.remote
            options.remote = 'git://%s' % options.remote
        else:
            remote = ulp.netloc.strip('/')

        projects = self.fetch_projects_in_manifest(options)

        if options.print_new_projects or options.dump_projects or \
                not options.repo_create:
            gerrit = Gerrit(remote)

            new_projects = list()
            existed_projects = gerrit.ls_projects()
            for p in projects:
                if p.uri not in existed_projects:
                    new_projects.append(p)

            if options.dump_projects or options.print_new_projects or \
                    not options.repo_create and len(new_projects) > 0:
                RepoSubcmd.dump_projects(options, projects, new_projects)
                return

        if options.output_xml_file:
            RepoSubcmd.build_xml_file(options, projects, True)
            return

        return self.run_with_thread(  # pylint: disable=E1101
            options.job, projects, RepoSubcmd.push, options, remote)
Esempio n. 6
0
    def execute(self, options, *args, **kws):
        SubCommandWithThread.execute(self, options, *args, **kws)

        logger = self.get_logger()  # pylint: disable=E1101

        def _in_group(limits, groups):
            allminus = True

            for limit in limits:
                opposite = False
                if limit.startswith('-') or limit.startswith('!'):
                    limit = limit[1:]
                    opposite = True
                else:
                    allminus = False

                if limit in groups:
                    return not opposite

            if (allminus or 'default' in limits) and \
                    'notdefault' not in groups and '-default' not in groups:
                return True

            return False

        def _filter_with_group(project, name, limit):
            limits = re.split(r'\s*,\s*', limit or 'default')

            groups = re.split(r'\s*,\s*', project.pop('group', ''))

            if name not in groups:
                groups.append(name)
            bname = os.path.basename(name)
            if bname not in groups:
                groups.append(bname)

            if _in_group(limits, groups):
                return True
            else:
                logger.debug('%s: %s not in %s', getattr(project, 'name'),
                             limits, groups)

                return False

        def _list(batch, projs, nprojs):
            def _inc(dicta, key):
                if key in dicta:
                    dicta[key] += 1
                else:
                    dicta[key] = 1

            print('\nFile: %s' % batch)
            print('==================================')
            if len(nprojs):
                print('Parallel projects with %s job(s)' % (options.job or 1))
                print('---------------------------------')
                results = dict()
                for project in nprojs:
                    _inc(results, '[%s] %s' % (project.schema, project.name))

                for k, result in enumerate(sorted(results.keys())):
                    print('  %2d. %s' % (k + 1, result))

            if len(projs):
                print('\nNon-parallel projects')
                print('---------------------------------')
                results = dict()
                for project in projs:
                    _inc(results, '[%s] %s' % (project.schema, project.name))

                for k, result in enumerate(sorted(results.keys())):
                    print('  %2d. %s%s' %
                          (k + 1, result, ' (%d)' %
                           results[result] if results[result] > 1 else ''))

            print('')

            return True

        def _run(project):
            largs = options.args or list()
            ignore_error = options.ignore_error or False

            # clean current directory
            project.current_dir = False
            # ensure to construct thread logger
            self.get_logger(project.name)  # pylint: disable=E1101
            self._run(
                project.schema,  # pylint: disable=E1101
                project,
                largs,
                ignore_except=ignore_error)

        def _batch(batch):
            conf = BatchXmlConfigFile(batch)

            projs, nprojs, tprojs = list(), list(), list()
            projects = conf.get_names(BatchXmlConfigFile.PROJECT_PREFIX)
            for name in projects or list():
                projects = conf.get_values(name)  # pylint: disable=E1101
                if not isinstance(projects, list):
                    projects = [projects]

                # handle projects with the same name
                for project in projects:
                    proj = Values()
                    # remove the prefix 'project.'
                    proj_name = conf.get_subsection_name(name)  # pylint: disable=E1101
                    setattr(proj, 'name', proj_name)
                    if _filter_with_group(project, proj_name, options.group):
                        optparse = self._cmdopt(project.schema)  # pylint: disable=E1101
                        # recalculate the attribute types
                        proj.join(project, option=optparse)
                        proj.join(options, option=optparse, override=False)
                        if len(projects) == 1:
                            tprojs.append(proj)
                        else:
                            projs.append(proj)

            for project in tprojs:
                try:
                    multiple = self._cmd(  # pylint: disable=E1101
                        project.schema).support_jobs()
                except AttributeError:
                    raise SyntaxError(
                        'schema is not recognized or undefined in %s' %
                        project)

                working_dir = project.pop('working_dir')
                if working_dir:
                    setattr(project, 'working_dir',
                            os.path.abspath(working_dir))

                if multiple:
                    projs.append(project)
                else:
                    nprojs.append(project)

            if options.list:
                return _list(batch, projs, nprojs)

            ret = self.run_with_thread(  # pylint: disable=E1101
                options.job, nprojs, _run)
            ret = self.run_with_thread(  # pylint: disable=E1101
                1, projs, _run) and ret

            return ret

        RaiseExceptionIfOptionMissed(options.batch_file or args,
                                     "batch file (--batch-file) is not set")

        ret = True
        files = (options.batch_file or list())[:]
        files.extend(args[:])

        for batch in files:
            if os.path.isfile(batch):
                ret = _batch(batch) and ret
            else:
                logger.error('cannot find batch file %s', batch)
                ret = False

            if not ret and not options.ignore_errors:
                break

        return ret
Esempio n. 7
0
    def options(self, optparse, inherited=False, modules=None):
        SubCommandWithThread.options(self,
                                     optparse,
                                     option_remote=True,
                                     option_import=True,
                                     modules=modules or globals())

        options = optparse.add_option_group('Repo tool options')
        options.add_option('-u',
                           '--manifest-url',
                           dest='manifest',
                           metavar='URL',
                           help='Set the git-repo manifest url')
        options.add_option('-b',
                           '--branch',
                           '--manifest-branch',
                           dest='manifest_branch',
                           metavar='REVISION',
                           help='Set the project branch or revision')
        options.add_option('-m',
                           '--manifest-name',
                           dest='manifest_name',
                           metavar='NAME.xml',
                           help='initialize the manifest name')
        options.add_option('--mirror',
                           dest='mirror',
                           action='store_true',
                           default=False,
                           help=optparse.SUPPRESS_HELP)

        if not inherited:
            options = optparse.get_option_group('--refs') or \
                optparse.add_option_group('Remote options')
            options.add_option('--prefix',
                               dest='prefix',
                               action='store',
                               metavar='PREFIX',
                               help='prefix on the remote location')
            options.add_option(
                '--sha1-tag',
                dest='sha1_tag',
                action='store',
                metavar='TAG',
                help='Push named tag for the SHA-1 to the remote. It works '
                'without the option "--all"')

            options = optparse.add_option_group('Debug options')
            options.add_option('--dump-projects',
                               dest='dump_projects',
                               action='store_true',
                               help='Print the info of imported project')
            options.add_option(
                '--print-new-projects',
                dest='print_new_projects',
                action='store_true',
                help='Print the new projects which isn\'t managed by Gerrit')

            options = optparse.add_option_group('Other options')
            options.add_option(
                '--include-init-manifest',
                dest='include_init_manifest',
                action='store_true',
                help='Include .repo/manifests if mirror didn\'t contain it')

            options = optparse.add_option_group('Extra action options')
            options.add_option(
                '--convert-manifest-file',
                dest='convert_manifest_file',
                action='store_true',
                help='Do convert the manifest file with the manifest map file')
            options.add_option(
                '--ignore-new-project',
                dest='ignore_new_project',
                action='store_true',
                help='Ignore new projects and do import the git-repo project')

            options = optparse.get_option_group('--hook-dir') or \
                optparse.add_option_group('File options')
            options.add_option('--manifest-xml-file',
                               dest='manifest_xml_file',
                               action='store',
                               metavar='MANIFEST',
                               default='.repo/manifest.xml',
                               help='Set the manifest XML file to parse')
            options.add_option('--output-xml-file',
                               dest='output_xml_file',
                               action='store',
                               metavar='FILE',
                               help='Set the output XML filename')
            options.add_option('--map-file',
                               dest='map_file',
                               action='store',
                               metavar='MAP_FILE',
                               help='Set the manifest map file with patterns')