Download this file

ohloh.py    154 lines (134 with data), 8.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
 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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
# Copyright 2014 Bitergium SLL
import urllib2
from xml.dom import minidom
from utils import Configuration, xmlElements, Forges
from OSSEval.utils import TrivialJSONEncoder
class OhlohProxy():
def search_json(self, name):
a = TrivialJSONEncoder().encode(OhlohProxy.search(name))
return a
@staticmethod
def search(name):
page = 1
print "Ohloh search - " + name + " - page " + str(page)
url_ohloh = "https://www.ohloh.net/p.xml?api_key=" + Configuration.api_key + "&query=" + name + "&page="
response = urllib2.urlopen(url_ohloh + str(page))
xml = response.read()
xmldoc = minidom.parseString(xml)
items_available = xmlElements(xmldoc.getElementsByTagName('items_available')).firstValue()
status = xmlElements(xmldoc.getElementsByTagName('status')).firstValue()
project_list = []
while (status == 'success' and len(project_list) < min(Configuration.max_number_of_records, items_available)):
page = page + 1
print "Ohloh search - " + name + " - page " + str(page)
item_list = xmldoc.getElementsByTagName('project')
for s in item_list :
try:
op = OhlohProject()
op.id = xmlElements(s.getElementsByTagName('url_name')).firstValue()
op.name = xmlElements(s.getElementsByTagName('name')).firstValue()
op.description = xmlElements(s.getElementsByTagName('description')).firstValue()
op.small_logo_url = xmlElements(s.getElementsByTagName('small_logo_url')).firstValue()
op.homepage_url = xmlElements(s.getElementsByTagName('homepage_url')).firstValue()
op.id_forge = Forges.OHLOH
op.datasource_id = 0
project_list.append(op)
# s.getElementsByTagName('id')[0].localName
# id
except Exception as ex:
print str(ex)
response = urllib2.urlopen(url_ohloh + str(page))
xml = response.read()
xmldoc = minidom.parseString(xml)
status = xmldoc.getElementsByTagName('status')[0].firstChild.nodeValue
return project_list
@staticmethod
def getProjectInfo(project_identifier):
url_ohloh = "http://www.ohloh.net/projects/" + project_identifier + ".xml?api_key=" + Configuration.api_key
response = urllib2.urlopen(url_ohloh)
xml = response.read()
xmldoc = minidom.parseString(xml)
info = {}
status = xmlElements(xmldoc.getElementsByTagName('status')).firstValue()
if status == 'success':
info['id'] = project_identifier
info['project_identifier'] = project_identifier
info['widget_languages'] = '<script type="text/javascript" src="http://www.ohloh.net/p/' + project_identifier + '/widgets/project_languages.js"></script>'
info['ohloh_url'] = "http://www.ohloh.net/p/" + project_identifier
info['commits_spark'] = "http://www.ohloh.net/p/" + project_identifier + "/analyses/latest/commits_spark.png";
info['created_at'] = xmlElements(xmldoc.getElementsByTagName('created_at')).firstValue()
info['updated_at'] = xmlElements(xmldoc.getElementsByTagName('updated_at')).firstValue()
info['description'] = xmlElements(xmldoc.getElementsByTagName('description')).firstValue()
info['homepage_url'] = xmlElements(xmldoc.getElementsByTagName('homepage_url')).firstValue()
info['download_url'] = xmlElements(xmldoc.getElementsByTagName('download_url')).firstValue()
info['medium_logo_url'] = xmlElements(xmldoc.getElementsByTagName('medium_logo_url')).firstValue()
info['small_logo_url'] = xmlElements(xmldoc.getElementsByTagName('small_logo_url')).firstValue()
info['user_count'] = xmlElements(xmldoc.getElementsByTagName('user_count')).firstValue()
info['average_rating'] = xmlElements(xmldoc.getElementsByTagName('average_rating')).firstValue()
info['rating_count'] = xmlElements(xmldoc.getElementsByTagName('rating_count')).firstValue()
info['review_count'] = xmlElements(xmldoc.getElementsByTagName('review_count')).firstValue()
info['twelve_month_contributor_count'] = xmlElements(xmldoc.getElementsByTagName('twelve_month_contributor_count')).firstValue()
info['total_code_lines'] = xmlElements(xmldoc.getElementsByTagName('total_code_lines')).firstValue()
info['main_language_name'] = xmlElements(xmldoc.getElementsByTagName('main_language_name')).firstValue()
info['licenses'] = []
license_list = xmldoc.getElementsByTagName('license')
for s in license_list :
info['licenses'].append(xmlElements(s.getElementsByTagName('nice_name')).firstValue())
info['languages'] = []
language_list = xmldoc.getElementsByTagName('language')
for l in language_list :
language = {}
language['project_identifier'] = l.firstChild.nodeValue
language['percentage'] = l.attributes['percentage'].value
language['color'] = l.attributes['color'].value
language['id'] = l.attributes['id'].value
info['languages'].append(language)
url_ohloh = "http://www.ohloh.net/projects/" + project_identifier + "/factoids.xml?api_key=" + Configuration.api_key
response = urllib2.urlopen(url_ohloh)
xml = response.read()
xmldoc = minidom.parseString(xml)
status = xmlElements(xmldoc.getElementsByTagName('status')).firstValue()
info['factoids'] = []
if status == 'success':
factoid_list = xmldoc.getElementsByTagName('factoid')
for f in factoid_list :
factoid = {}
factoid['type'] = xmlElements(f.getElementsByTagName('type')).firstValue()
factoid['description'] = xmlElements(f.getElementsByTagName('description')).firstValue()
factoid['severity'] = xmlElements(f.getElementsByTagName('severity')).firstValue()
info['factoids'].append(factoid)
url_ohloh = "http://www.ohloh.net/projects/" + project_identifier + "/analyses/latest/size_facts.xml?api_key=" + Configuration.api_key
response = urllib2.urlopen(url_ohloh)
xml = response.read()
xmldoc = minidom.parseString(xml)
info['size_fact'] = None
status = xmlElements(xmldoc.getElementsByTagName('status')).firstValue()
if status == 'success':
size_fact_list = xmldoc.getElementsByTagName('size_fact')
if len(size_fact_list) > 0:
sf = size_fact_list[len(size_fact_list) - 1]
size_fact = {}
size_fact['month'] = xmlElements(sf.getElementsByTagName('month')).firstValue()
size_fact['code'] = xmlElements(sf.getElementsByTagName('code')).firstValue()
size_fact['comments'] = xmlElements(sf.getElementsByTagName('comments')).firstValue()
size_fact['blanks'] = xmlElements(sf.getElementsByTagName('comment_ratio')).firstValue()
size_fact['commits'] = xmlElements(sf.getElementsByTagName('commits')).firstValue()
size_fact['comment_ratio'] = xmlElements(sf.getElementsByTagName('comment_ratio')).firstValue()
size_fact['man_months'] = xmlElements(sf.getElementsByTagName('man_months')).firstValue()
# I just need the last as it is the most recent
info['size_fact'] = size_fact
return info
class OhlohProject():
id = 0
name = ""
description = ""
small_logo_url = ""
homepage_url = ""
id_forge = 0
datasource_id = 0
def load_information(self):
self.info = OhlohProxy.getProjectInfo(self.name)