Parent: [2c9463] (diff)

Download this file

models.py    118 lines (102 with data), 4.9 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
from datetime import date, datetime
from urlparse import urlparse
from django.db import models
from ohloh import OhlohProxy
from flossmole import FSF, FC, GC, GH
from utils import Forges
class OSProject(models.Model):
"""
Must be the same name of the Django app
"""
name = models.CharField(max_length=200)
instance = models.OneToOneField('analysis.Instance', related_name='actual_instance', primary_key=True)
def __str__(self):
return self.name + " - " + self.instance.name
def getInstanceInfo(self):
'''
Part of the required interface
i is a dictionary; each source information is withing the source name key, e.g.
i['FM']
i['OHLOH']
i['FSF']
i['GC']
i['GH']
...
Some information is extracted from specific sources and made available at root level; e.g.
i['days'] number of days since the project has been registered; it is calculated using i['FM']['date_added'] or i['OHLOH']['created_at']
...
'''
i = {}
for ospf in self.osprojectforge_set.all():
i[ospf.forge.name] = ospf.getProjectInfo()
# From now on you find heuristics that try to reasonably define a single value where you have several sources of information
# e.g. project is created 1/1/2012 according to Github and 4/2/2007 according to FSF; the heuristic will choose the remotest date
# we need a name to search on search engines
if self.instance.name_for_search <> "":
i['name'] = self.instance.name_for_search
else:
i['name'] = self.name
# some searches on search engines have to be restricted to project site; let's try to guess it
# the order is given by a heuristic based on data reliability
i['homepage'] = ""
try: i['homepage'] = i['FSF']['real_url']
except: pass
try: i['homepage'] = i['GH']['homepage']
except: pass
try: i['homepage'] = i['FM']['url_homepage']
except: pass
try: i['homepage'] = i['OHLOH']['homepage_url']
except: pass
if i['homepage'] <> "":
try:
i['siteforsearchengine'] = urlparse(i['homepage']).netloc
if i['siteforsearchengine'][:4] == "www.":
i['siteforsearchengine'] = i['siteforsearchengine'][4:]
except: i['siteforsearchengine'] = ""
# default to -1 e.g. no value; the oldest creation dates wins; GC and GH have no info; FSF released_on seems to have the same semantic
i['days'] = -1
try:
i['OHLOH']['days'] = (datetime.today() - datetime.strptime(i['OHLOH']['created_at'], '%Y-%m-%dT%H:%M:%SZ')).days
if i['OHLOH']['days'] > i['days']: i['days'] = i['OHLOH']['days']
except: pass
try:
i['FM']['days'] = (datetime.today() - datetime.strptime(i['FM']['date_added'], '%Y-%m-%d %H:%M:%S\n')).days
if i['FM']['days'] > i['days']: i['days'] = i['FM']['days']
except: pass
try:
i['FSF']['released_on'] = (date.today() - i['FSF']['released_on']).days
if i['FSF']['days'] > i['days']: i['days'] = i['FSF']['days']
except: pass
return i
class Forge(models.Model):
name = models.CharField(max_length=50)
url = models.CharField(max_length=200)
os_projects = models.ManyToManyField(OSProject, through='OSProjectForge', blank=True)
def __str__(self):
return self.name + " - " + self.url
class OSProjectForge(models.Model):
name = models.CharField(max_length=200)
forge = models.ForeignKey(Forge)
os_project = models.ForeignKey(OSProject)
identifier_in_forge = models.CharField(max_length=200)
datasource_id = models.IntegerField()
def __str__(self):
return self.name + " - " + self.forge.name
def getProjectInfo(self):
if self.forge.id == Forges.OHLOH:
osprojectforge_info = OhlohProxy.getProjectInfo(self.identifier_in_forge)
if self.forge.id == Forges.FC:
osprojectforge_info = FC.getProjectInfo(self.identifier_in_forge)
if self.forge.id == Forges.FSF:
osprojectforge_info = FSF.getProjectInfo(self.identifier_in_forge)
if self.forge.id == Forges.GC:
osprojectforge_info = GC.getProjectInfo(self.identifier_in_forge)
if self.forge.id == Forges.GH:
osprojectforge_info = GH.getProjectInfo(self.identifier_in_forge)
return osprojectforge_info
class OSSConfiguration(models.Model):
flossmole_locale = models.BooleanField()
ohloh_api_key = models.CharField(max_length = 100)
local_record_limit = models.IntegerField()
remote_record_limit = models.IntegerField()
ohloh_record_limit = models.IntegerField()