예제 #1
0
def get_dependencies_from_pom(main_pom_file, pom_file, poms_base_dir, libA,
                              libB, versionMissing, logf):

    try:
        tree = parse(pom_file)
    except Exception as e:
        logf.write(
            str(e) +
            ", --> Pom file %s does not exist when looked by the main pom file %s.\n"
            % (pom_file, main_pom_file))
        return

    # The main root to extract information
    root = bs(tree.toxml(), 'lxml')

    project_info = project(
        None, None,
        None)  # Intializing project class with None as intial Information

    if root.project.find_all('groupid', recursive=False):
        root_gid = root.project.find_all('groupid', recursive=False)
        for rid in root_gid:
            project_info.set_groupId(rid.text)

    if root.project.find_all('artifactid', recursive=False):
        root_aid = root.project.find_all('artifactid', recursive=False)
        for rid in root_aid:
            project_info.set_artifactId(rid.text)

    if root.project.find_all('version', recursive=False):
        root_vid = root.project.find_all('version', recursive=False)
        for rid in root_vid:
            project_info.set_version(rid.text)

    # To keep parent information
    parent_info = parent(None, None, None, None)
    has_parent = False

    for p in root.project.find_all('parent', recursive=False):
        if type(p) == bs4.element.Tag:
            has_parent = True
            parent_info.set_groupId(p.find('groupid').text)
            parent_info.set_artifactId(p.find('artifactid').text)
            parent_info.set_version(p.find('version').text)
            parent_info.set_path(poms_base_dir + parent_info.get_groupId() +
                                 "-" + parent_info.get_artifactId() + "-" +
                                 parent_info.get_version() + ".pom")

    # To handle if the project groupId and version not giving, then we use the parent groupId and version
    if project_info.get_groupId() is None:
        project_info.set_groupId(parent_info.get_groupId())
    if project_info.get_version() is None:
        project_info.set_version(parent_info.get_version())

    # Adding the information of LibA here

    if libA[0]['groupid'] is None:
        libA[0]['groupid'] = project_info.get_groupId()
    if libA[0]['artifactid'] is None:
        libA[0]['artifactid'] = project_info.get_artifactId()
    if libA[0]['version'] is None:
        libA[0]['version'] = project_info.get_version()

    # Collecting direct deps of this project

    direct_deps = root.project.find_all('dependencies', recursive=False)
    for deps in direct_deps:  # Dependencies tag, and dep = dependency
        if type(deps) == bs4.element.Tag:
            for dep in deps:
                if type(dep) == bs4.element.Tag:

                    # temp_dict = {'groupid': None, 'artifactid': None, 'version': None, 'scope': None}
                    temp_dep = dependency(None, None, None, None)

                    if dep.find('groupid'):
                        temp_dep.set_groupId(dep.find('groupid').text)
                    if dep.find('artifactid'):
                        temp_dep.set_artifactId(dep.find('artifactid').text)
                    if dep.find('version'):
                        temp_dep.set_version(dep.find('version').text)
                    if dep.find('scope'):
                        temp_dep.set_scope(dep.find('scope').text)

                    if temp_dep.get_scope() == 'test' or temp_dep.get_scope(
                    ) == 'system':  # Ignore 2 scopes
                        pass

                    else:
                        if temp_dep.get_groupId(
                        ) is not None and temp_dep.get_artifactId(
                        ) is not None:
                            if temp_dep.get_groupId(
                            )[0] == "$":  # To handles the weird groupIds

                                temp_dep.set_groupId(
                                    resolve_groupId(root,
                                                    temp_dep.get_groupId(),
                                                    project_info.get_groupId(),
                                                    parent_info.get_groupId()))

                            if temp_dep.get_version() is not None:

                                if temp_dep.get_version()[0] == "$":

                                    temp_dep.set_version(
                                        resolve_version(
                                            root, temp_dep.get_version(),
                                            project_info.get_version(),
                                            parent_info.get_version()))

                                libB.append(temp_dep.get_groupId() + ":" +
                                            temp_dep.get_artifactId() + ":" +
                                            temp_dep.get_version())

                            if temp_dep.get_version() is None:

                                versionMissing.update({
                                    len(libB): {
                                        'gid': temp_dep.get_groupId(),
                                        'aid': temp_dep.get_artifactId()
                                    }
                                })
                                libB.append(temp_dep.get_groupId() + ":" +
                                            temp_dep.get_artifactId() + ":" +
                                            "ver_none")

                        else:
                            try:
                                libB.append(temp_dep.get_groupId() + ":" +
                                            temp_dep.get_artifactId() + ":" +
                                            temp_dep.get_version())

                            except Exception as e:
                                if temp_dep.get_groupId() is None:
                                    temp_dep.set_groupId('None')
                                if temp_dep.get_artifactId() is None:
                                    temp_dep.set_artifactId('None')
                                if temp_dep.get_version() is None:
                                    temp_dep.set_version('None')

                                libB_temp = temp_dep.get_groupId(
                                ) + ":" + temp_dep.get_artifactId(
                                ) + ":" + temp_dep.get_version()
                                logf.write("The main pom file %s has a parent %s that has a dependency with invalid artifactId(g:a:v)--> %s.\n" % \
                                 (main_pom_file, pom_file, libB_temp))
                                del libB_temp
                                pass

    del_version_idx = []
    if len(versionMissing) > 0:
        deps_manage = root.project.find_all('dependencymanagement',
                                            recursive=False)
        for key, value in versionMissing.items():
            version_found = False
            for deps in deps_manage:  # deps = dependecies
                if type(deps) == bs4.element.Tag:
                    for dep in deps:  # dep = dependency
                        if type(dep) == bs4.element.Tag:
                            for d in dep:
                                if type(d) == bs4.element.Tag:

                                    depm = dependency(None, None, None, None)

                                    if d.find('groupid'):
                                        depm.set_groupId(
                                            d.find('groupid').text)
                                    if d.find('artifactid'):
                                        depm.set_artifactId(
                                            d.find('artifactid').text)
                                    if d.find('version'):
                                        depm.set_version(
                                            d.find('version').text)
                                    if d.find('scope'):
                                        depm.set_scope(d.find('scope').text)

                                    if depm.get_groupId()[0] == "$":

                                        depm.set_groupId(
                                            resolve_groupId(
                                                root, depm.get_groupId(),
                                                project_info.get_groupId(),
                                                parent_info.get_groupId()))

                                    if depm.get_groupId(
                                    ) == value['gid'] and depm.get_artifactId(
                                    ) == value['aid'] and depm.get_version(
                                    )[0] == '$' and depm.get_scope(
                                    ) != 'import':

                                        depm.set_version(
                                            resolve_version(
                                                root, depm.get_version(),
                                                project_info.get_version(),
                                                parent_info.get_version()))

                                    if depm.get_groupId(
                                    ) == value['gid'] and depm.get_artifactId(
                                    ) == value['aid'] and depm.get_scope(
                                    ) != 'import':

                                        libB_split = libB[key].split(":")
                                        libB[key] = libB_split[
                                            0] + ":" + libB_split[
                                                1] + ":" + depm.get_version()
                                        del_version_idx.append(key)
                                        version_found = True

                                    if depm.get_scope() == "import":

                                        if depm.get_version()[0] == '$':

                                            depm.set_version(
                                                resolve_version(
                                                    root, depm.get_version(),
                                                    project_info.get_version(),
                                                    parent_info.get_version()))

                                        depm_fname = depm.get_groupId(
                                        ) + "-" + depm.get_artifactId(
                                        ) + "-" + depm.get_version() + ".pom"
                                        missing_version = get_deps_man_from_import_scope(
                                            main_pom_file, depm_fname,
                                            poms_base_dir, key, value, logf)

                                        if missing_version:
                                            libB_split = libB[key].split(":")
                                            libB[key] = libB_split[
                                                0] + ":" + libB_split[
                                                    1] + ":" + missing_version  #  find missing version
                                            del_version_idx.append(key)
                                            version_found = True

                                if version_found:
                                    break
                        if version_found:
                            break
                if version_found:
                    break

    if len(del_version_idx) > 0:
        for i in range(len(del_version_idx)):
            del versionMissing[del_version_idx[i]]
    del del_version_idx

    if has_parent:
        # Recursively checking parents
        get_dependencies_from_pom(main_pom_file, parent_info.get_path(),
                                  poms_base_dir, libA, libB, versionMissing,
                                  logf)

    return
예제 #2
0
class ControlSurfaceComponent(ControlManager, Subject):
    """
    Base class for all classes encapsulating functions in Live
    """
    name = ''
    canonical_parent = None
    is_private = False
    _show_msg_callback = dependency(show_message=None)
    _has_task_group = False
    _layer = None

    @depends(register_component=None, song=None)
    def __init__(self,
                 name='',
                 register_component=None,
                 song=None,
                 layer=None,
                 is_enabled=True,
                 *a,
                 **k):
        if not callable(register_component):
            raise AssertionError
            super(ControlSurfaceComponent, self).__init__(*a, **k)
            self.name = name
            raise layer is None or not is_enabled or AssertionError
            self._explicit_is_enabled = is_enabled
            self._recursive_is_enabled = True
            self._is_enabled = self._explicit_is_enabled
            self._allow_updates = True
            self._update_requests = 0
            self._song = song
            self._layer = layer is not None and layer
        register_component(self)

    def disconnect(self):
        if self._has_task_group:
            self._tasks.kill()
            self._tasks.clear()
        super(ControlSurfaceComponent, self).disconnect()

    def _internal_on_enabled_changed(self):
        if self._layer:
            if self.is_enabled():
                grabbed = self._layer.grab(self)
                if not grabbed:
                    raise AssertionError, 'Only one component can use a layer at atime'
                else:
                    self._layer.release(self)
            if self._has_task_group:
                self.is_enabled() and self._tasks.resume()
            else:
                self._tasks.pause()

    def on_enabled_changed(self):
        self.update()

    def update_all(self):
        self.update()

    def set_enabled(self, enable):
        self._explicit_is_enabled = bool(enable)
        self._update_is_enabled()

    def _set_enabled_recursive(self, enable):
        self._recursive_is_enabled = bool(enable)
        self._update_is_enabled()

    def _update_is_enabled(self):
        if self._recursive_is_enabled:
            is_enabled = self._explicit_is_enabled
            self._is_enabled = is_enabled != self._is_enabled and is_enabled
            self._internal_on_enabled_changed()
            self.on_enabled_changed()

    def set_allow_update(self, allow_updates):
        allow = bool(allow_updates)
        if self._allow_updates != allow:
            self._allow_updates = allow
            if self._allow_updates and self._update_requests > 0:
                self._update_requests = 0
                self.update()

    def control_notifications_enabled(self):
        return self.is_enabled()

    def application(self):
        return Live.Application.get_application()

    def song(self):
        return self._song

    @lazy_attribute
    @depends(parent_task_group=None)
    def _tasks(self, parent_task_group=None):
        tasks = parent_task_group.add(Task.TaskGroup())
        if not self._is_enabled:
            tasks.pause()
        self._has_task_group = True
        return tasks

    def _get_layer(self):
        return self._layer

    def _set_layer(self, new_layer):
        if self._layer != new_layer:
            self._layer and self._layer.release(self)
        self._layer = new_layer
        if new_layer and self.is_enabled():
            grabbed = new_layer.grab(self)
            if not grabbed:
                raise AssertionError, 'Only one component can use a layer at atime'

    layer = property(_get_layer, _set_layer)

    def is_enabled(self, explicit=False):
        """
        Returns whether the component is enabled.
        If 'explicit' is True the parent state is ignored.
        """
        return self._is_enabled if not explicit else self._explicit_is_enabled

    def on_track_list_changed(self):
        """
        Called by the control surface if tracks are added/removed,
        to be overridden
        """
        pass

    def on_scene_list_changed(self):
        """
        Called by the control surface if scenes are added/removed, to
        be overridden
        """
        pass

    def on_selected_track_changed(self):
        """
        Called by the control surface when a track is selected, to be
        overridden
        """
        pass

    def on_selected_scene_changed(self):
        """
        Called by the control surface when a scene is selected, to be
        overridden
        """
        pass

    @depends(parent_task_group=None)
    def _register_timer_callback(self, callback, parent_task_group=None):
        """
        DEPRECATED. Use tasks instead
        """
        raise callable(callback) or AssertionError
        raise parent_task_group.find(callback) is None or AssertionError

        def wrapper(delta):
            callback()
            return Task.RUNNING

        parent_task_group.add(Task.FuncTask(wrapper, callback))

    @depends(parent_task_group=None)
    def _unregister_timer_callback(self, callback, parent_task_group=None):
        """
        DEPRECATED. Use tasks instead
        """
        raise callable(callback) or AssertionError
        task = parent_task_group.find(callback)
        raise task is not None or AssertionError
        parent_task_group.remove(task)
예제 #3
0
def get_deps_man_from_import_scope(main_pom_file, depm_fname, poms_base_dir,
                                   key, value, logf):

    depm_path = poms_base_dir + depm_fname

    try:
        depm_tree = parse(depm_path)
    except Exception as e:
        logf.write(
            str(e) +
            ", --  Pom file %s does not exist when looked by the main pom file through dependencymanagement section --> %s.\n"
            % (depm_path, main_pom_file))
        return

    # The main root to extract information
    depm_root = bs(depm_tree.toxml(), 'lxml')

    project_info = project(None, None, None)

    if depm_root.project.find_all('groupid', recursive=False):
        root_gid = depm_root.project.find_all('groupid', recursive=False)
        for rid in root_gid:
            project_info.set_groupId(rid.text)

    if depm_root.project.find_all('artifactid', recursive=False):
        root_aid = depm_root.project.find_all('artifactid', recursive=False)
        for rid in root_aid:
            project_info.set_artifactId(rid.text)

    if depm_root.project.find_all('version', recursive=False):
        root_vid = depm_root.project.find_all('version', recursive=False)
        for rid in root_vid:
            project_info.set_version(rid.text)

    # To keep parent information
    parent_info = parent(None, None, None, None)
    has_parent = False

    # if parent is not None:
    for p in depm_root.project.find_all('parent', recursive=False):
        if type(p) == bs4.element.Tag:
            has_parent = True
            parent_info.set_groupId(p.find('groupid').text)
            parent_info.set_artifactId(p.find('artifactid').text)
            parent_info.set_version(p.find('version').text)
            parent_info.set_path(parent_info.get_groupId() + "-" +
                                 parent_info.get_artifactId() + "-" +
                                 parent_info.get_version() + ".pom")

    # To handle if the project groupId and version not giving, then we use the parent groupId and version
    if project_info.get_groupId() is None:
        project_info.set_groupId(parent_info.get_groupId())
    if project_info.get_version() is None:
        project_info.set_version(parent_info.get_version())

    depm_with_import_list = []

    deps_manage = depm_root.project.find_all('dependencymanagement',
                                             recursive=False)
    if deps_manage:  # Check if has dependency management section
        for deps in deps_manage:  # deps = dependecies
            if type(deps) == bs4.element.Tag:
                for dep in deps:  # dep = dependency
                    if type(dep) == bs4.element.Tag:
                        for d in dep:
                            if type(d) == bs4.element.Tag:

                                depm = dependency(None, None, None, None)

                                if d.find('groupid'):
                                    depm.set_groupId(d.find('groupid').text)
                                if d.find('artifactid'):
                                    depm.set_artifactId(
                                        d.find('artifactid').text)
                                if d.find('version'):
                                    depm.set_version(d.find('version').text)
                                if d.find('scope'):
                                    depm.set_scope(d.find('scope').text)

                                if depm.get_groupId()[0] == "$":

                                    depm.set_groupId(
                                        resolve_groupId(
                                            depm_root, depm.get_groupId(),
                                            project_info.get_groupId(),
                                            parent_info.get_groupId()))

                                if depm.get_groupId(
                                ) == value['gid'] and depm.get_artifactId(
                                ) == value['aid'] and depm.get_version(
                                )[0] == '$' and depm.get_scope() != 'import':

                                    depm.set_version(
                                        resolve_version(
                                            depm_root, depm.get_version(),
                                            project_info.get_version(),
                                            parent_info.get_version()))

                                if depm.get_groupId(
                                ) == value['gid'] and depm.get_artifactId(
                                ) == value['aid'] and depm.get_scope(
                                ) != "import":

                                    return depm.get_version()

                                if depm.get_scope() == "import":

                                    if depm.get_version()[0] == '$':

                                        depm.set_version(
                                            resolve_version(
                                                depm_root, depm.get_version(),
                                                project_info.get_version(),
                                                parent_info.get_version()))

                                    depm_fname = depm.get_groupId(
                                    ) + "-" + depm.get_artifactId(
                                    ) + "-" + depm.get_version() + ".pom"
                                    depm_with_import_list.append(depm_fname)

    for iter_ in range(len(depm_with_import_list)):
        capture_ = get_deps_man_from_import_scope(main_pom_file,
                                                  depm_with_import_list[iter_],
                                                  poms_base_dir, key, value,
                                                  logf)
        if capture_ == None:
            continue
        else:
            return capture_

    if has_parent:
        return get_deps_man_from_import_scope(main_pom_file,
                                              parent_info.get_path(),
                                              poms_base_dir, key, value, logf)