00001 import urllib2
00002 from MoinMoin.Page import Page
00003 from MoinMoin.wikiutil import get_unicode
00004
00005 from macroutils import load_stack_release, \
00006 load_package_manifest, UtilException, load_stack_manifest
00007 from headers import get_nav, get_stack_links, get_package_links, get_description
00008
00009 generates_headings = True
00010 dependencies = []
00011
00012 def macro_StackageHeader(macro, arg1, arg2='ja'):
00013 stack_name = get_unicode(macro.request, arg1)
00014 lang = get_unicode(macro.request, arg2)
00015 if ' ' in stack_name:
00016
00017 splits = stack_name.split(' ')
00018 if len(splits) > 2:
00019 return "ERROR in StackHeader. Usage: [[StackHeader(pkg_name opt_lang)]]"
00020 stack_name, lang = splits
00021 if not stack_name:
00022 return "ERROR in StackHeader. Usage: [[StackHeader(pkg_name opt_lang)]]"
00023
00024 try:
00025 data = load_stack_manifest(stack_name, lang)
00026 except UtilException, e:
00027 return str(e)
00028
00029 packages = data.get('packages', [])
00030 is_unary = [stack_name] == packages
00031
00032 desc = get_description(macro, data, 'stack')
00033 nav = get_nav(macro, stack_name, packages)
00034 links = get_stack_links(macro, stack_name, data, packages, is_unary)
00035
00036 if is_unary:
00037 try:
00038 package_data = load_package_manifest(stack_name, lang)
00039 links += get_package_links(macro, stack_name, package_data)
00040 except:
00041 pass
00042
00043 return macro.formatter.rawHTML(nav) + macro.formatter.rawHTML(links) + desc
00044