Example #1
0
def parse_profiles(xml_path):
    """ Parse .qi/qibuild.xml. Return a dict
    name -> Profile
    """
    res = dict()
    tree = qixml.read(xml_path)
    root = tree.getroot()
    profile_elems = root.findall("profiles/profile")
    for profile_elem in profile_elems:
        profile_name = qixml.parse_required_attr(profile_elem, "name")
        profile = Profile(profile_name)
        res[profile_name] = profile
        cmake_elem = profile_elem.find("cmake")
        if cmake_elem is None:
            continue
        flags_elem = cmake_elem.find("flags")
        if flags_elem is None:
            continue
        flag_elems = flags_elem.findall("flag")
        for flag_elem in flag_elems:
            key = qixml.parse_required_attr(flag_elem, "name")
            value = flag_elem.text.strip()
            to_add = "%s=%s" % (key, value)
            profile.cmake_flags.append(to_add)
    return res
Example #2
0
def check_parent_project(toc, project_name, project_path):
    """ Check if the qibuild project was not found because
    there was a missing
    <project src= ... />  in the parent qiproject.xml file

    """
    parent_proj = get_parent_project(toc, project_path)
    if not parent_proj:
        return
    parent_qiproj = os.path.join(parent_proj.path, "qiproject.xml")
    if not os.path.exists(parent_qiproj):
        return
    question = "Add the path to project %s to its parent qiproject.xml"
    question = question % (project_name)
    answer = qisys.interact.ask_yes_no(question, default=True)
    if answer:
        ui.info("Patching", parent_qiproj)
        tree = qixml.read(parent_qiproj)
        child_src = os.path.relpath(project_path, parent_proj.path)
        child_src = qisys.sh.to_posix_path(child_src)
        to_add = qixml.etree.Element("project")
        to_add.set("src", child_src)
        tree.getroot().append(to_add)
        qixml.write(tree, parent_qiproj)
        toc.projects = list()
        toc.worktree.load()
        toc.update_projects()
Example #3
0
    def parse(self, xml_path):
        """ Recursive function. This is also called on each
        sub manifest, so that self.sub_manifests contains
        fully initialized Manifest() objects when this function
        returns

        """
        self.xml_path = xml_path
        tree = qixml.read(xml_path)
        remote_elems = tree.findall("remote")
        for remote_elem in remote_elems:
            remote = Remote()
            remote.parse(remote_elem)
            self.remotes[remote.name] = remote
        project_elems = tree.findall("project")
        for project_elem in project_elems:
            project = Project()
            project.parse(project_elem)
            self.projects.append(project)
        blacklist_elems = tree.findall("blacklist")
        for blacklist_elem in blacklist_elems:
            name = blacklist_elem.get("name")
            if name:
                self.blacklist.append(name)
        manifest_elems = tree.findall("manifest")
        for manifest_elem in manifest_elems:
            manifest_url = manifest_elem.get("url")
            if manifest_url:
                dirname = os.path.dirname(xml_path)
                sub_manifest_xml = os.path.join(dirname, manifest_url)
                sub_manifest = Manifest()
                sub_manifest.xml_path = sub_manifest_xml
                sub_manifest.parse(sub_manifest.xml_path)
                self.sub_manifests.append(sub_manifest)
        self.update_projects()
Example #4
0
 def parse_qiproject_xml(self):
     qiproject_xml = os.path.join(self.path, "qiproject.xml")
     if not os.path.exists(qiproject_xml):
         return
     tree = qixml.read(qiproject_xml)
     project_elems = tree.findall("project")
     for project_elem in project_elems:
         src = qixml.parse_required_attr(project_elem, "src", xml_path=qiproject_xml)
         self.subprojects.append(src)
Example #5
0
def add_profile(xml_path, profile):
    """ Add a new profile to an XML file

    """
    tree = qixml.read(xml_path)
    root = tree.getroot()
    profiles = root.find("profiles")
    if profiles is None:
        profiles = qixml.etree.Element("profiles")
        root.append(profiles)
    profiles.append(profile.elem())
    qixml.write(tree, xml_path)
Example #6
0
    def load(self):
        """ Load the worktree.xml file. """
        self.projects = list()
        dot_qi = os.path.join(self.root, ".qi")
        worktree_xml = os.path.join(dot_qi, "worktree.xml")
        if not os.path.exists(worktree_xml):
            qisys.sh.mkdir(dot_qi)
            with open(worktree_xml, "w") as fp:
                fp.write("<worktree />\n")
        if os.path.exists(worktree_xml):
            self.xml_tree = qixml.read(worktree_xml)
            self.parse_projects()

        self.projects.sort(key=operator.attrgetter("src"))
Example #7
0
def project_from_cwd():
    """Return a project name from the current working directory

    """
    head = os.getcwd()
    qiproj_xml = None
    while True:
        qiproj_xml = os.path.join(head, "qiproject.xml")
        if os.path.exists(qiproj_xml):
            break
        (head, _tail) = os.path.split(head)
        if not _tail:
            break
    if not qiproj_xml:
        mess  = "Could not guess project name from current working directory\n"
        mess += "(No qiproject.xml found in the parent directories\n"
        mess += "Please go inside a project, or specify the project name "
        mess += "from the command line"

    xml_elem = qixml.read(qiproj_xml)
    return xml_elem.getroot().get("name")
Example #8
0
def project_from_dir(toc, directory=None, raises=True):
    """Return a project name from a directory.

    """
    if not directory:
        directory = os.getcwd()
    head = directory
    tail = None
    qiproj_xml = None
    while True:
        candidate = os.path.join(head, "qiproject.xml")
        if os.path.exists(candidate):
            qiproj_xml = candidate
            break
        (head, tail) = os.path.split(head)
        if not tail:
            break
    if not qiproj_xml:
        if raises:
            mess  = "Could not guess project name from current working directory: "
            mess += "'%s'\n" % os.getcwd()
            mess += "(No qiproject.xml found in the parent directories)\n"
            mess += "Please go inside a project, or specify the project name "
            mess += "from the command line"
            raise Exception(mess)
        else:
            return None
    xml_elem = qixml.read(qiproj_xml)
    project_name = xml_elem.getroot().get("name")
    if toc.get_project(project_name, raises=False):
        return project_name
    mess = """Found a valid qiproject.xml ('{qiproj_xml}')
while trying to guess a buildable project from the current working dir ('{cwd}')
But the project name: '{project_name}' does not match any buildable toc project"""
    mess = mess.format(qiproj_xml=qiproj_xml, cwd=directory, project_name=project_name)
    ui.warning(mess)
    project_path = os.path.dirname(qiproj_xml)
    res = add_missing_buildable_project(toc, project_name, project_path)
    return res
Example #9
0
    def parse(self, xml_path):
        """ Recursive function. This is also called on each
        sub manifest, so that self.sub_manifests contains
        fully initialized Manifest() objects when this function
        returns

        """
        self.xml_path = xml_path
        tree = qixml.read(xml_path)

        remotes = parse_remotes(tree)
        for remote in remotes:
            self.remotes[remote.name] = remote

        projects = parse_projects(tree)
        self.projects.extend(projects)

        blacklists = parse_blacklists(tree)
        self.blacklist.extend(blacklists)

        sub_manifests = parse_manifests(tree, xml_path)
        self.sub_manifests.extend(sub_manifests)

        self.update_projects()