+ def handle_description(node):
+ if 'metaname' in node:
+ name = node['metaname']
+ pkg_info = pkg_dict[name]
+ desc = pkg_info.get('description')
+ if desc[0:10] == '__KS_URL__':
+ logger.info("Processing "+name+" for its description: "+pkg_info.get('description'))
+ # Extract URL from __KS_URL__
+ ksURL = desc[11:].splitlines()[0].strip()
+ # Omit the first line with __KS_URL__ from showing.
+ pkg_info['description'] = desc[len(desc.splitlines(True)[0]):]
+
+ # Search for filename if directory is given
+ # e.g., Convert http://a.com/a/ to https://a.com/a/blahblah.ks
+ # Works for file-indexing html
+ if ksURL[-3:].lower() != ".ks":
+ if ksURL[-1:] != "/":
+ ksURL += "/"
+ r = requests.get(ksURL)
+ m = re.search('>([^<]*\\.ks)\\s*<', r.text)
+ if not m.group(1):
+ m = re.search('"([^"]*\\.ks)\\s*"', r.text)
+ if not m.group(1):
+ m = re.search("'([^']*\\.ks)\\s*'", r.text)
+ if not m.group(1):
+ node['icon'] = 'glyphicon glyphicon-remove-sign'
+ node['tooltip'] = 'Cannot find image base from' + ksURL
+ return node
+ ksURL += m.group(1)
+ node['tooltip'] = 'Image base from '+ksURL
+ node['ks'] = ksURL
+ elif desc[0:10] == '__EXPAND__':
+ # Omit the first line with __EXPAND__ from showing.
+ pkg_info['description'] = desc[len(desc.splitlines(True)[0]):]
+ node['state'] = { 'expanded': True }
+ return node