# 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).
# Commercial licenses are available and do not require any SOS Open Source attributions
# or visible copyright notices but they are not permitted under this license.
# OSSEval Copyright 2014 Bitergium SLL
# SOS Open Source Copyright 2012 Roberto Galoppini
# Author: Davide Galletti
from xml.dom import minidom
import urllib2
import OpenSourceProject
class Configuration():
api_key = OpenSourceProject.ohloh_api_key
max_number_of_records = OpenSourceProject.local_record_limit
flossmole_locale = OpenSourceProject.flossmole_locale
class Forges(object):
ALL = 0
#SF = Sourceforge
SF = 1
#FC = Freecode was FM = Freshmeat
FC = 2
#FSF = Free Software Foundation
FSF = 5
#GH = Github
GH = 11
#GC = Google code
GC = 12
OHLOH = 100
CODEPLEX = 1000
APACHE = 1200
ECLIPSE = 1300
class xmlElements():
def __init__(self, xml):
self.xml = xml
def firstValue(self):
try:
return self.xml[0].firstChild.nodeValue
except:
return ""
class UrllibHelper():
@staticmethod
def urlopen(url_string, max_attempts = 3):
'''
Sometimes the download just fails for no apparent reason; retrying right after the
failure solves the issue; so this method retries max_attempts times with a default of 3
'''
success = False
n_attempts = 1
ret = ""
while not (success or n_attempts>max_attempts):
try:
response = urllib2.urlopen(url_string)
ret = response.read()
success = True
except Exception as ex:
print('Error downloading ' + url_string + " - Attempt n.:" + str(n_attempts) + " - " + str(ex))
n_attempts = n_attempts + 1
return ret