コード例 #1
0
ファイル: component.py プロジェクト: rojkov/pacemaker
    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')
コード例 #2
0
ファイル: product.py プロジェクト: rojkov/pacemaker
    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')
コード例 #3
0
ファイル: project.py プロジェクト: rojkov/pacemaker
    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')
コード例 #4
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))
コード例 #5
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))
コード例 #6
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"
コード例 #7
0
ファイル: project.py プロジェクト: rojkov/pacemaker
    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)
コード例 #8
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"
コード例 #9
0
    def test_delete(self):
        """ Test ProductController.delete action
        """

        product = Session.query(Product).\
                filter_by(name='product_to_delete').first()
        product_id = product.id
        response = self.app.post(url(controller='packages/product',
                                         action='delete',
                                         id=product_id))
        # Test response...
        assert response.status == 302, "Wrong response code"
        print "Location: ", response.header_dict['location']
        print "Expected location: ", url(controller='packages/packages', host='localhost'), \
                    "Wrong response location"
        assert response.header_dict['location'] == \
                url(controller='packages/packages', host='localhost'), \
                    "Wrong response location"
        # reset sqlalchemy cache
        Session.begin()
        Session.commit()
        count = Session.query(Product).\
                filter_by(name='product_to_delete').count()
        assert count == 0, "Product hasn't been deleted"

        # Try to delete product which has children
        product = Session.query(Product).\
                filter_by(name='product1').first()
        product_id = product.id
        response = self.app.post(url(controller='packages/product',
                                         action='delete',
                                         id=product_id))
        # Test response...
        assert response.status == 302, "Wrong response code"
        assert response.header_dict['location'] == \
                url(controller='packages/product',
                        host='localhost',
                        id=product_id), \
                    "Wrong response location"
        # reset sqlalchemy cache
        Session.begin()
        Session.commit()
        count = Session.query(Product).\
                filter_by(name='product1').count()
        assert count == 1, "Product has been deleted"
コード例 #10
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"
コード例 #11
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"
コード例 #12
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"
コード例 #13
0
 def test_submit_edit(self):
     """ Test ProductController.submit_edit action
     """
     product = Session.query(Product).\
             filter_by(name='product_to_edit').first()
     product_id = product.id
     response = self.app.post(url(controller='packages/product',
                                      action='submit_edit',
                                      id=product_id),
                              params={
                                 'name': 'product_new_name'
                              })
     # Test response...
     assert response.status == 302, "Wrong response code"
     assert response.header_dict['location'] == \
             url(controller='packages/product',
                     host='localhost',
                     id=product_id), \
                 "Wrong response location"
     # reset sqlalchemy cache
     Session.begin()
     Session.commit()
     product_n = Session.query(Product).filter_by(id=product_id).first()
     assert product_n.name == 'product_new_name', "Wrong product name"
コード例 #14
0
ファイル: base.py プロジェクト: rojkov/pacemaker
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
コード例 #15
0
ファイル: __init__.py プロジェクト: rojkov/pacemaker
    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()
コード例 #16
0
ファイル: source.py プロジェクト: rojkov/pacemaker
    def index(self, id):

        source = get_object_or_404(Source, id)
        c.product_name = source.component.project.product.name
        c.project_id = source.component.project_id
        c.project_name = source.component.project.name
        c.product_id = source.component.project.product_id
        c.component_name = source.component.name
        c.component_id = source.component_id
        c.source_name = source.name
        c.source_id = id

        c.binaries = []
        for binary in Session.query(Binary).filter(Binary.source_id == id).order_by(Binary.name):
            c.binaries.append({"name": binary.name, "id": binary.id})

        return render("/packages/source_overview.mako")
コード例 #17
0
ファイル: source.py プロジェクト: rojkov/pacemaker
    def delete(self, id):
        """Deletes a selected source.
        """
        # TODO: check permisssions

        source = get_object_or_404(Source, id)

        bin_count = Session.query(Binary).filter_by(source_id=id).count()
        if bin_count > 0:
            h.flash(
                "Can't delete the source %s as it still \
                     contains binaries."
                % source.name
            )
            return redirect_to(controller="packages/component", action="index", id=source.component_id)

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

        return redirect_to(controller="packages/component", action="index", id=source.component_id)
コード例 #18
0
ファイル: architecture.py プロジェクト: rojkov/pacemaker
def get_nodes(root, openitems):
    """ Gets nodes recursively
    """

    log.debug("root - %s\n %s" % (root, openitems))
    chain = ['product', 'project', 'component', 'source', 'binary']
    classes = (Product, Project, Component, Source, Binary)
    if root == 'source':
        depth = 0
    else:
        obj_type, obj_id = root.split('_')
        depth = chain.index(obj_type) + 1

    # subquery doesn't make sense for leaf elements like binaries
    if depth < len(classes) - 1:
        # subquery statement (i.e. product ids with counts of projects)
        # SELECT product_id, count(*) FROM project GROUP BY product_id
        stmt = Session.query(getattr(classes[depth+1], chain[depth] + '_id'),
                             func.count('*').label('obj_count')).\
                group_by(getattr(classes[depth+1], chain[depth] + '_id')).\
                subquery()
    # not root and not leaves
    if root != 'source' and depth < len(classes) - 1:
        # SELECT project.*,comp_count FROM project LEFT JOIN (subquery)...
        objects = Session.query(classes[depth], stmt.c.obj_count).\
                                outerjoin((stmt, classes[depth].id==\
                                    getattr(stmt.c, chain[depth] + '_id'))).\
                                filter(getattr(classes[depth], 
                                               obj_type + '_id') == obj_id).\
                                order_by(classes[depth].name)
    # leaves
    elif depth == len(classes) - 1:
        objects = Session.query(classes[depth]).filter_by(source_id=obj_id)
        objects = [(obj, 0) for obj in objects]
    # root
    else:
        objects = Session.query(classes[depth], stmt.c.obj_count).\
                                outerjoin((stmt, classes[depth].id==\
                                         getattr(stmt.c, 
                                                 chain[depth] + '_id'))).\
                                order_by(classes[depth].name)
    result = []
    for object, count in objects:
        if count > 0:
            text = "%s (%d)" % (object.name, count)
        else:
            text = "%s" % (object.name, )
        item_id = "%s_%s" % (chain[depth], object.id)
        item = dict(text = text,
                    href = url(controller='packages/' + chain[depth],
                                     action='index',
                                     id=object.id),
                    classes = "%sitem" % chain[depth],
                    id = item_id)
        if item_id in openitems:
            openitems.remove(item_id)
            item['children'] = get_nodes(item_id, openitems)
            item['expanded'] = True
        else:
            item['hasChildren'] = (count > 0)
        result.append(item)
    return result
コード例 #19
0
 def test_index(self):
     # look up for object ID
     source = Session.query(Source).first()
     response = self.app.get(url(controller='packages/source',
                                     action='index',
                                     id=source.id))
コード例 #20
0
 def test_index(self):
     # look up for object ID
     binary = Session.query(Binary).first()
     response = self.app.get(url(controller='packages/binary', 
                                     action='index',
                                     id=binary.id))