# This Source Code Form of OSSEval is subject to the terms of the GNU AFFERO
# GENERAL PUBLIC LICENSE, v. 3.0. If a copy of the AGPL was not
# distributed with this file, You can obtain one at http://www.gnu.org/licenses/agpl.txt
#
# OSSeval is powered by the SOS Open Source AGPL edition.
# The AGPL requires that you do not remove the SOS Open Source attribution and copyright
# notices from the user interface (see section 5.d below).
# OSSEval Copyright 2014 Bitergium SLL
# SOS Open Source Copyright 2012 Roberto Galoppini
# Author: Davide Galletti
import urllib2, json
from utils import Configuration, Forges, StringList, StringHelper
from django.db import connections
class Apache():
@staticmethod
def search(name):
project_list = []
cursor = connections['flossmole'].cursor()
parameters = { 'limit': Configuration.max_number_of_records }
cursor.execute("SELECT idDoap, Name, Shortdesc, Description, Homepage FROM apache_doap WHERE LOWER(name) LIKE '%%" + name.lower() + "%%' LIMIT %(limit)s", parameters)
results = cursor.fetchall()
for record in results:
dap = DoapApacheProject()
dap.id = record[0]
dap.id_forge = Forges.APACHE
dap.datasource_id = 0
dap.name = record[1]
dap.shortdesc = record[2]
dap.description = record[3]
dap.homepage = record[4]
project_list.append(dap)
return project_list
@staticmethod
def getProjectInfo(project_identifier):
dep = DoapApacheProject()
dep.load_from_db(project_identifier)
return { "doap" : dep.getDict() }
class Eclipse():
@staticmethod
def search(name):
project_list = []
cursor = connections['flossmole'].cursor()
parameters = { 'limit': Configuration.max_number_of_records }
cursor.execute("SELECT idDoap, Name, Shortdesc, Description, Homepage FROM eclipse_doap WHERE LOWER(name) LIKE '%%" + name.lower() + "%%' LIMIT %(limit)s", parameters)
results = cursor.fetchall()
for record in results:
dep = DoapEclipseProject()
dep.id = record[0]
dep.id_forge = Forges.ECLIPSE
dep.datasource_id = 0
dep.name = record[1]
dep.shortdesc = record[2]
dep.description = record[3]
dep.homepage = record[4]
project_list.append(dep)
return project_list
@staticmethod
def getProjectInfo(project_identifier):
dep = DoapEclipseProject()
dep.load_from_db(project_identifier)
# I try to get metrics from Bitergia's Grimoire
try:
# http://dashboard.castalia.camp/projects/modeling.emf.compare_metrics.json
response = urllib2.urlopen("http://dashboard.castalia.camp/projects/" + dep.name + "_metrics.json")
metrics_json = response.read()
metrics_decoded = json.loads(metrics_json)
return { "doap" : dep.getDict(), "metrics_decoded": metrics_decoded }
except:
return { "doap" : dep.getDict() }
class FoafPerson:
def __init__(self, firstName, lastName, login = ""):
# see issue 867 for details: http://markosproject.berlios.de/mantis/view.php?id=867
# Apache data sometimes is wrongly encoded: 'utf8' codec can't decode byte 0xfc in position 9: invalid start byte
try:
foo = firstName.decode('utf-8')
self.firstName = firstName
except:
self.firstName = StringHelper.removeNonAscii(firstName)
self.lastName = lastName
self.login = login
class DoapVersion:
def __init__(self):
self.os = []
class DoapRepository:
def __init__(self, parent):
self.parent_id_doap = parent.idDoap
class DoapProject(object):
"""
Class with the information in the DOAP format
"""
def __init__(self):
self._idDoap = None
@property
def idDoap(self):
return self._idDoap
@idDoap.setter
def idDoap(self, value):
self._idDoap = value
if hasattr(self, "svn_repository") and (not (self.svn_repository is None)):
self.svn_repository.parent_id_doap = self._idDoap
if hasattr(self, "hg_repository") and (not (self.hg_repository is None)):
self.hg_repository.parent_id_doap = self._idDoap
if hasattr(self, "darcs_repository") and (not (self.darcs_repository is None)):
self.darcs_repository.parent_id_doap = self._idDoap
if hasattr(self, "bzr_repository") and (not (self.bzr_repository is None)):
self.bzr_repository.parent_id_doap = self._idDoap
if hasattr(self, "arch_repository") and (not (self.arch_repository is None)):
self.arch_repository.parent_id_doap = self._idDoap
if hasattr(self, "bk_repository") and (not (self.bk_repository is None)):
self.bk_repository.parent_id_doap = self._idDoap
if hasattr(self, "cvs_repository") and (not (self.cvs_repository is None)):
self.cvs_repository.parent_id_doap = self._idDoap
if hasattr(self, "git_repository") and (not (self.git_repository is None)):
self.git_repository.parent_id_doap = self._idDoap
def load_from_db(self, idDoap):
self.idDoap = idDoap
try:
cursor = connections['flossmole'].cursor()
cursor.execute("SELECT name, shortdesc, description, homepage, created, mailing_list, download_page, bug_database, platform, service_endpoint, audience, blog, old_homepage, category, license, download_mirror, wiki, programming_language, os, language FROM " + self.table_prefix + "_doap WHERE idDoap="+str(idDoap))
result = cursor.fetchone()
if not (result is None):
self.name = result[0]
self.shortdesc = result[1]
self.description = result[2]
self.homepage = result[3]
self.created = str(result[4])
self.mailing_list = result[5]
self.download_page = result[6]
self.bug_database = result[7]
self.platform = result[8]
self.service_endpoint = result[9]
self.audience = result[10]
self.blog = result[11]
self.old_homepage = StringList().load_base64(result[12]).plain
self.category = StringList().load_base64(result[13]).plain
self.license = StringList().load_base64(result[14]).plain
self.download_mirror = StringList().load_base64(result[15]).plain
self.wiki = StringList().load_base64(result[16]).plain
self.programming_language = StringList().load_base64(result[17]).plain
self.os = StringList().load_base64(result[18]).plain
self.language = StringList().load_base64(result[19]).plain
#DoapVersion Table
self.release = []
cur = connections['flossmole'].cursor()
cur.execute("SELECT platform, revision, file_release, created, name FROM " + self.table_prefix + "_DoapVersion WHERE idDoap=" + str(self.idDoap))
results = cur.fetchall()
for record in results:
dv = DoapVersion()
dv.name = record[4]
dv.created = str(record[3])
dv.revision = record[1]
dv.platform = record[0]
dv.file_release = StringList().load_base64(record[2]).plain
self.release.append(dv)
#DoapRepository Table
cur = connections['flossmole'].cursor()
cur.execute("SELECT browse, anon_root, location, type FROM " + self.table_prefix + "_DoapRepository WHERE idDoap=" + str(self.idDoap))
results = cur.fetchall()
for record in results:
dr = DoapRepository(self)
dr.browse = record[0]
dr.anon_root = record[1]
dr.location = record[2]
dr.type = record[3]
if dr.type == 'svn':
self.svn_repository = dr
if dr.type == 'bk':
self.bk_repository = dr
if dr.type == 'cvs':
pass
#PATCH doapfiend adds a cvs even if it is not there self.cvs_repository = dr
if dr.type == 'arch':
self.arch_repository = dr
if dr.type == 'bzr':
self.bzr_repository = dr
if dr.type == 'git':
self.git_repository = dr
if dr.type == 'hg':
self.hg_repository = dr
if dr.type == 'darcs':
self.darcs_repository = dr
self.maintainer = []
self.developer = []
self.documenter = []
self.helper = []
self.tester = []
self.translator = []
parameters = {
'idDoapProject': idDoap
}
cur = connections['flossmole'].cursor()
cur.execute("SELECT fp.firstName, fp.lastName, fp.login, dpfp.idDoapRole FROM " + self.table_prefix + "_FoafPerson fp JOIN " + self.table_prefix + "_DoapProjectFoafPerson dpfp on fp.idFoafPerson=dpfp.idFoafPerson WHERE idDoapProject=%(idDoapProject)s", parameters)
results = cur.fetchall()
for record in results:
fp = FoafPerson(record[0], record[1], record[2])
idDoapRole = record[3]
if idDoapRole == 1:
self.maintainer.append(fp)
elif idDoapRole == 2:
self.developer.append(fp)
elif idDoapRole == 3:
self.documenter.append(fp)
elif idDoapRole == 4:
self.tester.append(fp)
elif idDoapRole == 5:
self.translator.append(fp)
elif idDoapRole == 6:
self.helper.append(fp)
except Exception, e:
print(str(e))
def getDict(self):
dic_var = self.__dict__.copy()
dic_var['maintainer'] = []
for m in self.maintainer:
dic_var['maintainer'].append(m.__dict__)
dic_var['release'] = []
for r in self.release:
dic_var['release'].append(r.__dict__)
if hasattr(self, 'svn_repository'):
dic_var['svn_repository'] = self.svn_repository.__dict__
return dic_var
class DoapApacheProject(DoapProject):
def __init__(self):
super(DoapApacheProject, self).__init__()
self.table_prefix = "apache"
class DoapEclipseProject(DoapProject):
def __init__(self):
super(DoapEclipseProject, self).__init__()
self.table_prefix = "eclipse"