00001 from MoinMoin.Page import Page
00002 from MoinMoin.wikiutil import get_unicode
00003
00004 from macroutils import wiki_url, get_repo_li, get_vcs_li, load_repo_manifest, sub_link, UtilException, CONTRIBUTE_TMPL
00005
00006 generates_headings = True
00007 dependencies = []
00008
00009 def get_stack_items(macro, repo_data):
00010 f = macro.formatter
00011 p, url, div, br = f.paragraph, f.url, f.div, f.linebreak
00012 em, strong = f.emphasis, f.strong
00013 h, li, ul = f.heading, f.listitem, f.bullet_list
00014 text, rawHTML = f.text, f.rawHTML
00015
00016 items = []
00017 vcs_config = repo_data['vcs']
00018 stacks = repo_data['stacks']
00019 for name in sorted(stacks.iterkeys()):
00020 data = stacks[name]
00021 data['vcs'] = vcs_config['type']
00022
00023
00024 authors = data.get('authors', 'unknown')
00025 try:
00026 if type(authors) != unicode:
00027 authors = unicode(authors, 'utf-8')
00028 except UnicodeDecodeError:
00029 authors = ''
00030 license = data.get('license', 'unknown')
00031 description = data.get('description', '')
00032 try:
00033 if type(description) != unicode:
00034 description = unicode(description, 'utf-8')
00035 except UnicodeDecodeError:
00036 description = ''
00037 packages = data.get('packages', [])
00038
00039
00040 packages = [s for s in packages if not s.startswith('test_')]
00041 packages.sort()
00042
00043 package_links = []
00044 for pkg in packages:
00045 package_links.append(wiki_url(macro, pkg))
00046
00047
00048
00049
00050 if vcs_config['type'] == 'svn':
00051 vcs_li = get_vcs_li(macro, data)
00052 else:
00053 vcs_li = ''
00054 stack_html = \
00055 rawHTML('<a name="%s">'%(name))+\
00056 h(1,3)+rawHTML(wiki_url(macro, name))+h(0,3)+\
00057 p(1,id="package-info")+rawHTML(description)+p(0)+\
00058 p(1,id="package-info")+ul(1)+\
00059 li(1)+text("Author: "+authors)+li(0)+\
00060 li(1)+text("License: "+license)+li(0)+\
00061 li(1)+text("Packages: ")+rawHTML(", ".join(package_links))+li(0)+\
00062 vcs_li+\
00063 ul(0)+p(0)
00064 items.append(stack_html)
00065 return items
00066
00067 def macro_RepoHeader(macro, args):
00068 if ',' in args:
00069 args = args.split(',')
00070 else:
00071 args = args.split()
00072
00073 if not args:
00074 return "ERROR in RepoHeader. Usage: [[RepoHeader(repo_name [packages stacks])]]"
00075
00076 repo_name = get_unicode(macro.request, args[0])
00077 if not repo_name:
00078 return "ERROR in RepoHeader. Usage: [[RepoHeader(repo_name [packages stacks])]]"
00079 try:
00080 repo_data = load_repo_manifest(repo_name)
00081 except UtilException, e:
00082 name = repo_name
00083 return CONTRIBUTE_TMPL%locals()
00084
00085 if len(args) > 1:
00086 display_packages = 'packages' in args[1:]
00087 else:
00088 display_packages = False
00089
00090 f = macro.formatter
00091 p, url, div, br = f.paragraph, f.url, f.div, f.linebreak
00092 em, strong = f.emphasis, f.strong
00093 h, li, ul = f.heading, f.listitem, f.bullet_list
00094 text, rawHTML = f.text, f.rawHTML
00095
00096 stack_items = get_stack_items(macro, repo_data)
00097
00098 toc = ''
00099
00100 stack_names = sorted(repo_data['stacks'].iterkeys())
00101 if stack_names:
00102 toc += li(1)+text('Stacks')+ul(1)
00103 for name in sorted(stack_names):
00104 toc += li(1)+rawHTML('<a href="#%s">%s</a>'%(name, name))+li(0)
00105 toc += ul(0)+li(0)
00106
00107 package_names = sorted(repo_data['packages'].iterkeys()) if display_packages else []
00108 if package_names:
00109 toc += li(1)+text('Packages')+ul(1)
00110 for name in package_names:
00111 toc += li(1)+wiki_url(macro, name)+li(0)
00112 toc += ul(0)+li(0)
00113
00114 vcs_config = repo_data['vcs']
00115 uri = vcs_config['uri']
00116 repo_desc = h(1,2)+text(repo_name)+h(0,2)+\
00117 ul(1)+\
00118 li(1)+text('Version Control: %s '%(vcs_config['type']))+rawHTML('<a href="%s">%s</a>'%(uri, uri))+li(0)+\
00119 toc+\
00120 ul(0)
00121
00122
00123 return repo_desc+'\n'.join(stack_items)