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, CONTRIBUTE_TMPL
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_StackHeader(macro, arg1, arg2=None):
00013 stack_name = get_unicode(macro.request, arg1)
00014 distro = 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_distro)]]"
00020 stack_name, distro = splits
00021 if not stack_name:
00022 return "ERROR in StackHeader. Usage: [[StackHeader(pkg_name opt_distro)]]"
00023
00024 try:
00025 data = load_stack_manifest(stack_name, distro)
00026 except UtilException, e:
00027 name = stack_name
00028 return CONTRIBUTE_TMPL%locals()
00029
00030 packages = data.get('packages', [])
00031 is_unary = [stack_name] == packages
00032
00033 desc = get_description(macro, data, 'stack')
00034 nav = get_nav(macro, stack_name, packages)
00035 links = get_stack_links(macro, stack_name, data, packages, is_unary)
00036
00037 if is_unary:
00038 try:
00039 package_data = load_package_manifest(stack_name, lang)
00040 links += get_package_links(macro, stack_name, package_data)
00041 except:
00042 pass
00043
00044 return macro.formatter.rawHTML(nav) + macro.formatter.rawHTML(links) + desc
00045