Parent: [c9d94b] (diff)

Child: [831432] (diff)

Download this file

utils.py    71 lines (62 with data), 2.3 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
# 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