Beispiel #1
0
def parse_argv(argv, pkgsys):
    options = {}
    for name, value in config.items('scheme-%s' % pkgsys.pkgsysname):
        options['--%s' % name] = value

    pkgsys.init_options(options)

    optname = None
    reqarglist = []

    for arg in argv[1:]:
        if optname is not None:
            options[optname] = arg
            optname = None
        elif arg in options:
            optname = arg
        elif arg[:9] == '--scheme-':
            secname = 'scheme-%s-%s' % (pkgsys.pkgsysname, arg[9:])
            if not config.has_section(secname):
                raise RuntimeError, 'The section %s is not present.' % secname
            for name, value in config.items(secname):
                options['--%s' % name] = value
        else:
            reqarglist.append(arg)

    ensure_dir(options['--unpack-dir'])
    if options['--cache-root'] != '':
        # For the cache saving, download-dir has to be reset.
        options['--download-dir'] = \
            os.path.join(options['--cache-root'], 'downloads')
        options['--cache-simple'] = \
            os.path.join(options['--cache-root'], 'simple')
        ensure_dir(options['--cache-simple'])
    ensure_dir(options['--download-dir'])

    for bopt in ['--skip-broken', '--deps', '--skip-logged']:
        options[bopt] = get_bool_opt(options[bopt])

    pkgsys.finalize_options(options)

    return options, reqarglist
Beispiel #2
0
def parse_argv(argv, pkgsys):
    options = {}
    for name, value in config.items('scheme-%s' % pkgsys.pkgsysname):
        options['--%s' % name] = value

    pkgsys.init_options(options)

    optname = None
    reqarglist = []

    for arg in argv[1:]:
        if optname is not None: options[optname] = arg; optname = None
        elif arg in options: optname = arg
        elif arg[:9] == '--scheme-':
            secname = 'scheme-%s-%s' % (pkgsys.pkgsysname, arg[9:])
            if not config.has_section(secname):
                raise RuntimeError, 'The section %s is not present.' % secname
            for name, value in config.items(secname):
                options['--%s' % name] = value
        else:
            reqarglist.append(arg)

    ensure_dir(options['--unpack-dir'])
    if options['--cache-root'] != '':
        # For the cache saving, download-dir has to be reset.
        options['--download-dir'] = \
            os.path.join(options['--cache-root'], 'downloads')
        options['--cache-simple'] = \
            os.path.join(options['--cache-root'], 'simple')
        ensure_dir(options['--cache-simple'])
    ensure_dir(options['--download-dir'])

    for bopt in ['--skip-broken', '--deps', '--skip-logged']:
        options[bopt] = get_bool_opt(options[bopt])

    pkgsys.finalize_options(options)

    return options, reqarglist
Beispiel #3
0
    def run(self):
        # Prepare for iterations.
        pkgreqmap = reqmap()
        for reqarg in self.reqarglist: pkgreqmap.append_arg(reqarg)
        pkgreqmap.resolve_matchlist(self.logobj, self.options['--url'],
                                    self.options['--skip-logged'])

        pkgidx = PackageIndex(index_url = self.options['--url'])

        show_sepline = False
        # Main loop.
        distlist = []
        ok_packages = []
        while len(pkgreqmap) > 0:
            new_pkgreqmap = reqmap()
            for idx, total, pkgreqobj in pkgreqmap.reqobj_seq():

                pkgname = pkgreqobj.project_name
                if pkgname in ok_packages: continue
                ok_packages.append(pkgname)
                reqstr = str(pkgreqobj)

                if show_sepline: self.pkgsys.sepline()
                else: show_sepline = True

                self.pkgsys.info('======== %s: %d/%d ========' % \
                                     (pkgname, idx + 1, total))

                if self.options['--skip-broken']:
                    try: self.logobj.check_broken(pkgname)
                    except: continue

                # Collect values into args step by step.
                args = copy.copy(self.options)
                args['self'] = self.arg0

                self.pkgsys.begin('Downloading %s' % reqstr)
                try:
                    dist = pkgidx.fetch_distribution(pkgreqobj,
                                                     self.options['--download-dir'],
                                                     source = True)
                    if dist is None:
                        raise RuntimeError, 'None'
                except:
                    self.pkgsys.end(False)
                    self.logobj.in_except(pkgname,
                                          'Download %s failed' % reqstr)
                    continue
                else:
                    self.pkgsys.end(True)

                self.pkgsys.begin('Unpacking %s' % dist.location)
                try: smart_archive(args, dist, self.options['--unpack-dir'])
                except:
                    self.pkgsys.end(False)
                    self.logobj.in_except(pkgname, 'Unpack %s failed' % reqstr)
                    continue
                else:
                    self.pkgsys.end(True)
                unpackpath = args['unpackpath']

                config_secs = ['%s-%s' % (dist.project_name, dist.version),
                               dist.project_name]

                for secname in config_secs:
                    for name, value in config.items(secname):
                        if name not in args: args[name] = value
                if not 'patches' in args: args['patches'] = []
                else: args['patches'] = args['patches'].split()

                # Apply patches.
                for patch in config.patches(config_secs):
                    self.pkgsys.begin('Applying %s' % os.path.basename(patch))
                    os.system('(cd %s; patch -p0 < %s) > /dev/null' % \
                                  (unpackpath, patch))
                    self.pkgsys.end(True)
                    if os.path.isfile(os.path.join(unpackpath, 'fixsetup.py')):
                        os.system('(cd %s; python fixsetup.py)' % unpackpath)

                self.pkgsys.begin('Get package args')
                try: get_package_args(args, dist)
                except:
                    self.pkgsys.end(False)
                    self.logobj.in_except(pkgname, 'Get package args failed')
                    continue
                else:
                    self.pkgsys.end(True)

                self.pkgsys.begin('Setup args')
                try: self.pkgsys.setup_args(args)
                except:
                    self.pkgsys.end(False)
                    self.logobj.in_except(pkgname, 'pkgsys.setup_args failed')
                    continue
                else:
                    self.pkgsys.end(True)

                self.pkgsys.begin('Writing %s' % args['output'])
                try:
                    ensure_dir(os.path.dirname(args['output']))
                    if smart_write(args['output'],
                                   os.path.join(pkgroot, args['template']),
                                   args):
                        updated = True
                    if smart_symlink(args['pkgpath'],
                                     os.path.join(args['filedir'],
                                                  args['pkgfile'])):
                        updated = True
                    if args['patches'] != []:
                        ensure_dir(args['patchdir'])
                        for patch in config.patches(config_secs):
                            tgtpatch = os.path.join(args['patchdir'],
                                                    os.path.basename(patch))
                            if smart_symlink(patch, tgtpatch):
                                updated = True
                except:
                    self.pkgsys.end(False)
                    self.logobj.in_except(pkgname, 'write failed')
                    continue
                else:
                    self.pkgsys.end(True)

                self.pkgsys.begin('Postproess %s' % args['output'])
                try: self.pkgsys.process(args)
                except:
                    self.pkgsys.end(False)
                    self.logobj.in_except(pkgname, 'process failed')
                    continue
                else:
                    self.pkgsys.end(True)

                if self.options['--deps']:
                    reqstrlist = args['install_requires']
                    for k in args['extras_require'].keys():
                        reqstrlist.extend(args['extras_require'][k])
                    for reqstr in reqstrlist:
                        new_pkgreqmap.add(reqstr2obj(reqstr))

                self.logobj.pkgname_ok(pkgname)
                if self.options['--cache-root'] != '': distlist.append(dist)

                # Process of a single package is finished.

            pkgreqmap = new_pkgreqmap

        if self.options['--cache-root']:
            cache = pypicache(self.pkgsys,
                              self.options['--cache-root'],
                              self.options['--cache-url'])
            cache.add_packages(distlist)
            del(cache)
Beispiel #4
0
    def run(self):
        # Prepare for iterations.
        pkgreqmap = reqmap()
        for reqarg in self.reqarglist:
            pkgreqmap.append_arg(reqarg)
        pkgreqmap.resolve_matchlist(self.logobj, self.options['--url'],
                                    self.options['--skip-logged'])

        pkgidx = PackageIndex(index_url=self.options['--url'])

        show_sepline = False
        # Main loop.
        distlist = []
        ok_packages = []
        while len(pkgreqmap) > 0:
            new_pkgreqmap = reqmap()
            for idx, total, pkgreqobj in pkgreqmap.reqobj_seq():

                pkgname = pkgreqobj.project_name
                if pkgname in ok_packages: continue
                ok_packages.append(pkgname)
                reqstr = str(pkgreqobj)

                if show_sepline: self.pkgsys.sepline()
                else: show_sepline = True

                self.pkgsys.info('======== %s: %d/%d ========' % \
                                     (pkgname, idx + 1, total))

                if self.options['--skip-broken']:
                    try:
                        self.logobj.check_broken(pkgname)
                    except:
                        continue

                # Collect values into args step by step.
                args = copy.copy(self.options)
                args['self'] = self.arg0

                self.pkgsys.begin('Downloading %s' % reqstr)
                try:
                    dist = pkgidx.fetch_distribution(
                        pkgreqobj, self.options['--download-dir'], source=True)
                    if dist is None:
                        raise RuntimeError, 'None'
                except:
                    self.pkgsys.end(False)
                    self.logobj.in_except(pkgname,
                                          'Download %s failed' % reqstr)
                    continue
                else:
                    self.pkgsys.end(True)

                self.pkgsys.begin('Unpacking %s' % dist.location)
                try:
                    smart_archive(args, dist, self.options['--unpack-dir'])
                except:
                    self.pkgsys.end(False)
                    self.logobj.in_except(pkgname, 'Unpack %s failed' % reqstr)
                    continue
                else:
                    self.pkgsys.end(True)
                unpackpath = args['unpackpath']

                config_secs = [
                    '%s-%s' % (dist.project_name, dist.version),
                    dist.project_name
                ]

                for secname in config_secs:
                    for name, value in config.items(secname):
                        if name not in args: args[name] = value
                if not 'patches' in args: args['patches'] = []
                else: args['patches'] = args['patches'].split()

                # Apply patches.
                for patch in config.patches(config_secs):
                    self.pkgsys.begin('Applying %s' % os.path.basename(patch))
                    os.system('(cd %s; patch -p0 < %s) > /dev/null' % \
                                  (unpackpath, patch))
                    self.pkgsys.end(True)
                    if os.path.isfile(os.path.join(unpackpath, 'fixsetup.py')):
                        os.system('(cd %s; python fixsetup.py)' % unpackpath)

                self.pkgsys.begin('Get package args')
                try:
                    get_package_args(args, dist)
                except:
                    self.pkgsys.end(False)
                    self.logobj.in_except(pkgname, 'Get package args failed')
                    continue
                else:
                    self.pkgsys.end(True)

                self.pkgsys.begin('Setup args')
                try:
                    self.pkgsys.setup_args(args)
                except:
                    self.pkgsys.end(False)
                    self.logobj.in_except(pkgname, 'pkgsys.setup_args failed')
                    continue
                else:
                    self.pkgsys.end(True)

                self.pkgsys.begin('Writing %s' % args['output'])
                try:
                    ensure_dir(os.path.dirname(args['output']))
                    if smart_write(args['output'],
                                   os.path.join(pkgroot, args['template']),
                                   args):
                        updated = True
                    if smart_symlink(
                            args['pkgpath'],
                            os.path.join(args['filedir'], args['pkgfile'])):
                        updated = True
                    if args['patches'] != []:
                        ensure_dir(args['patchdir'])
                        for patch in config.patches(config_secs):
                            tgtpatch = os.path.join(args['patchdir'],
                                                    os.path.basename(patch))
                            if smart_symlink(patch, tgtpatch):
                                updated = True
                except:
                    self.pkgsys.end(False)
                    self.logobj.in_except(pkgname, 'write failed')
                    continue
                else:
                    self.pkgsys.end(True)

                self.pkgsys.begin('Postproess %s' % args['output'])
                try:
                    self.pkgsys.process(args)
                except:
                    self.pkgsys.end(False)
                    self.logobj.in_except(pkgname, 'process failed')
                    continue
                else:
                    self.pkgsys.end(True)

                if self.options['--deps']:
                    reqstrlist = args['install_requires']
                    for k in args['extras_require'].keys():
                        reqstrlist.extend(args['extras_require'][k])
                    for reqstr in reqstrlist:
                        new_pkgreqmap.add(reqstr2obj(reqstr))

                self.logobj.pkgname_ok(pkgname)
                if self.options['--cache-root'] != '': distlist.append(dist)

                # Process of a single package is finished.

            pkgreqmap = new_pkgreqmap

        if self.options['--cache-root']:
            cache = pypicache(self.pkgsys, self.options['--cache-root'],
                              self.options['--cache-url'])
            cache.add_packages(distlist)
            del (cache)