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