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