Beispiel #1
0
 def _consume_section(self):
     keyword = self.params['section']
     if keyword:
         keyword = re.escape(keyword).replace("\\", "\\\\")
         if self.binary_search():
             self.helper.push_triple(\
                 Variable("binary"), DEB.section, Variable("section"))
         elif self.source_search():
             self.helper.push_triple(\
                 Variable("source"), DEB.section, Variable("section"))
         else:
             raise Exception()  # FIXME
         self.helper.push_triple_variables(\
              Variable("section"), DEB.sectionName, Variable("sectionname"))
         self.helper.add_or_filter_regex({Variable("sectionname"): keyword})
     else:
         self.helper.add_variable("section")
         self.helper.add_variable("sectionname")
         if self.binary_search():
             triple1 = Triple(\
                  Variable("binary"), DEB.section, Variable("section"))
         elif self.source_search():
             triple1 = Triple(\
                  Variable("source"), DEB.section, Variable("section"))
         else:
             raise Exception()  # FIXME
         triple2 = Triple(\
              Variable("section"), DEB.sectionName, Variable("sectionname"))
         self.helper.add_optional(triple1, triple2)
Beispiel #2
0
 def test__consume_vcs_several(self):
     self.builder.params['vcs'] = ["SVN", "GIT"]
     mock = self.mox.CreateMock(SelectQueryHelper)
     mock.push_triple(Variable("source"), DEB.repository,
                      Variable("repobnode"))
     triple1 = Triple(Variable("repobnode"), RDF.type, DOAP.SVNRepository)
     triple2 = Triple(Variable("repobnode"), RDF.type, DOAP.GitRepository)
     mock.add_union([triple1], [triple2])
     self.builder.helper = mock
     self.mox.ReplayAll()
     self.builder._consume_vcs()
     self.mox.VerifyAll()
Beispiel #3
0
 def test_add_union(self):
     st1 = Triple(Variable("a"), Variable("b"), Variable("c"))
     st2 = Triple(Variable("d"), Variable("e"), Variable("f"))
     gp1 = [st1, st2]
     gp2 = [st1]
     self.s.add_union(gp1, gp2)
     self.assertEqual(1, len(self.s.query.whereclause.stmts))
     self.assertEqual(2,
                      len(self.s.query.whereclause.stmts[0].graphpatterns))
     self.assertEqual(
         2, len(self.s.query.whereclause.stmts[0].graphpatterns[0]))
     self.assertEqual(
         1, len(self.s.query.whereclause.stmts[0].graphpatterns[1]))
     self.assertRaises(Exception, self.s.add_union, gp1)
Beispiel #4
0
 def setUp(self):
     self.s = SelectQueryHelper()
     self.triple1 = Triple()
     self.triple1.subject = Variable("var1")
     self.triple1.property = RDFS.type
     self.triple1.object = DEB.Source
     self.triple2 = Triple()
     self.triple2.subject = Variable("var2")
     self.triple2.property = RDFS.type
     self.triple2.object = DEB.Binary
     self.triple3 = Triple()
     self.triple3.subject = Variable("var3")
     self.triple3.property = RDFS.type
     self.triple3.object = Variable("var4")
Beispiel #5
0
 def test__consume_homepage_true(self):
     self.builder.params['homepage'] = True
     mock = self.mox.CreateMock(SelectQueryHelper)
     mock.add_variable(Variable("homepage"))
     triple = Triple(\
         Variable("source"), FOAF.page, Variable("homepage"))
     mock.add_optional(triple)
     self.builder.helper = mock
     self.mox.ReplayAll()
     self.builder._consume_homepage()
     self.mox.VerifyAll()
Beispiel #6
0
 def test__consume_vcs_one(self):
     self.builder.params['vcs'] = ["SVN"]
     mock = self.mox.CreateMock(SelectQueryHelper)
     mock.push_triple(Variable("source"), DEB.repository,
                      Variable("repobnode"))
     triple = Triple(Variable("repobnode"), RDF.type, DOAP.SVNRepository)
     mock.add_triple(triple)
     self.builder.helper = mock
     self.mox.ReplayAll()
     self.builder._consume_vcs()
     self.mox.VerifyAll()
Beispiel #7
0
 def test__consume_priority_binary_any(self):
     self.mock_binary_search()
     self.builder.params['priority'] = "ANY"
     mock = self.mox.CreateMock(SelectQueryHelper)
     mock.add_variable("priority")
     triple = Triple(Variable("binary"), DEB.priority, Variable("priority"))
     mock.add_optional(triple)
     self.builder.helper = mock
     self.mox.ReplayAll()
     self.builder._consume_priority()
     self.mox.VerifyAll()
Beispiel #8
0
    def _consume_popcon(self):
        if self.binary_search() and self.params['popcon']:
            triple = Triple(Variable("unversionedbinary"), \
                            DEB.popconInstalled, Variable("?popconinstalled"))
            self.helper.add_variable("popconinstalled")
            self.helper.add_optional(triple)

            triple = Triple(Variable("unversionedbinary"), \
                            DEB.popconUsedRegularly, Variable("?popconused"))
            self.helper.add_variable("popconused")
            self.helper.add_optional(triple)

            triple = Triple(Variable("unversionedbinary"), \
                            DEB.popconInstalledButNotInUse, Variable("?popconnotinuse"))
            self.helper.add_variable("popconnotinuse")
            self.helper.add_optional(triple)

            triple = Triple(Variable("unversionedbinary"), \
                            DEB.popconUpgradedRecently, Variable("?popconupgraded"))
            self.helper.add_variable("popconupgraded")
            self.helper.add_optional(triple)
Beispiel #9
0
 def _consume_priority(self):
     option = self.params['priority']
     if option == 'ANY':
         self.helper.add_variable("priority")
         if self.binary_search():
             triple = Triple(\
                 Variable("binary"), DEB.priority, Variable("priority"))
         elif self.source_search():
             triple = Triple(\
                 Variable("source"), DEB.priority, Variable("priority"))
         else:
             raise Exception()  # FIXME
         self.helper.add_optional(triple)
     else:
         if self.binary_search():
             self.helper.push_triple(\
                 Variable("binary"), DEB.priority, URIRef(option))
         elif self.source_search():
             self.helper.push_triple(\
                 Variable("source"), DEB.priority, URIRef(option))
         else:
             raise Exception()  # FIXME
Beispiel #10
0
    def _consume_vcs(self):
        options = self.params['vcs']
        if options:
            self.helper.push_triple(\
                Variable("source"), DEB.repository, Variable("repobnode"))
            graphpatterns = []
            if 'SVN' in options:
                graphpatterns.append(\
                    [Triple(Variable("repobnode"), RDF.type, DOAP.SVNRepository)])
            if 'GIT' in options:
                graphpatterns.append(\
                    [Triple(Variable("repobnode"), RDF.type, DOAP.GitRepository)])
            if 'CVS' in options:
                graphpatterns.append(\
                    [Triple(Variable("repobnode"), RDF.type, DOAP.CVSRepository)])
            if 'HG' in options:
                graphpatterns.append(\
                    [Triple(Variable("repobnode"), RDF.type, DOAP.HgRepository)])

            if len(graphpatterns) == 1:
                self.helper.add_triple(graphpatterns[0][0])
            else:
                self.helper.add_union(*graphpatterns)
Beispiel #11
0
 def _consume_comaintainer(self):
     option = self.params['comaintainer']
     if option == 'WITH':
         self.helper.push_triple(\
             Variable("source"), DEB.uploader, Variable("uploader"))
     elif option == 'WITHOUT':
         triple = Triple(\
             Variable("source"), DEB.uploader, Variable("uploader"))
         self.helper.add_optional(triple)
         self.helper.add_filter_notbound(Variable("uploader"))
     elif option == 'ALL':
         pass
     else:
         raise SPARQLQueryBuilderUnexpectedFieldValueError("comaintainer")
Beispiel #12
0
 def _consume_version(self):
     options = self.params['version']
     if 'NATIVE' in options or 'NMU' in options:
         triple = Triple(\
             Variable("sourceversion"), DEB.debianRevision, Variable("debianRevision"))
         self.helper.add_optional(triple)
     if 'NATIVE' in options:
         self.helper.add_filter_notbound(Variable("debianRevision"))
     if 'NMU' in options:
         self.helper.push_triple(\
             Variable("sourceversion"), DEB.upstreamVersion, Variable("upstreamVersion"))
         restrictions = {Variable("debianRevision"): ".*\\\..*",\
                         Variable("upstreamVersion"): ".*\\\+nmu.*"}
         self.helper.add_or_filter_regex(restrictions)
     if 'EPOCH' in options:
         self.helper.push_triple(Variable("sourceversion"), DEB.epoch,
                                 Variable("epoch"))
Beispiel #13
0
 def test_add_triple_variables(self):
     st1 = Triple(Variable("a"), Variable("b"), Variable("c"))
     self.s.add_triple_variables(st1)
     self.assertEqual(3, len(self.s.query.variables))
Beispiel #14
0
 def _consume_homepage(self):
     if self.params['homepage']:
         self.helper.add_variable("homepage")
         triple = Triple(\
              Variable("source"), FOAF.page, Variable("homepage"))
         self.helper.add_optional(triple)