1
2
3
4
5
6 import os
7 import glob
8
9 from moap.util import log
10
12 """
13 @type args: 1-tuple of str
14 """
15
17 """
18 Try to find a .doap file in the given path.
19
20 path can be None (for current directory), a .doap file, or a directory.
21
22 @rtype: L{Doap}
23 """
24 if not path:
25 path = os.getcwd()
26
27 if not os.path.exists(path):
28 raise DoapException('Path %s does not exist.\n' % path)
29
30 if not path.endswith('.doap'):
31 cands = glob.glob(os.path.join(path, '*.doap'))
32 if not cands:
33 raise DoapException('No .doap file found in %s.\n' % path)
34
35 if len(cands) > 1:
36 raise DoapException('More than one doap file in %s.\n' \
37 'Please specify one.\n' % path)
38
39 path = cands[0]
40
41 d = Doap()
42 d.addFile(path)
43
44 return d
45
46 -class Doap(log.Loggable):
47 logCategory = "doap"
48 """
49 I abstract a DOAP file.
50 """
58
60 if not os.path.exists(file):
61 raise KeyError
62
63 self.path = file
64 location = "file:%s" % file
65 self.debug('adding location %s' % location)
66 self._querier.addLocation(location)
67
69 if not self._project:
70 self.debug('Querying project')
71
72
73 querystring = """
74 PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
75 PREFIX doap: <http://usefulinc.com/ns/doap#>
76 PREFIX foaf: <http://xmlns.com/foaf/0.1/>
77 SELECT ?name, ?shortname, $description, ?shortdesc,
78 ?homepage, ?bug, ?download, ?wiki, ?created
79 WHERE {
80 ?project rdf:type doap:Project .
81 ?project doap:homepage ?homepage .
82 ?project doap:name ?name .
83 OPTIONAL { ?project doap:shortname ?shortname }
84 OPTIONAL { ?project doap:description $description }
85 OPTIONAL { ?project doap:shortdesc ?shortdesc }
86 OPTIONAL { ?project doap:created ?created }
87 OPTIONAL { ?project doap:bug-database ?bug }
88 OPTIONAL { ?project doap:download-page ?download }
89 OPTIONAL { ?project doap:wiki ?wiki }
90 }
91 """
92 result = self._querier.query(querystring, query_language='sparql')
93 assert len(result) == 1, \
94 "Length of result is %d instead of 1" % len(result)
95
96 for r in result: pass
97 self.log('Query result: %r' % r)
98
99 p = Project()
100
101
102 p.homepage = stringifyNode(r['homepage'])
103
104 p.name = str(r['name'])
105 self.debug('Found Project named %s' % p.name)
106
107
108 if r['shortname']:
109 p.shortname = str(r['shortname'])
110 if r['description']:
111 p.description = r['description'].literal_value['string']
112 if r['shortdesc']:
113 p.shortdesc = r['shortdesc'].literal_value['string'].strip()
114 if r['created']:
115 p.created = str(r['created'])
116 if r['bug']:
117 p.bug_database = stringifyNode(r['bug'])
118 if r['download']:
119 p.download_page = stringifyNode(r['download'])
120 if r['wiki']:
121 p.wiki = stringifyNode(r['wiki'])
122
123 self._project = p
124
125 self._queryReleases(p)
126
127 return self._project
128
130
131
132 querystring = """
133 PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
134 PREFIX dc: <http://purl.org/dc/elements/1.1/>
135 PREFIX doap: <http://usefulinc.com/ns/doap#>
136 PREFIX foaf: <http://xmlns.com/foaf/0.1/>
137 SELECT ?projectId, ?name, ?branch, ?revision, ?created, ?description
138 WHERE {
139 ?project rdf:type doap:Project .
140 ?project doap:shortname ?projectId .
141 ?project doap:release ?release .
142 ?release doap:name ?name .
143 ?release doap:branch ?branch .
144 ?release doap:revision ?revision .
145 ?release doap:created ?created
146 OPTIONAL { ?release dc:description ?description }
147 }
148 ORDER BY DESC(?created)
149 """
150 result = self._querier.query(querystring, query_language='sparql')
151 for r in result:
152 projectId = str(r['projectId'])
153 if projectId != p.shortname:
154 continue
155
156 v = Version()
157 v.name = str(r['name'])
158 v.revision = str(r['revision'])
159 self.debug('Found Version with revision %s' % v.revision)
160 v.branch = str(r['branch'])
161 if r['description']:
162 v.description = str(r['description'])
163 if r.has_key('created'):
164 v.created = str(r['created'])
165 r = Release()
166 r.version = v
167 p.release.append(r)
168
169 self._queryFileReleases(p, v)
170
171
173
174 projectId = p.shortname
175 revision = v.revision
176 querystring = """
177 PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
178 PREFIX doap: <http://usefulinc.com/ns/doap#>
179 PREFIX foaf: <http://xmlns.com/foaf/0.1/>
180 SELECT ?fileRelease
181 WHERE {
182 ?project rdf:type doap:Project .
183 ?project doap:shortname "%(projectId)s" .
184 ?project doap:release ?release .
185 ?release doap:revision "%(revision)s" .
186 ?release doap:file-release ?fileRelease
187 }
188 """ % locals()
189
190 result = self._querier.query(querystring, query_language='sparql')
191 for r in result:
192 f = r['fileRelease']
193 uri = stringifyNode(f)
194 self.log('Found file-release %s' % uri)
195 v.file_release.append(uri)
196
226
229
231 """
232 @cvar file_release: list of file-release entries (FIXME)
233 """
234 revision = None
235 branch = None
236 name = None
237 created = None
238 description = None
239
241 self.file_release = []
242
244 return '<Version %s>' % self.revision
245
247 if node.is_resource():
248 return str(node.uri)
249 else:
250 return str(node)
251