def pyinstall(package, vrange):
    """Install local files listed in pkg.pyinstall files as public modules."""
    status = True
    srcfpath = "./debian/%s.pyinstall" % package
    if not exists(srcfpath):
        return status
    versions = get_requested_versions(vrange)

    for line in codecs.open(srcfpath, encoding='utf-8'):
        if not line or line.startswith('#'):
            continue
        details = INSTALL_RE.match(line)
        if not details:
            status = False
            log.warn('%s.pyinstall: unrecognized line: %s', package, line)
            continue
        details = details.groupdict()
        if details['module']:
            details['module'] = details['module'].replace('.', '/')
        myvers = versions & get_requested_versions(details['vrange'])
        if not myvers:
            log.debug('%s.pyinstall: no matching versions for line %s',
                      package, line)
            continue
        files = glob(details['pattern'])
        if not files:
            status = False
            log.error('%s.pyinstall: file not found: %s', package,
                      details['pattern'])
            continue
        for fpath in files:
            fpath = fpath.lstrip('/.')
            if details['module']:
                dstname = join(details['module'], split(fpath)[1])
            elif fpath.startswith('debian/'):
                dstname = fpath[7:]
            else:
                dstname = fpath
            for version in myvers:
                dstfpath = join(sitedir(version, package), dstname)
                dstdir = split(dstfpath)[0]
                if not exists(dstdir):
                    try:
                        os.makedirs(dstdir)
                    except Exception:
                        log.error('cannot create %s directory', dstdir)
                        return False
                if exists(dstfpath):
                    try:
                        os.remove(dstfpath)
                    except Exception:
                        status = False
                        log.error('cannot replace %s file', dstfpath)
                        continue
                try:
                    os.link(fpath, dstfpath)
                except Exception:
                    status = False
                    log.error('cannot copy %s file to %s', fpath, dstdir)
    return status
예제 #2
0
def load(dname='/usr/share/python/dist/',
         fname='debian/pydist-overrides',
         fbname='/usr/share/python/dist_fallback'):
    """Load iformation about installed Python distributions."""
    if exists(fname):
        to_check = [fname]  # first one!
    else:
        to_check = []
    if isdir(dname):
        to_check.extend(join(dname, i) for i in os.listdir(dname))
    if exists(fbname):  # fall back generated at python-defaults build time
        to_check.append(fbname)  # last one!

    result = {}
    for fpath in to_check:
        with open(fpath) as fp:
            for line in fp:
                line = line.strip('\r\n')
                if line.startswith('#') or not line:
                    continue
                dist = PYDIST_RE.search(line)
                if not dist:
                    raise Exception('invalid pydist line: %s (in %s)' %
                                    (line, fpath))
                dist = dist.groupdict()
                name = safe_name(dist['name'])
                dist['versions'] = get_requested_versions(dist['vrange'])
                dist['dependency'] = dist['dependency'].strip()
                if dist['rules']:
                    dist['rules'] = dist['rules'].split(';')
                else:
                    dist['rules'] = []
                result.setdefault(name, []).append(dist)
    return result
예제 #3
0
def load(dname='/usr/share/python/dist/', fname='debian/pydist-overrides',
         fbname='/usr/share/python/dist_fallback'):
    """Load iformation about installed Python distributions."""
    if exists(fname):
        to_check = [fname]  # first one!
    else:
        to_check = []
    if isdir(dname):
        to_check.extend(join(dname, i) for i in os.listdir(dname))
    if exists(fbname):  # fall back generated at python-defaults build time
        to_check.append(fbname)  # last one!

    result = {}
    for fpath in to_check:
        with open(fpath) as fp:
            for line in fp:
                line = line.strip('\r\n')
                if line.startswith('#') or not line:
                    continue
                dist = PYDIST_RE.search(line)
                if not dist:
                    raise Exception('invalid pydist line: %s (in %s)' % (line, fpath))
                dist = dist.groupdict()
                name = safe_name(dist['name'])
                dist['versions'] = get_requested_versions(dist['vrange'])
                dist['dependency'] = dist['dependency'].strip()
                if dist['rules']:
                    dist['rules'] = dist['rules'].split(';')
                else:
                    dist['rules'] = []
                result.setdefault(name, []).append(dist)
    return result
예제 #4
0
def pyremove(package, vrange):
    """Remove public modules listed in pkg.pyremove file."""
    status = True
    srcfpath = "./debian/%s.pyremove" % package
    if not exists(srcfpath):
        return status
    versions = get_requested_versions(vrange)

    for line in codecs.open(srcfpath, encoding='utf-8'):
        if not line or line.startswith('#'):
            continue
        details = REMOVE_RE.match(line)
        if not details:
            status = False
            log.warn('%s.pyremove: unrecognized line: %s',
                     package, line)
            continue
        details = details.groupdict()
        myvers = versions & get_requested_versions(details['vrange'])
        if not myvers:
            log.debug('%s.pyremove: no matching versions for line %s',
                      package, line)
            continue
        for version in myvers:
            files = glob(sitedir(version, package) + details['pattern'])
            if not files:
                log.debug('%s.pyremove: nothing to remove: python%d.%d, %s',
                          package, version, details['pattern'])
                continue
            for fpath in files:
                if isdir(fpath):
                    try:
                        rmtree(fpath)
                    except Exception, e:
                        status = False
                        log.error(e)
                else:
                    try:
                        os.remove(fpath)
                    except (IOError, OSError), e:
                        status = False
                        log.error(e)
def pyremove(package, vrange):
    """Remove public modules listed in pkg.pyremove file."""
    status = True
    srcfpath = "./debian/%s.pyremove" % package
    if not exists(srcfpath):
        return status
    versions = get_requested_versions(vrange)

    for line in codecs.open(srcfpath, encoding='utf-8'):
        if not line or line.startswith('#'):
            continue
        details = REMOVE_RE.match(line)
        if not details:
            status = False
            log.warn('%s.pyremove: unrecognized line: %s', package, line)
            continue
        details = details.groupdict()
        myvers = versions & get_requested_versions(details['vrange'])
        if not myvers:
            log.debug('%s.pyremove: no matching versions for line %s', package,
                      line)
            continue
        for version in myvers:
            files = glob(sitedir(version, package) + details['pattern'])
            if not files:
                log.debug('%s.pyremove: nothing to remove: python%d.%d, %s',
                          package, version, details['pattern'])
                continue
            for fpath in files:
                if isdir(fpath):
                    try:
                        rmtree(fpath)
                    except Exception, e:
                        status = False
                        log.error(e)
                else:
                    try:
                        os.remove(fpath)
                    except (IOError, OSError), e:
                        status = False
                        log.error(e)
예제 #6
0
def pyinstall(package, vrange):
    """Install local files listed in pkg.pyinstall files as public modules."""
    status = True
    srcfpath = "./debian/%s.pyinstall" % package
    if not exists(srcfpath):
        return status
    versions = get_requested_versions(vrange)

    for line in codecs.open(srcfpath, encoding='utf-8'):
        if not line or line.startswith('#'):
            continue
        details = INSTALL_RE.match(line)
        if not details:
            status = False
            log.warn('%s.pyinstall: unrecognized line: %s',
                     package, line)
            continue
        details = details.groupdict()
        if details['module']:
            details['module'] = details['module'].replace('.', '/')
        myvers = versions & get_requested_versions(details['vrange'])
        if not myvers:
            log.debug('%s.pyinstall: no matching versions for line %s',
                      package, line)
            continue
        files = glob(details['pattern'])
        if not files:
            status = False
            log.error('%s.pyinstall: file not found: %s',
                      package, details['pattern'])
            continue
        for fpath in files:
            fpath = fpath.lstrip('/.')
            if details['module']:
                dstname = join(details['module'], split(fpath)[1])
            elif fpath.startswith('debian/'):
                dstname = fpath[7:]
            else:
                dstname = fpath
            for version in myvers:
                dstfpath = join(sitedir(version, package), dstname)
                dstdir = split(dstfpath)[0]
                if not exists(dstdir):
                    try:
                        os.makedirs(dstdir)
                    except Exception:
                        log.error('cannot create %s directory', dstdir)
                        return False
                if exists(dstfpath):
                    try:
                        os.remove(dstfpath)
                    except Exception:
                        status = False
                        log.error('cannot replace %s file', dstfpath)
                        continue
                try:
                    os.link(fpath, dstfpath)
                except Exception:
                    status = False
                    log.error('cannot copy %s file to %s', fpath, dstdir)
    return status