Exemplo n.º 1
0
    def create_request(self, options):
        """This is a factory of Request objects.
        
        Creates a Request object with given options plus queue specific
        options. Should the options conflict the factory resolves
        the conflicts in the way that queue's options have precedence
        over given request options.

        options: list of tuple (name, value)
        """

        # Check if given options are allowed for this Queue object.
        allowed = self.get_allowed_options()
        LOG.debug("Allowed options: %s" % allowed)
        not_allowed = []
        for option, _ in options:
            if option not in allowed:
                not_allowed.append(option)
        if not_allowed:
            raise QueueError("Given request options are not allowed "
                             "for this Queue: %s" % ", ".join(not_allowed))

        # TODO: create effective options as intersection between
        #       'options' and self.options
        user_options = [(100, name, value) for name, value in options]
        request_options = [(o.priority, o.name, o.value) for o in self.options]
        request_options.extend(user_options)
        request_options.sort()
        request_options = tuple((o[1], o[2]) for o in request_options)

        request = Request(request_options)
        self.requests.append(request)
        Session.flush()
        return request
Exemplo n.º 2
0
    def index(self, id):
        """Shows overview for product
        """

        log.debug("ProductController.index action invoked")
        product = get_object_or_404(Product, id)
        c.product_id = product.id
        c.product_name = product.name

        stmt = Session.query(Component.project_id, 
                             func.count('*').label('comp_count')).\
                group_by(Component.project_id).subquery()

        c.projects = []
        # SELECT project.*,comp_count FROM project LEFT JOIN (subquery)...
        for project, count in Session.query(Project, stmt.c.comp_count).\
                       outerjoin((stmt, Project.id==stmt.c.project_id)).\
                       filter(Project.product_id == product.id).\
                       order_by(Project.name):
            if not count:
                count = 0
            c.projects.append({'name': project.name,
                               'id': project.id,
                               'comp_count': count})

        return render('/packages/product_overview.mako')
Exemplo n.º 3
0
    def index(self, id):

        component = get_object_or_404(Component, id)
        c.product_name = component.project.product.name
        c.project_id = component.project_id
        c.project_name = component.project.name
        c.product_id = component.project.product_id
        c.component_name = component.name
        c.component_id = id

        stmt = Session.query(Binary.source_id, 
                             func.count('*').label('bin_count')).\
                group_by(Binary.source_id).subquery()

        c.sources = []
        # SELECT source.*,bin_count FROM source LEFT JOIN (subquery)...
        for source, count in Session.query(Source, stmt.c.bin_count).\
                       outerjoin((stmt, Source.id==stmt.c.source_id)).\
                       filter(Source.component_id == component.id).\
                       order_by(Source.name):
            if not count:
                count = 0
            c.sources.append({'name': source.name,
                              'id': source.id,
                              'bin_count': count})

        return render('/packages/component_overview.mako')
Exemplo n.º 4
0
    def index(self, id):

        project = get_object_or_404(Project, id)
        c.product_name = project.product.name
        c.project_id = id
        c.project_name = project.name
        c.product_id = project.product_id

        stmt = Session.query(Source.component_id, 
                             func.count('*').label('src_count')).\
                group_by(Source.component_id).subquery()

        c.components = []
        # SELECT component.*,src_count FROM component LEFT JOIN (subquery)...
        for component, count in Session.query(Component, stmt.c.src_count).\
                       outerjoin((stmt, Component.id==stmt.c.component_id)).\
                       filter(Component.project_id == project.id).\
                       order_by(Component.name):
            if not count:
                count = 0
            c.components.append({'name': component.name,
                                 'id': component.id,
                                 'src_count': count})

        return render('/packages/project_overview.mako')
Exemplo n.º 5
0
 def __call__(self, environ, start_response):
     """Invoke the Controller"""
     # WSGIController.__call__ dispatches to the Controller method
     # the request is routed to. This routing information is
     # available in environ['pylons.routes_dict']
     try:
         return WSGIController.__call__(self, environ, start_response)
     finally:
         Session.remove()
Exemplo n.º 6
0
    def submit_edit(self, id):
        """Processes edited source
        """

        source = get_object_or_404(Source, id)
        Session.begin()
        source.name = self.form_result["name"]
        msg = "Source package <b>%s</b> has been updated" % source.name
        Session.commit()
        h.flash(msg)

        return redirect_to(controller="packages/source", action="index", id=id)
Exemplo n.º 7
0
    def submit_edit(self, id):
        """Processes edited product
        """

        product = get_object_or_404(Product, id)
        Session.begin()
        product.name = self.form_result['name']
        msg = "Product <b>%s</b> has been updated" % product.name
        Session.commit()
        h.flash(msg)

        return redirect_to(controller='packages/product', id=id)
Exemplo n.º 8
0
    def submit_binary(self, id):
        """Processes new submitted binary
        """

        source = get_object_or_404(Source, id)
        Session.begin()
        binary = Binary(self.form_result["name"])
        source.binaries.append(binary)
        msg = "A new binary <b>%s</b> has been added" % binary.name
        Session.commit()
        h.flash(msg)

        return redirect_to(controller="packages/source", action="index", id=id)
Exemplo n.º 9
0
    def submit_edit(self, id):
        """Processes edited binary
        """

        binary = get_object_or_404(Binary, id)
        Session.begin()
        binary.name = self.form_result['name']
        msg = "Binary package <b>%s</b> has been updated" % binary.name
        Session.commit()
        h.flash(msg)

        return redirect_to(controller='packages/binary',
                           action='index',
                           id=id)
Exemplo n.º 10
0
    def submit_edit(self, id):
        """Processes edited component
        """

        component = get_object_or_404(Component, id)
        Session.begin()
        component.name = self.form_result['name']
        component.description = self.form_result['description']
        msg = "Component <b>%s</b> has been updated" % component.name
        Session.commit()
        h.flash(msg)

        return redirect_to(controller='packages/component',
                           action='index',
                           id=id)
Exemplo n.º 11
0
    def submit_source(self, id):
        """Processes new submitted source
        """

        component = get_object_or_404(Component, id)
        Session.begin()
        source = Source(self.form_result['name'])
        component.sources.append(source)
        msg = "A new source <b>%s</b> has been added" % source.name
        Session.commit()
        h.flash(msg)

        return redirect_to(controller='packages/component', 
                           action='index',
                           id=id)
Exemplo n.º 12
0
    def submit_project(self, id):
        """Processes new submitted project
        """
        
        product = get_object_or_404(Product, id)
        Session.begin()
        project = Project(self.form_result['name'])
        product.projects.append(project)
        msg = "A new project <b>%s</b> has been added" % project.name
        Session.commit()
        h.flash(msg)

        return redirect_to(controller='packages/product', 
                           action='index',
                           id=id)
Exemplo n.º 13
0
    def test_index(self):

        # look up for object ID
        component = Session.query(Component).first()
        response = self.app.get(url(controller='packages/component',
                                        action='index',
                                        id=component.id))
Exemplo n.º 14
0
    def walktree(self, depth = 0, root = 'source'):
        """Recursion function to walk over the acrhitectural tree"""

        # our hierachy
        chain = ('product', 'project', 'component', 'source', 'binary')
        # plural forms
        chains = ('products', 'projects', 'components', 'sources', 'binaries', 
                  'stop')
        # agregation hierachy
        chainclass = (Product, Project, Component, Source, Binary)
        response = self.app.get(url(controller = 'packages/architecture',
                                        action = 'get_architecture_nodes'),
                                params = {'root': root})
        nodes = simplejson.loads(response.body)
        assert len(nodes) == 3, "AJAX returned wrong number of nodes"
        for node in nodes:
            assert node['classes'] == chain[depth] + 'item', \
                    "Wrong class of item"
            itemtype, id = node['id'].split('_')
            assert itemtype == chain[depth], \
                    "Wrong type of item"
            db_node = Session.query(chainclass[depth]).filter_by(id = id).one()
            if chains[depth + 1] != 'stop':
                subnodes = getattr(db_node, chains[depth + 1])
                if len(subnodes) > 0:
                    assert node['hasChildren'], "Wring hasChildren attribute"
                    self.walktree(depth + 1, node['id'])
                else:
                     assert not node['hasChildren'], \
                             "Wring hasChildren attribute"
            else:
                assert not node['hasChildren'], \
                        "Leaf node must not have children"
Exemplo n.º 15
0
    def submit_component(self, id):
        """Processes new submitted component
        """

        project = get_object_or_404(Project, id)
        Session.begin()
        component = Component(self.form_result['name'])
        component.description = self.form_result['description']
        project.components.append(component)
        msg = "A new component <b>%s</b> has been added" % component.name
        Session.commit()
        h.flash(msg)

        return redirect_to(controller='packages/project', 
                           action='index',
                           id=id)
Exemplo n.º 16
0
    def test_index(self):
        """ Test ProductController.index action
        """

        # look up for object ID
        product = Session.query(Product).first()
        response = self.app.get(url(controller='packages/product',
                                        action='index',
                                        id=product.id))
        # Test response...
        assert response.status == 200, "Wrong response code"

        # get 404 if no ID provided
        response = self.app.get(url(controller='packages/product',
                                        action='index',
                                        id=""),
                               status=404)
        # Test response...
        assert response.status == 404, "Wrong response code"

        # get 404 if malformed ID provided
        response = self.app.get(url(controller='packages/product',
                                        action='index',
                                        id="bla-bla..."),
                               status=404)
        # Test response...
        assert response.status == 404, "Wrong response code"

        # get 404 if provided ID doesn't exist
        response = self.app.get(url(controller='packages/product',
                                        action='index',
                                        id=30000),
                               status=404)
        # Test response...
        assert response.status == 404, "Wrong response code"
Exemplo n.º 17
0
    def test_index(self):

        # look up for object ID
        project = Session.query(Project).first()
        response = self.app.get(url(controller='packages/project',
                                        action='index',
                                        id=project.id))
Exemplo n.º 18
0
def setUpModule():

    # add all the needed objects in DB
    Session.begin()
    product = Product("product1")
    product_to_edit = Product("product_to_edit")
    product_to_delete = Product("product_to_delete")
    project1 = Project("project1")
    project2 = Project("project2")
    component = Component("component1")
    project1.components.append(component)
    product.projects.append(project1)
    product.projects.append(project2)
    Session.add(product)
    Session.add(product_to_edit)
    Session.add(product_to_delete)
    Session.commit()
Exemplo n.º 19
0
def tearDownModule():
    connection = Session.connection()
    products = Product.__table__
    projects = Project.__table__
    components = Component.__table__
    connection.execute(components.delete())
    connection.execute(projects.delete())
    connection.execute(products.delete())
Exemplo n.º 20
0
    def delete(self, id):
        """Deletes a selected project.
        """
        #TODO: check permisssions

        project = get_object_or_404(Project, id)

        comp_count = Session.query(Component).filter_by(project_id = id).count()
        if comp_count > 0:
            h.flash("Can't delete the project %s as it still \
                     contains components." % project.name)
            return redirect_to(controller='packages/product',
                               action='index',
                               id=project.product_id)

        name = project.name
        Session.begin()
        Session.delete(project)
        Session.commit()
        h.flash("The project <b>%s</b> has been deleted successfully" % \
                name)

        return redirect_to(controller='packages/product',
                           action='index',
                           id=project.product_id)
Exemplo n.º 21
0
    def get_tasks(self):
        """Return tasks created for Request instance.
        
        If tasks have not been created then process options
        with registered option handlers which create tasks
        according to provided options.
        """

        if self.tasks:
            return self.tasks

        generator = TaskGenerator()
        for opt, value in self.options:
            generator.process(opt, value)
        Session.begin()
        self.tasks = generator.out()
        Session.commit()
        return self.tasks
Exemplo n.º 22
0
    def test_add_project(self):
        """ Test ProductController.add_project action
        """

        product = Session.query(Product).filter_by(name='product1').first()
        response = self.app.get(url(controller='packages/product',
                                        action='add_project',
                                        id=product.id))
        # Test response...
        assert response.status == 200, "Wrong response code"
Exemplo n.º 23
0
    def test_edit(self):
        """ Test ProductController.edit action
        """

        # look up for object ID
        product = Session.query(Product).first()
        response = self.app.get(url(controller='packages/product',
                                        action='edit',
                                        id=product.id))
        # Test response...
        assert response.status == 200, "Wrong response code"
Exemplo n.º 24
0
 def tearDown(self):
     connection = Session.connection()
     products = Product.__table__
     projects = Project.__table__
     components = Component.__table__
     sources = Source.__table__
     binaries = Binary.__table__
     connection.execute(binaries.delete())
     connection.execute(sources.delete())
     connection.execute(components.delete())
     connection.execute(projects.delete())
     connection.execute(products.delete())
Exemplo n.º 25
0
 def setUp(self):
     # TODO: this setup is better to move to common fixture
     Session.begin()
     for i in range(1, self.node_num + 1):
         product = Product("product%s" % i)
         for j in range(1, self.node_num + 1):
             if i == 2: # product without projects
                 continue
             project = Project("project%s.%s" % (i, j))
             for k in range(1, self.node_num + 1):
                 if j == 2: # project without components
                     continue
                 component = Component("component%s.%s.%s" % (i, j, k))
                 for l in range(1, self.node_num + 1):
                     if k == 2: # component without sources
                         continue
                     source = Source("source%s.%s.%s.%s" % (i, j, k, l))
                     for m in range(1, self.node_num + 1):
                         if l == 2: # source without binaries
                             continue
                         binary = Binary("binary%s.%s.%s.%s.%s" %
                                         (i, j, k, l, m))
                         source.binaries.append(binary)
                     component.sources.append(source)
                 project.components.append(component)
             product.projects.append(project)
         Session.add(product)
     Session.commit()
Exemplo n.º 26
0
    def test_submit_project(self):
        """ Test ProductController.submit_project action
        """

        product = Session.query(Product).filter_by(name='product1').first()
        product_id = product.id
        response = self.app.post(url(controller='packages/product',
                                         action='submit_project',
                                         id=product_id),
                                 params={
                                    'name': 'project333'
                                 })
        # Test response...
        assert response.status == 302, "Wrong response code"
        assert response.header_dict['location'] == \
                url(host='localhost',
                        controller='packages/product',
                        action='index',
                        id=product_id), "Wrong response location"

        project = Session.query(Project).filter_by(name='project333').first()
        assert project.product_id == product_id, \
                                 "New project assigned to wrong product"
Exemplo n.º 27
0
 def setUp(self):
     Session.begin()
     queue = Queue('testqueue')
     queueoption1 = QueueOption('check', '+helloworld', 100)
     queue.allowed_options = "check, build-deb-package"
     queue.options.append(queueoption1)
     Session.add(queue)
     Session.commit()
     self.queue = queue
Exemplo n.º 28
0
def get_object_or_404(class_, id):
    """Gets model object from DB if available or shows 404 page.
    """

    if not id:
        abort(404)

    try:
        id = int(id)
    except ValueError:
        abort(404)

    object = Session.query(class_).filter_by(id = id).first()
    if object is None:
        abort(404)
    return object
Exemplo n.º 29
0
def setUpModule():

    # add all the needed objects in DB
    Session.begin()
    product = Product("product1")
    project = Project("project1")
    component = Component("component1")
    project.components.append(component)
    product.projects.append(project)
    Session.add(product)
    Session.commit()
Exemplo n.º 30
0
    def run(self):

        # look for root tasks
        #
        # SELECT task.id, count(ta.parent_task_id) AS parent_count 
        # FROM task 
        # LEFT OUTER JOIN task_association ta ON task.id=ta.child_task_id
        # WHERE request_id = %d
        # GROUP BY task.id
        # HAVING count(ta.parent_task_id) = 0
        roottasks = Session.query(Task).filter(Task.request_id==self.id).\
                outerjoin((task_association_table,
                          Task.id==task_association_table.c.child_task_id)).\
                group_by(Task).\
                having(func.count(task_association_table.c.parent_task_id)==0)
        for roottask in roottasks:
            roottask.run()