10 from urlparse
import urlparse
18 conn = httplib.HTTPConnection(x.netloc)
19 conn.request(
"HEAD", x.path)
20 return conn.getresponse().status
26 elements = manifest.getElementsByTagName(name)
27 if len(elements) == 0:
34 if element
is None or len(element.childNodes)==0:
36 return element.childNodes[0].data
39 sorted_report = sorted(rdict.iteritems(), key=operator.itemgetter(1))
41 print "=" * 5, name,
"="*(40-len(name))
42 for (value, count)
in sorted_report:
47 if 'Maintained by' in s:
48 i = s.index(
'Maintained by')
49 s = s[:i] + s[i+1+len(
'Maintained by'):]
51 for a
in s.split(
','):
52 for b
in a.split(
'and'):
53 if split
and '/' in b:
55 authors.append(b.strip())
60 authors = collections.defaultdict(list)
61 descriptions = collections.defaultdict(int)
62 briefs = collections.defaultdict(int)
63 reviews = collections.defaultdict(int)
64 licenses = collections.defaultdict(int)
65 urls = collections.defaultdict(int)
69 if len(sys.argv)<=1
or '-h' in sys.argv:
70 print "Need to specify a directory to search through as the first parameter" 71 print " [use the -web flag to ping the address " 72 print " specified in the URL tag to see if it exists ] " 75 check_urls =
'-web' in sys.argv
77 for root, subFolders, files
in os.walk(sys.argv[1]):
78 if 'manifest.xml' in files:
80 elif 'stack.xml' in files:
85 package = os.path.basename(root)
87 manifest_xml = open(
"%s/manifest.xml"%root,
'r').read() 89 manifest_xml = open(
"%s/stack.xml"%root,
'r').read() 92 manifest = xml.dom.minidom.parseString(manifest_xml)
96 node = {
'name': package}
100 authors[a_name].append(package)
101 node[
'author'] = author
104 if not description_xml:
105 node[
'description'] =
None 108 description =
get_text(manifest,
'description').strip()
109 brief = description_xml.getAttribute(
'brief').strip()
110 node[
'description'] =
'minimal' if description==package
else 'detailed' 111 node[
'brief'] =
'minimal' if brief==package
else 'detailed' 113 descriptions[ node[
'description'] ] += 1
114 briefs[ node[
'brief'] ] += 1
117 if review_xml
is None:
120 review = review_xml.getAttribute(
'status')
121 node[
'review' ] = review
125 node[
'license' ] = license
139 packages.append(node)
143 lengths = collections.defaultdict(int)
144 for d
in packages + stacks:
145 for a,b
in d.iteritems():
146 if type(b)==type(
u''):
147 b = b.encode(
'ascii',
'replace')
148 if len(str(b)) > lengths[a]:
149 lengths[a] = len(str(b))
150 if len(str(a)) > lengths[a]:
151 lengths[a] = len(str(a))
153 fields = [
'name',
'description',
'brief',
'license',
'url',
'review',
'author']
157 print (
"%%-%ds"%lengths[field])%field,
161 print "=" * lengths[field],
166 print (
"%%-%ds"%lengths[field])%str(d[field]),
172 print (
"%%-%ds"%lengths[field])%field,
176 print "=" * lengths[field],
182 if type(val)==type(
u''):
183 val = val.encode(
'ascii',
'replace')
185 n = lengths[field] - len(val)-1
189 print (
"%%-%ds"%lengths[field])%str(val),
192 report(
'Descriptions', descriptions)
193 report(
'Brief Descriptions', briefs)
194 report(
'Reviews', reviews)
195 report(
'Licenses', licenses)
199 print "=" * 5, name,
"="*(40-len(name))
200 for a,c
in sorted(authors.items()):
201 a = a.encode(
'ascii',
'replace')
202 print "%s %4d"%(a.strip(),len(c))
204 for (i,b)
in enumerate(c):
def get_element(doc, name)
def extract_items(s, split=False)