import logging
+import requests
+import re
from operator import itemgetter
from tic.utils.rpmmisc import meetRequireVersion
def set_meta_require(meta_info):
meta_nodes = meta_info.get('nodes')
+ children = set()
for child_meta in meta_nodes:
set_meta_require(child_meta)
+ children.add(child_meta['metaname'])
duplicate = set()
pkg_info = pkg_dict[meta_info['metaname']]
for pkg in targets:
# The meta-pkg of the other group are excluded.
- if not pkg.get('meta') and pkg['name'] not in duplicate:
+ if pkg['name'] not in duplicate:
refer_count[pkg['id']] += 1
duplicate.add(pkg['name'])
- meta_nodes.append(make_node(pkg, meta_info.get('category')))
+
+ if pkg.get('meta'):
+ if not pkg['name'] in children:
+ meta_nodes.append(make_linked_meta_node(pkg['name'], pkg['summary']))
+ else:
+ meta_nodes.append(make_node(pkg, meta_info.get('category')))
# Added 'zz' to non meta-package because they are to be listed last
- meta_nodes = sorted(meta_nodes, key = lambda k: k['metaname'] if 'metaname' in k else 'zz'+k['text'])
- meta_info['nodes'] = meta_nodes
+ meta_nodes = sorted(meta_nodes, key = lambda k: 'aa'+k['metaname'] if 'metaname' in k else 'zz'+k['text'])
+ meta_info['nodes'] = meta_nodes
+
+ if meta_info['metaname'] =='building-blocks-sub2-Preset_iot-examples-3_RPI3_headless_devboard':
+ print(pkg_info)
def make_node(pkg_info, category=None):
n = dict(text=pkg_info['name'], nodes=[])
if category: n['category'] = category
return n
def make_meta_node(pkgname, viewtext):
return dict(text=viewtext, metaname=pkgname, nodes=[])
+ def make_linked_meta_node(pkgname, viewtext):
+ return dict(text='<i>'+viewtext+'</i>', metaname=pkgname, nodes=[])
def is_blank_ui_meta_node(pkgname):
return (pkgname[-8:-2] == '__UI__')
def handle_ui_meta_node(tag, node):
else:
node['text'] = ''
return node
+ 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
# view_data for tree view on web-ui
view_data = []
if is_blank_ui_meta_node(root[0]):
name = root[0]
sub1_node = handle_ui_meta_node(name[-2:], root_node)
+ root_node = handle_description(root_node)
view_data.append(root_node)
for sub1 in meta_info['sub1']:
if is_blank_ui_meta_node(sub1[0]):
name = sub1[0]
sub1_node = handle_ui_meta_node(name[-2:], sub1_node)
+ sub1_node = handle_description(sub1_node)
# search root
if sub1[1] in view_ref:
# add to root node
if is_blank_ui_meta_node(sub2[0]):
name = sub2[0]
sub1_node = handle_ui_meta_node(name[-2:], sub2_node)
+ sub2_node = handle_description(sub2_node)
# search sub1
if sub2[2] in view_ref:
if 'category' in view_ref[sub2[2]] and view_ref[sub2[2]]['category']: