$search
00001 #!/usr/bin/python 00002 00003 import roslib; roslib.load_manifest('manifest_cleaner') 00004 import rospy 00005 import xml.dom.minidom 00006 import os 00007 import os.path 00008 import sys 00009 import collections 00010 import operator 00011 from urlparse import urlparse 00012 import httplib 00013 00014 00015 def get_code(url): 00016 x = urlparse(url) 00017 00018 try: 00019 conn = httplib.HTTPConnection(x.netloc) 00020 conn.request("HEAD", x.path) 00021 return conn.getresponse().status 00022 except StandardError: 00023 return None 00024 00025 00026 def get_element(doc, name): 00027 elements = manifest.getElementsByTagName(name) 00028 if len(elements) == 0: 00029 return None 00030 element = elements[0] 00031 return element 00032 00033 def get_text(doc, name): 00034 element = get_element(doc, name) 00035 if element is None or len(element.childNodes)==0: 00036 return '' 00037 return element.childNodes[0].data 00038 00039 def report(name, rdict): 00040 sorted_report = sorted(rdict.iteritems(), key=operator.itemgetter(1)) 00041 print 00042 print "=" * 5, name, "="*(40-len(name)) 00043 for (value, count) in sorted_report: 00044 print value, count 00045 00046 def extract_items(s, split=False): 00047 authors = [] 00048 if 'Maintained by' in s: 00049 i = s.index('Maintained by') 00050 s = s[:i] + s[i+1+len('Maintained by'):] 00051 00052 for a in s.split(','): 00053 for b in a.split('and'): 00054 if split and '/' in b: 00055 b = b[:b.index('/')] 00056 authors.append(b.strip()) 00057 return authors 00058 00059 #diff mainpage.dox ../pr2_sith/mainpage.dox | grep '^>' 00060 00061 authors = collections.defaultdict(list) 00062 descriptions = collections.defaultdict(int) 00063 briefs = collections.defaultdict(int) 00064 reviews = collections.defaultdict(int) 00065 licenses = collections.defaultdict(int) 00066 urls = collections.defaultdict(int) 00067 packages = [] 00068 stacks = [] 00069 00070 if len(sys.argv)<=1 or '-h' in sys.argv: 00071 print "Need to specify a directory to search through as the first parameter" 00072 print " [use the -web flag to ping the address " 00073 print " specified in the URL tag to see if it exists ] " 00074 exit(1) 00075 00076 check_urls = '-web' in sys.argv 00077 00078 for root, subFolders, files in os.walk(sys.argv[1]): 00079 if 'manifest.xml' in files: 00080 is_package = True 00081 elif 'stack.xml' in files: 00082 is_package = False 00083 else: 00084 continue 00085 00086 package = os.path.basename(root) 00087 if is_package: 00088 manifest_xml = open("%s/manifest.xml"%root, 'r').read() 00089 else: 00090 manifest_xml = open("%s/stack.xml"%root, 'r').read() 00091 00092 try: 00093 manifest = xml.dom.minidom.parseString(manifest_xml) 00094 except: 00095 continue 00096 00097 node = {'name': package} 00098 00099 author = get_text(manifest, 'author') 00100 for a_name in extract_items(author, True): 00101 authors[a_name].append(package) 00102 node['author'] = author 00103 00104 description_xml = get_element(manifest, 'description') 00105 if not description_xml: 00106 node['description'] = None 00107 node['brief'] = None 00108 else: 00109 description = get_text(manifest, 'description').strip() 00110 brief = description_xml.getAttribute('brief').strip() 00111 node['description'] = 'minimal' if description==package else 'detailed' 00112 node['brief'] = 'minimal' if brief==package else 'detailed' 00113 00114 descriptions[ node['description'] ] += 1 00115 briefs[ node['brief'] ] += 1 00116 00117 review_xml = get_element(manifest, 'review') 00118 if review_xml is None: 00119 review = None 00120 else: 00121 review = review_xml.getAttribute('status') 00122 node[ 'review' ] = review 00123 reviews[review] += 1 00124 00125 license = get_text(manifest, 'license') 00126 node[ 'license' ] = license 00127 for lic in extract_items(license): 00128 licenses[lic] += 1 00129 00130 url = get_text(manifest, 'url') 00131 if url is not None: 00132 if check_urls: 00133 url = get_code(url) 00134 else: 00135 url = 'specified' 00136 node[ 'url' ] = url 00137 urls[url] += 1 00138 00139 if is_package: 00140 packages.append(node) 00141 else: 00142 stacks.append(node) 00143 00144 lengths = collections.defaultdict(int) 00145 for d in packages + stacks: 00146 for a,b in d.iteritems(): 00147 if type(b)==type(u''): 00148 b = b.encode('ascii', 'replace') 00149 if len(str(b)) > lengths[a]: 00150 lengths[a] = len(str(b)) 00151 if len(str(a)) > lengths[a]: 00152 lengths[a] = len(str(a)) 00153 00154 fields = ['name', 'description', 'brief', 'license', 'url', 'review', 'author'] 00155 00156 if len(stacks)>0: 00157 for field in fields: 00158 print ("%%-%ds"%lengths[field])%field, 00159 print 00160 00161 for field in fields: 00162 print "=" * lengths[field], 00163 print 00164 00165 for d in stacks: 00166 for field in fields: 00167 print ("%%-%ds"%lengths[field])%str(d[field]), 00168 print 00169 print 00170 00171 if len(packages)>0: 00172 for field in fields: 00173 print ("%%-%ds"%lengths[field])%field, 00174 print 00175 00176 for field in fields: 00177 print "=" * lengths[field], 00178 print 00179 00180 for d in packages: 00181 for field in fields: 00182 val = d[field] 00183 if type(val)==type(u''): 00184 val = val.encode('ascii', 'replace') 00185 print val, 00186 n = lengths[field] - len(val)-1 00187 if n>0: 00188 print " "*n, 00189 else: 00190 print ("%%-%ds"%lengths[field])%str(val), 00191 print 00192 00193 report('Descriptions', descriptions) 00194 report('Brief Descriptions', briefs) 00195 report('Reviews', reviews) 00196 report('Licenses', licenses) 00197 report('Urls', urls) 00198 print 00199 name = "Authors" 00200 print "=" * 5, name, "="*(40-len(name)) 00201 for a,c in sorted(authors.items()): 00202 a = a.encode('ascii', 'replace') 00203 print "%s %4d"%(a.strip(),len(c)) 00204 print ' ', 00205 for (i,b) in enumerate(c): 00206 print "%-30s"%b, 00207 if i%3==2: 00208 print '\n ', 00209 print 00210 00211