|
a |
|
b/OSSEval/OpenSourceProject/doap.py |
|
|
1 |
# This Source Code Form of OSSEval is subject to the terms of the GNU AFFERO
|
|
|
2 |
# GENERAL PUBLIC LICENSE, v. 3.0. If a copy of the AGPL was not
|
|
|
3 |
# distributed with this file, You can obtain one at http://www.gnu.org/licenses/agpl.txt
|
|
|
4 |
#
|
|
|
5 |
# OSSeval is powered by the SOS Open Source AGPL edition.
|
|
|
6 |
# The AGPL requires that you do not remove the SOS Open Source attribution and copyright
|
|
|
7 |
# notices from the user interface (see section 5.d below).
|
|
|
8 |
|
|
|
9 |
# OSSEval Copyright 2014 Bitergium SLL
|
|
|
10 |
# SOS Open Source Copyright 2012 Roberto Galoppini
|
|
|
11 |
# Author: Davide Galletti
|
|
|
12 |
|
|
|
13 |
|
|
|
14 |
|
|
|
15 |
from utils import Configuration, Forges
|
|
|
16 |
|
|
|
17 |
from django.db import connections
|
|
|
18 |
|
|
|
19 |
class Apache():
|
|
|
20 |
|
|
|
21 |
@staticmethod
|
|
|
22 |
def search(name):
|
|
|
23 |
project_list = []
|
|
|
24 |
cursor = connections['flossmole'].cursor()
|
|
|
25 |
parameters = { 'limit': Configuration.max_number_of_records }
|
|
|
26 |
cursor.execute("SELECT idDoap, Name, Shortdesc, Description, Homepage FROM apache_doap WHERE LOWER(name) LIKE '%%" + name.lower() + "%%' LIMIT %(limit)s", parameters)
|
|
|
27 |
results = cursor.fetchall()
|
|
|
28 |
for record in results:
|
|
|
29 |
fp = FlossmoleProject()
|
|
|
30 |
fp.id = record[0]
|
|
|
31 |
fp.id_forge = Forges.FSF
|
|
|
32 |
fp.datasource_id = record[1]
|
|
|
33 |
fp.name = record[2]
|
|
|
34 |
fp.description = record[3]
|
|
|
35 |
project_list.append(fp)
|
|
|
36 |
return project_list
|
|
|
37 |
|
|
|
38 |
@staticmethod
|
|
|
39 |
def getProjectInfo(project_identifier):
|
|
|
40 |
info = {}
|
|
|
41 |
cursor = connections['flossmole'].cursor()
|
|
|
42 |
cursor.execute("SELECT max(datasource_id) FROM fsf_projects")
|
|
|
43 |
row = cursor.fetchone()
|
|
|
44 |
datasource_id = row[0]
|
|
|
45 |
parameters = { 'datasource_id': datasource_id, 'project_identifier': project_identifier }
|
|
|
46 |
cursor.execute("SELECT proj_long_name, desc_long, url, real_url, released_on, proj_num FROM fsf_projects WHERE proj_unixname=%(project_identifier)s and datasource_id=%(datasource_id)s", parameters)
|
|
|
47 |
result = cursor.fetchone()
|
|
|
48 |
info['name'] = result[0]
|
|
|
49 |
info['desc_long'] = result[1]
|
|
|
50 |
info['url'] = result[2]
|
|
|
51 |
info['real_url'] = result[3]
|
|
|
52 |
info['released_on'] = result[4]
|
|
|
53 |
proj_num = result[5]
|
|
|
54 |
|
|
|
55 |
info['licenses'] = []
|
|
|
56 |
parameters = { 'datasource_id': datasource_id, 'proj_num': proj_num }
|
|
|
57 |
cursor.execute("SELECT license FROM fsf_project_licenses WHERE proj_num=%(proj_num)s and datasource_id=%(datasource_id)s", parameters)
|
|
|
58 |
results = cursor.fetchall()
|
|
|
59 |
for record in results:
|
|
|
60 |
info['licenses'].append(record[0])
|
|
|
61 |
|
|
|
62 |
info['developers'] = []
|
|
|
63 |
cursor.execute("SELECT person_name, role, email FROM fsf_developer_projects WHERE proj_num=%(proj_num)s and datasource_id=%(datasource_id)s", parameters)
|
|
|
64 |
results = cursor.fetchall()
|
|
|
65 |
for record in results:
|
|
|
66 |
developer = {}
|
|
|
67 |
developer['person_name'] = record[0]
|
|
|
68 |
developer['role'] = record[1]
|
|
|
69 |
developer['email'] = record[2]
|
|
|
70 |
info['developers'].append(developer)
|
|
|
71 |
|
|
|
72 |
info['categories'] = []
|
|
|
73 |
parameters = { 'datasource_id': datasource_id, 'proj_num': proj_num }
|
|
|
74 |
cursor.execute("SELECT project_category_title FROM fsf_project_categories WHERE proj_num=%(proj_num)s and datasource_id=%(datasource_id)s", parameters)
|
|
|
75 |
results = cursor.fetchall()
|
|
|
76 |
for record in results:
|
|
|
77 |
info['categories'].append(record[0])
|
|
|
78 |
|
|
|
79 |
info['requirements'] = []
|
|
|
80 |
cursor.execute("SELECT requirement, requirement_type FROM fsf_project_requirements WHERE proj_num=%(proj_num)s and datasource_id=%(datasource_id)s", parameters)
|
|
|
81 |
results = cursor.fetchall()
|
|
|
82 |
for record in results:
|
|
|
83 |
requirement = {}
|
|
|
84 |
requirement['requirement'] = record[0]
|
|
|
85 |
requirement['requirement_type'] = record[1]
|
|
|
86 |
info['requirements'].append(requirement)
|
|
|
87 |
|
|
|
88 |
return info
|
|
|
89 |
|
|
|
90 |
|
|
|
91 |
class FoafPerson:
|
|
|
92 |
def __init__(self, firstName, lastName, login = ""):
|
|
|
93 |
# see issue 867 for details: http://markosproject.berlios.de/mantis/view.php?id=867
|
|
|
94 |
# Apache data sometimes is wrongly encoded: 'utf8' codec can't decode byte 0xfc in position 9: invalid start byte
|
|
|
95 |
try:
|
|
|
96 |
foo = firstName.decode('utf-8')
|
|
|
97 |
self.firstName = firstName
|
|
|
98 |
except:
|
|
|
99 |
self.firstName = StringHelper.removeNonAscii(firstName)
|
|
|
100 |
self.lastName = lastName
|
|
|
101 |
self.login = login
|
|
|
102 |
|
|
|
103 |
class DoapVersion:
|
|
|
104 |
def __init__(self):
|
|
|
105 |
self.os = []
|
|
|
106 |
|
|
|
107 |
class DoapRepository:
|
|
|
108 |
def __init__(self, parent):
|
|
|
109 |
self.parent_id_doap = parent.idDoap
|
|
|
110 |
|
|
|
111 |
class DoapProject(object):
|
|
|
112 |
"""
|
|
|
113 |
Class with the information in the DOAP format
|
|
|
114 |
"""
|
|
|
115 |
def __init__(self):
|
|
|
116 |
self._idDoap = None
|
|
|
117 |
|
|
|
118 |
@property
|
|
|
119 |
def idDoap(self):
|
|
|
120 |
return self._idDoap
|
|
|
121 |
|
|
|
122 |
@idDoap.setter
|
|
|
123 |
def idDoap(self, value):
|
|
|
124 |
self._idDoap = value
|
|
|
125 |
if hasattr(self, "svn_repository") and (not (self.svn_repository is None)):
|
|
|
126 |
self.svn_repository.parent_id_doap = self._idDoap
|
|
|
127 |
if hasattr(self, "hg_repository") and (not (self.hg_repository is None)):
|
|
|
128 |
self.hg_repository.parent_id_doap = self._idDoap
|
|
|
129 |
if hasattr(self, "darcs_repository") and (not (self.darcs_repository is None)):
|
|
|
130 |
self.darcs_repository.parent_id_doap = self._idDoap
|
|
|
131 |
if hasattr(self, "bzr_repository") and (not (self.bzr_repository is None)):
|
|
|
132 |
self.bzr_repository.parent_id_doap = self._idDoap
|
|
|
133 |
if hasattr(self, "arch_repository") and (not (self.arch_repository is None)):
|
|
|
134 |
self.arch_repository.parent_id_doap = self._idDoap
|
|
|
135 |
if hasattr(self, "bk_repository") and (not (self.bk_repository is None)):
|
|
|
136 |
self.bk_repository.parent_id_doap = self._idDoap
|
|
|
137 |
if hasattr(self, "cvs_repository") and (not (self.cvs_repository is None)):
|
|
|
138 |
self.cvs_repository.parent_id_doap = self._idDoap
|
|
|
139 |
if hasattr(self, "git_repository") and (not (self.git_repository is None)):
|
|
|
140 |
self.git_repository.parent_id_doap = self._idDoap
|
|
|
141 |
|
|
|
142 |
|
|
|
143 |
def load_from_db(self, idDoap):
|
|
|
144 |
self.idDoap = idDoap
|
|
|
145 |
try:
|
|
|
146 |
# expression for modified, modified_release is due to a bug in mysqldb for BIT data type
|
|
|
147 |
cursor = CrawlerDatabase.execute_cursor("SELECT name, shortdesc, description, homepage, created, mailing_list, download_page, bug_database, platform, service_endpoint, audience, blog, IF(modified=1,1,0) as modified, old_homepage, category, license, download_mirror, wiki, programming_language, os, language, idDWBatch, idProject, IF(modified_release=1,1,0) as modified_release FROM Doap WHERE idDoap="+str(idDoap))
|
|
|
148 |
result = cursor.fetchone()
|
|
|
149 |
#for each project in the batch
|
|
|
150 |
if (result is None):
|
|
|
151 |
#throw
|
|
|
152 |
pass
|
|
|
153 |
else:
|
|
|
154 |
self.name = result[0]
|
|
|
155 |
self.shortdesc = result[1]
|
|
|
156 |
self.description = result[2]
|
|
|
157 |
self.homepage = result[3]
|
|
|
158 |
self.created = str(result[4])
|
|
|
159 |
self.mailing_list = result[5]
|
|
|
160 |
self.download_page = result[6]
|
|
|
161 |
self.bug_database = result[7]
|
|
|
162 |
self.platform = result[8]
|
|
|
163 |
self.service_endpoint = result[9]
|
|
|
164 |
self.audience = result[10]
|
|
|
165 |
self.blog = result[11]
|
|
|
166 |
self.modified = True if result[12] == b'\x00' else False
|
|
|
167 |
self.modified_release = True if result[23] == b'\x00' else False
|
|
|
168 |
self.old_homepage = StringList().load_base64(result[13]).plain
|
|
|
169 |
self.category = StringList().load_base64(result[14]).plain
|
|
|
170 |
self.license = StringList().load_base64(result[15]).plain
|
|
|
171 |
self.download_mirror = StringList().load_base64(result[16]).plain
|
|
|
172 |
self.wiki = StringList().load_base64(result[17]).plain
|
|
|
173 |
self.programming_language = StringList().load_base64(result[18]).plain
|
|
|
174 |
self.os = StringList().load_base64(result[19]).plain
|
|
|
175 |
self.language = StringList().load_base64(result[20]).plain
|
|
|
176 |
self.idDWBatch = result[21]
|
|
|
177 |
self.idProject = result[22]
|
|
|
178 |
#DoapVersion Table
|
|
|
179 |
self.release = []
|
|
|
180 |
cur = CrawlerDatabase.execute_cursor("SELECT platform, revision, file_release, created, name FROM DoapVersion WHERE idDoap=" + str(self.idDoap))
|
|
|
181 |
results = cur.fetchall()
|
|
|
182 |
for record in results:
|
|
|
183 |
dv = DoapVersion()
|
|
|
184 |
dv.name = record[4]
|
|
|
185 |
dv.created = str(record[3])
|
|
|
186 |
dv.revision = record[1]
|
|
|
187 |
dv.platform = record[0]
|
|
|
188 |
dv.file_release = StringList().load_base64(record[2]).plain
|
|
|
189 |
self.release.append(dv)
|
|
|
190 |
#DoapRepository Table
|
|
|
191 |
cur = CrawlerDatabase.execute_cursor("SELECT browse, anon_root, location, type FROM DoapRepository WHERE idDoap=" + str(self.idDoap))
|
|
|
192 |
results = cur.fetchall()
|
|
|
193 |
for record in results:
|
|
|
194 |
dr = DoapRepository(self)
|
|
|
195 |
dr.browse = record[0]
|
|
|
196 |
dr.anon_root = record[1]
|
|
|
197 |
dr.location = record[2]
|
|
|
198 |
dr.type = record[3]
|
|
|
199 |
if dr.type == 'svn':
|
|
|
200 |
self.svn_repository = dr
|
|
|
201 |
if dr.type == 'bk':
|
|
|
202 |
self.bk_repository = dr
|
|
|
203 |
if dr.type == 'cvs':
|
|
|
204 |
pass
|
|
|
205 |
#PATCH doapfiend adds a cvs even if it is not there self.cvs_repository = dr
|
|
|
206 |
if dr.type == 'arch':
|
|
|
207 |
self.arch_repository = dr
|
|
|
208 |
if dr.type == 'bzr':
|
|
|
209 |
self.bzr_repository = dr
|
|
|
210 |
if dr.type == 'git':
|
|
|
211 |
self.git_repository = dr
|
|
|
212 |
if dr.type == 'hg':
|
|
|
213 |
self.hg_repository = dr
|
|
|
214 |
if dr.type == 'darcs':
|
|
|
215 |
self.darcs_repository = dr
|
|
|
216 |
|
|
|
217 |
self.maintainer = []
|
|
|
218 |
self.developer = []
|
|
|
219 |
self.documenter = []
|
|
|
220 |
self.helper = []
|
|
|
221 |
self.tester = []
|
|
|
222 |
self.translator = []
|
|
|
223 |
parameters = {
|
|
|
224 |
'idDoapProject': idDoap
|
|
|
225 |
}
|
|
|
226 |
cur = CrawlerDatabase.execute_cursor("SELECT fp.firstName, fp.lastName, fp.login, dpfp.idDoapRole FROM FoafPerson fp JOIN DoapProjectFoafPerson dpfp on fp.idFoafPerson=dpfp.idFoafPerson WHERE idDoapProject=%(idDoapProject)s", parameters)
|
|
|
227 |
results = cur.fetchall()
|
|
|
228 |
for record in results:
|
|
|
229 |
fp = FoafPerson(record[0], record[1], record[2])
|
|
|
230 |
idDoapRole = record[3]
|
|
|
231 |
if idDoapRole == 1:
|
|
|
232 |
self.maintainer.append(fp)
|
|
|
233 |
elif idDoapRole == 2:
|
|
|
234 |
self.developer.append(fp)
|
|
|
235 |
elif idDoapRole == 3:
|
|
|
236 |
self.documenter.append(fp)
|
|
|
237 |
elif idDoapRole == 4:
|
|
|
238 |
self.tester.append(fp)
|
|
|
239 |
elif idDoapRole == 5:
|
|
|
240 |
self.translator.append(fp)
|
|
|
241 |
elif idDoapRole == 6:
|
|
|
242 |
self.helper.append(fp)
|
|
|
243 |
except Exception, e:
|
|
|
244 |
Logger.error(str(e))
|