00001 import urllib2
00002 from MoinMoin.Page import Page
00003 from MoinMoin.wikiutil import get_unicode
00004
00005 from macroutils import load_stack_manifest, load_package_manifest, distro_names, CONTRIBUTE_TMPL, UtilException
00006 from headers import get_nav, get_description, get_package_links, generate_package_header, distro_html, get_stack_links
00007
00008 generates_headings = True
00009 dependencies = []
00010
00011 if 'boxturtle' in distro_names:
00012 distro_names.remove('boxturtle')
00013 if 'cturtle' in distro_names:
00014 distro_names.remove('cturtle')
00015 if 'diamondback' in distro_names:
00016 distro_names.remove('diamondback')
00017 if 'unstable' in distro_names:
00018 distro_names.remove('unstable')
00019
00020 def generate_old_stack_header(macro, stack_name, opt_distro=None):
00021 try:
00022 data = load_stack_manifest(stack_name, opt_distro)
00023 except UtilException, e:
00024 name = "name: %s, distro: %s" % (stack_name, opt_distro)
00025 return CONTRIBUTE_TMPL%locals()
00026
00027 packages = data.get('packages', [])
00028 is_unary = [stack_name] == packages
00029
00030 desc = get_description(macro, data, 'stack')
00031 nav = get_nav(macro, stack_name, packages, distro=opt_distro)
00032 links = get_stack_links(macro, stack_name, data, packages, is_unary, opt_distro)
00033
00034 if is_unary:
00035 try:
00036 package_data = load_package_manifest(stack_name, opt_distro)
00037 links += get_package_links(macro, stack_name, package_data, opt_distro, None)
00038 except:
00039 pass
00040
00041 return macro.formatter.rawHTML(nav) + '<br><br>' + macro.formatter.rawHTML(links) + desc
00042
00043 def macro_StackHeader(macro, arg1, arg2=None):
00044 stack_name = get_unicode(macro.request, arg1)
00045 opt_distro = get_unicode(macro.request, arg2)
00046 if ' ' in stack_name:
00047
00048 splits = stack_name.split(' ')
00049 if len(splits) > 2:
00050 return "ERROR in StackHeader. Usage: [[StackHeader(pkg_name opt_lang)]]"
00051 stack_name, lang = splits
00052 if not stack_name:
00053 return "ERROR in StackHeader. Usage: [[StackHeader(pkg_name opt_lang)]]"
00054
00055 if not opt_distro:
00056 headers_html = []
00057 for distro in distro_names:
00058 if distro in ['boxturtle', 'cturtle', 'diamondback']:
00059 stack_header_html = generate_old_stack_header(macro, stack_name, distro)
00060 else:
00061 stack_header_html = generate_package_header(macro, stack_name, distro)
00062 headers_html.append('<div class="version %s">' % distro + stack_header_html + '</div>')
00063
00064 html = "\n".join([distro_html(distro, distro_names) for distro in distro_names])
00065 return macro.formatter.rawHTML(html + "\n".join(headers_html))
00066 else:
00067 if opt_distro in ['boxturtle', 'cturtle', 'diamondback']:
00068 return generate_old_stack_header(macro, stack_name, opt_distro)
00069 else:
00070 return generate_package_header(macro, stack_name, opt_distro)
00071
00072