Exemplo n.º 1
0
    def __init__(self,
                 arch=None,
                 sync=False,
                 stdout=None,
                 stderr=None,
                 config=None):
        self.local_env = os.environ.copy()
        if stdout:
            self.stdout = stdout
        else:
            self.stdout = PIPE
        if stderr:
            self.stderr = stderr
        else:
            self.stderr = PIPE

        self.cfg = load_config(config)
        if not sync and not isdir(self.cfg['ov_path']):
            raise XTargetError("Can't find targets portage %s" %
                               self.cfg['ov_path'])

        self.arch_list = []
        if not sync and exists(self.cfg['ov_path'] + "/profiles/arch.list"):
            fd_in = open(self.cfg['ov_path'] + "/profiles/arch.list", 'r')
            for line in fd_in.readlines():
                self.arch_list.append(line)
            fd_in.close()
        self.local_env["PORTAGE_CONFIGROOT"] = self.cfg['tmpdir']
        self._create_configroot(arch)
        self.xportage = XPortage(root=self.cfg['tmpdir'])
Exemplo n.º 2
0
    def sync_overlay(self, dir=None):
        """Sync target's overlays"""
        if not dir:
            dir = get_current_target(config=self.cfg)

        self.local_env["ROOT"] = dir + "/root/"
        self.local_env["PORTAGE_CONFIGROOT"] = dir + "/root/"
        self.local_env["NO_TARGET_UPDATE"] = "True"

        rel = XTargetReleaseParser().get(dir, self.cfg['release_file'])
        if rel and rel.has_key('overlay'):
            for ov in rel['overlay']:
                var = "PORTAGE_%s_REVISION" % ov['name'].upper()
                self.local_env[var] = ov['version']

        cmd = Popen(["emerge", "--sync"],
                    bufsize=-1,
                    stdout=self.stdout,
                    stderr=self.stderr,
                    shell=False,
                    cwd=None,
                    env=self.local_env)
        (stdout, stderr) = cmd.communicate()
        ret = cmd.returncode

        if ret != 0:
            raise XTargetError("Syncing overlays of target failed", stdout,
                               stderr)

        rel = XTargetReleaseParser().get(dir, self.cfg['release_file'])
        xportage = XPortage(root=dir + "/root")

        base_mirror = xportage.config['BASE_MIRROR']
        if base_mirror:
            self.local_env["PORTAGE_BINHOST"] = base_mirror + "/" + rel.get(
                'name', '') + "/" + rel.get(
                    'arch', '') + "/" + xportage.config.get('CHOST', '')

        self.local_env["DISTDIR"] = dir + "/distfiles/"
        self.local_env["PORTAGE_TMPDIR"] = dir + "/build/"

        if not self.cfg['create_libc']:
            return
        cmd2 = Popen(["emerge", "-bug", "virtual/libc"],
                     bufsize=-1,
                     stdout=self.stdout,
                     stderr=self.stderr,
                     shell=False,
                     cwd=None,
                     env=self.local_env)
        (stdout2, stderr2) = cmd2.communicate()
        ret2 = cmd2.returncode

        if ret2 != 0:
            raise XTargetError("Merging libc failed", stdout2, stderr2)
Exemplo n.º 3
0
        def __init__(self, arch=None, sync=False, stdout=None, stderr=None, config=None):
                self.local_env = os.environ.copy()
                if stdout:
                        self.stdout = stdout
                else:
                        self.stdout = PIPE
                if stderr:
                        self.stderr = stderr
                else:
                        self.stderr = PIPE

                self.cfg = load_config(config)
                if not sync and not isdir(self.cfg['ov_path']):
                        raise XTargetError("Can't find targets portage %s" % self.cfg['ov_path'])

                self.arch_list = []
                if not sync and exists(self.cfg['ov_path'] + "/profiles/arch.list"):
                        fd_in = open(self.cfg['ov_path'] + "/profiles/arch.list", 'r')
                        for line in fd_in.readlines():
                                self.arch_list.append(line)
                        fd_in.close()
                self.local_env["PORTAGE_CONFIGROOT"] = self.cfg['tmpdir']
                self._create_configroot(arch)
                self.xportage = XPortage(root=self.cfg['tmpdir'])
Exemplo n.º 4
0
class XTargetBuilder(object):
        """ A class to manage targets.
        It uses XPortage to parse the \"targets\" profile """
        def __init__(self, arch=None, sync=False, stdout=None, stderr=None, config=None):
                self.local_env = os.environ.copy()
                if stdout:
                        self.stdout = stdout
                else:
                        self.stdout = PIPE
                if stderr:
                        self.stderr = stderr
                else:
                        self.stderr = PIPE

                self.cfg = load_config(config)
                if not sync and not isdir(self.cfg['ov_path']):
                        raise XTargetError("Can't find targets portage %s" % self.cfg['ov_path'])

                self.arch_list = []
                if not sync and exists(self.cfg['ov_path'] + "/profiles/arch.list"):
                        fd_in = open(self.cfg['ov_path'] + "/profiles/arch.list", 'r')
                        for line in fd_in.readlines():
                                self.arch_list.append(line)
                        fd_in.close()
                self.local_env["PORTAGE_CONFIGROOT"] = self.cfg['tmpdir']
                self._create_configroot(arch)
                self.xportage = XPortage(root=self.cfg['tmpdir'])

        def _create_configroot(self, arch):
                self._mk_tmpdir()
                fd_in = open(self.cfg['tmpdir'] + "/etc/make.conf", "w")
                fd_in.write('PORTDIR="%s"\n' % self.cfg['ov_path'])
                fd_in.write('PORTDIR_OVERLAY=""\n')
                fd_in.write('ACCEPT_KEYWORDS="-* %s"\n' % self.__get_keywords(arch))
                fd_in.write('FEATURES="-strict"\n')
                if exists(self.cfg['ov_config']):
                        fd_in.write(''.join(open(self.cfg['ov_config']).readlines()))
                fd_in.close()

        def list_profiles_ng(self, pkg_atom=None, version=False, filter=None, multi=True):
                """ List profiles.
                Returns a tuple of all targets and avaiable targets. """
                if pkg_atom:
                        version = True

                if not self.xportage.portdb:
                        self.xportage.create_trees()
                if pkg_atom is None:
                        if version:
                                target_list = self.xportage.portdb.cpv_all()
                        else:
                                target_list = self.xportage.portdb.cp_all()
                else:
                        try:
                                target_list = self.xportage.match_all(pkg_atom, multi=multi)
                        except XPortageError, e:
                                raise XTargetError(str(e))

                target_list.sort(key=key)
                bm = self.xportage.best_match

                if len(target_list) == 0:
                        raise XTargetError("No matching profile found")
                for target in target_list:
                    atom = target
                    if version:
                        atom = "=%s"%atom
                    try:
                        yield target, (bool(bm(atom)) if filter else True)
                    except XPortageError, e:
                        raise XTargetError(str(e))
Exemplo n.º 5
0
class XTargetBuilder(object):
    """ A class to manage targets.
        It uses XPortage to parse the \"targets\" profile """
    def __init__(self,
                 arch=None,
                 sync=False,
                 stdout=None,
                 stderr=None,
                 config=None):
        self.local_env = os.environ.copy()
        if stdout:
            self.stdout = stdout
        else:
            self.stdout = PIPE
        if stderr:
            self.stderr = stderr
        else:
            self.stderr = PIPE

        self.cfg = load_config(config)
        if not sync and not isdir(self.cfg['ov_path']):
            raise XTargetError("Can't find targets portage %s" %
                               self.cfg['ov_path'])

        self.arch_list = []
        if not sync and exists(self.cfg['ov_path'] + "/profiles/arch.list"):
            fd_in = open(self.cfg['ov_path'] + "/profiles/arch.list", 'r')
            for line in fd_in.readlines():
                self.arch_list.append(line)
            fd_in.close()
        self.local_env["PORTAGE_CONFIGROOT"] = self.cfg['tmpdir']
        self._create_configroot(arch)
        self.xportage = XPortage(root=self.cfg['tmpdir'])

    def _create_configroot(self, arch):
        self._mk_tmpdir()
        fd_in = open(self.cfg['tmpdir'] + "/etc/make.conf", "w")
        fd_in.write('PORTDIR="%s"\n' % self.cfg['ov_path'])
        fd_in.write('PORTDIR_OVERLAY=""\n')
        fd_in.write('ACCEPT_KEYWORDS="-* %s"\n' % self.__get_keywords(arch))
        fd_in.write('FEATURES="-strict"\n')
        if exists(self.cfg['ov_config']):
            fd_in.write(''.join(open(self.cfg['ov_config']).readlines()))
        fd_in.close()

    def list_profiles_ng(self,
                         pkg_atom=None,
                         version=False,
                         filter=None,
                         multi=True):
        """ List profiles.
                Returns a tuple of all targets and avaiable targets. """
        if pkg_atom:
            version = True

        if not self.xportage.portdb:
            self.xportage.create_trees()
        if pkg_atom is None:
            if version:
                target_list = self.xportage.portdb.cpv_all()
            else:
                target_list = self.xportage.portdb.cp_all()
        else:
            try:
                target_list = self.xportage.match_all(pkg_atom, multi=multi)
            except XPortageError, e:
                raise XTargetError(str(e))

        target_list.sort(key=key)
        bm = self.xportage.best_match

        if len(target_list) == 0:
            raise XTargetError("No matching profile found")
        for target in target_list:
            atom = target
            if version:
                atom = "=%s" % atom
            try:
                yield target, (bool(bm(atom)) if filter else True)
            except XPortageError, e:
                raise XTargetError(str(e))