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