Exemplo n.º 1
0
 def labels(self):
     """
     Return a list of "user friendly" labels.
     
     :return     <list> [ <str>, .. ]
     """
     return [self._labels.get(value) or text.pretty(key)
             for key, value in sorted(self.items(), key=lambda x: x[1])]
Exemplo n.º 2
0
    def label(self, value):
        """
        Returns a pretty text version of the key for the inputted value.

        :param      value | <variant>

        :return     <str>
        """
        return self._labels.get(value) or text.pretty(self(value))
Exemplo n.º 3
0
    def label(self, value):
        """
        Returns a pretty text version of the key for the inputted value.

        :param      value | <variant>

        :return     <str>
        """
        return self._labels.get(value) or text.pretty(self(value))
Exemplo n.º 4
0
 def labels(self):
     """
     Return a list of "user friendly" labels.
     
     :return     <list> [ <str>, .. ]
     """
     keys = self.keys()
     keys.sort(lambda x, y: cmp(self[x], self[y]))
     return [ text.pretty(key) for key in keys ]
Exemplo n.º 5
0
 def labels(self):
     """
     Return a list of "user friendly" labels.
     
     :return     <list> [ <str>, .. ]
     """
     keys = self.keys()
     keys.sort(lambda x, y: cmp(self[x], self[y]))
     return [text.pretty(key) for key in keys]
Exemplo n.º 6
0
 def labels(self):
     """
     Return a list of "user friendly" labels.
     
     :return     <list> [ <str>, .. ]
     """
     return [
         self._labels.get(value) or text.pretty(key)
         for key, value in sorted(self.items(), key=lambda x: x[1])
     ]
Exemplo n.º 7
0
    def valueByLabel(self, label):
        """
        Determine a given value based on the inputted label.

        :param      label   <str>
        
        :return     <int>
        """
        keys = self.keys()
        labels = [text.pretty(key) for key in keys]
        if label in labels:
            return self[keys[labels.index(label)]]
        return 0
Exemplo n.º 8
0
    def valueByLabel(self, label):
        """
        Determine a given value based on the inputted label.

        :param      label   <str>
        
        :return     <int>
        """
        keys = self.keys()
        labels = [text.pretty(key) for key in keys]
        if label in labels:
            return self[keys[labels.index(label)]]
        return 0
Exemplo n.º 9
0
    def displayText(self, value, blank='', joiner=', '):
        """
        Returns the display text for the value associated with
        the inputted text.  This will result in a comma separated
        list of labels for the value, or the blank text provided if
        no text is found.
        
        :param      value  | <variant>
                    blank  | <str>
                    joiner | <str>
        
        :return     <str>
        """
        if value is None:
            return ''

        labels = []
        for key, my_value in sorted(self.items(), key=lambda x: x[1]):
            if value & my_value:
                labels.append(self._labels.get(my_value, text.pretty(key)))

        return joiner.join(labels) or blank
Exemplo n.º 10
0
    def displayText(self, value, blank='', joiner=', '):
        """
        Returns the display text for the value associated with
        the inputted text.  This will result in a comma separated
        list of labels for the value, or the blank text provided if
        no text is found.
        
        :param      value  | <variant>
                    blank  | <str>
                    joiner | <str>
        
        :return     <str>
        """
        if value is None:
            return ''

        labels = []
        for key, my_value in sorted(self.items(), key=lambda x: x[1]):
            if value & my_value:
                labels.append(self._labels.get(my_value, text.pretty(key)))

        return joiner.join(labels) or blank
Exemplo n.º 11
0
def generateUserDocs(path,
                     target,
                     page=None,
                     breadcrumbs=None,
                     basepath='.',
                     title=''):
    """
    Generates the user documentation for the inputed path by \
    rendering any wiki text files to html and saving it out to the doc \
    root.
    
    :param      path            |  <str>
                target          |  <str>
                page            |  <str>
                source          |  <str>
                breadcrumbs     |  [<str>, .. ] || None
    """
    logger.info('Generating user documentation...')

    if page is None:
        page = templates.template('page.html')

    if not os.path.exists(target):
        os.mkdir(target)

    if breadcrumbs == None:
        breadcrumbs = []

    crumb_templ = templates.template('link_breadcrumbs.html')

    # setup the base crumbs
    base_url = basepath + '/..' * len(breadcrumbs)
    static_url = base_url + '/_static'
    url_handler.setRootUrl(base_url)

    # setup the title
    if not title:
        main_title = 'Home'
        if breadcrumbs:
            main_title = os.path.normpath(path).split(os.path.sep)[-1]
            main_title = text.pretty(main_title)
    else:
        main_title = title

    entry_contents = []
    has_index_file = False

    for entry in sorted(os.listdir(path)):
        filepath = os.path.join(path, entry)

        # skip the svn information
        if (entry == '.svn'):
            continue

        # check for manual index overrides
        elif (entry == 'index.wiki'):
            has_index_file = True

        # add wiki pages to the system
        elif (entry.endswith('.wiki')):
            filename = os.path.join(path, entry)
            outfilename = os.path.join(target, entry.replace('.wiki', '.html'))

            wiki_file = open(filename, 'r')
            wiki_contents = wiki_file.read()
            wiki_file.close()

            crumbs = []
            count = len(breadcrumbs)
            for i, crumb in enumerate(breadcrumbs):
                crumbs.append(crumb % (basepath + '/..' * count))

            # add the base crumb
            crumb = crumb_templ % {
                'url': '%s/index.html' % basepath,
                'text': main_title
            }
            crumbs.append(crumb)

            # add the page crumb
            crumb = crumb_templ % {'url': '#', 'text': title}
            crumbs.append(crumb)
            crumbstr = ''.join(crumbs)

            # generate the contents
            title = text.capitalizeWords(entry.split('.')[0])
            options = RENDER_OPTIONS.copy()
            options['FILENAME'] = filepath
            options['ROOT'] = base_url
            contents = wikitext.render(wiki_contents,
                                       url_handler,
                                       options=options)

            # update the environ
            environ = ENVIRON.copy()
            environ['title'] = title
            environ['contents'] = contents
            environ['base_url'] = base_url
            environ['static_url'] = static_url
            environ['breadcrumbs'] = crumbstr
            environ['navigation'] %= environ

            url = entry.replace('.wiki', '.html')
            entry_item = '<a href="%s/%s">%s</a>' % (basepath, url, title)
            entry_contents.append(entry_item)

            html = page % environ

            html_file = open(outfilename, 'w')
            html_file.write(html)
            html_file.close()

            continue

        # copy static paths
        elif (entry == '_static'):
            targetpath = os.path.join(target, '_static')

            # python26+
            try:
                ignore = shutil.ignore_patterns('.svn')
                shutil.copytree(filepath, targetpath, ignore=ignore)

            # python25-
            except AttributeError:
                shutil.copytree(filepath, targetpath)
            continue

        # include sub-documents that contain index.wiki
        elif ( os.path.isdir(filepath) and \
             os.path.exists(os.path.join(filepath, 'index.wiki')) ):
            base_name = os.path.normpath(path).split(os.path.sep)[-1]
            title = text.capitalizeWords(base_name)

            newtarget = os.path.join(target, entry)
            newcrumb = crumb_templ % {
                'url': '%s/index.html',
                'text': main_title
            }
            newcrumbs = breadcrumbs[:] + [newcrumb]

            entry_title = text.capitalizeWords(entry)
            opts = (basepath, entry, entry_title)
            entry_item = '<a href="%s/%s/index.html">%s</a>' % opts
            entry_contents.append(entry_item)

            generateUserDocs(filepath, newtarget, page, newcrumbs, basepath)

    # generate the main index file
    indexfilename = os.path.join(target, 'index.html')
    base_name = os.path.normpath(path).split(os.path.sep)[-1]

    # generate the entry html
    entry_html = ['<ul class=entries>']
    for entry in entry_contents:
        entry_html.append('<li>%s</li>' % entry)
    entry_html.append('</ul>')

    # base crumbs
    crumbs = []
    count = len(breadcrumbs)
    for i, crumb in enumerate(breadcrumbs):
        crumbs.append(crumb % (basepath + '/..' * count))

    url_handler.setRootUrl(basepath + '/..' * count)

    # add the parent crumb
    crumb = crumb_templ % {'url': '#', 'text': main_title}
    crumbs.append(crumb)

    # generate the environ
    environ = ENVIRON.copy()
    environ['title'] = main_title
    environ['base_url'] = base_url
    environ['static_url'] = static_url
    environ['breadcrumbs'] = ''.join(crumbs)
    environ['sub_pages'] = ''.join(entry_html)
    environ['navigation'] %= environ

    # include a base template
    if (not has_index_file):
        wiki_templ = templates.template('userguide.html')
    else:
        f = open(os.path.join(path, 'index.wiki'), 'r')
        wiki_txt = f.read()
        f.close()

        options = RENDER_OPTIONS.copy()
        options['FILENAME'] = indexfilename
        options['ROOT'] = base_url
        wiki_templ = wikitext.render(wiki_txt, url_handler, options=options)

    # generate the contents
    environ['contents'] = wiki_templ % environ

    html = page % environ

    # generate the index HTML
    index_file = open(indexfilename, 'w')
    index_file.write(html)
    index_file.close()
Exemplo n.º 12
0
def generateUserDocs(path,
                     target,
                     page=None,
                     breadcrumbs=None,
                     basepath='.',
                     title=''):
    """
    Generates the user documentation for the inputed path by \
    rendering any wiki text files to html and saving it out to the doc \
    root.
    
    :param      path            |  <str>
                target          |  <str>
                page            |  <str>
                source          |  <str>
                breadcrumbs     |  [<str>, .. ] || None
    """
    logger.info('Generating user documentation...')
    
    if page is None:
        page = templates.template('page.html')
    
    if not os.path.exists(target):
        os.mkdir(target)
    
    if breadcrumbs == None:
        breadcrumbs = []
    
    crumb_templ = templates.template('link_breadcrumbs.html')
    
    # setup the base crumbs
    base_url = basepath + '/..' * len(breadcrumbs)
    static_url = base_url + '/_static'
    url_handler.setRootUrl(base_url)
    
    # setup the title
    if not title:
        main_title = 'Home'
        if breadcrumbs:
            main_title = os.path.normpath(path).split(os.path.sep)[-1]
            main_title = text.pretty(main_title)
    else:
        main_title = title
    
    entry_contents = []
    has_index_file = False
    
    for entry in sorted(os.listdir(path)):
        filepath = os.path.join(path, entry)
        
        # skip the svn information
        if ( entry == '.svn' ):
            continue
        
        # check for manual index overrides
        elif ( entry == 'index.wiki' ):
            has_index_file = True
        
        # add wiki pages to the system
        elif ( entry.endswith('.wiki') ):
            filename    = os.path.join(path, entry)
            outfilename = os.path.join(target, entry.replace('.wiki','.html'))
            
            wiki_file = open(filename, 'r')
            wiki_contents = wiki_file.read()
            wiki_file.close()
            
            crumbs = []
            count  = len(breadcrumbs)
            for i, crumb in enumerate(breadcrumbs):
                crumbs.append(crumb % (basepath + '/..' * count))
            
            # add the base crumb
            crumb  = crumb_templ % {'url': '%s/index.html' % basepath,
                                    'text': main_title}
            crumbs.append(crumb)
            
            # add the page crumb
            crumb = crumb_templ % {'url': '#', 'text': title}
            crumbs.append( crumb )
            crumbstr = ''.join(crumbs)
            
            # generate the contents
            title    = text.capitalizeWords(entry.split('.')[0])
            options = RENDER_OPTIONS.copy()
            options['FILENAME'] = filepath
            options['ROOT'] = base_url
            contents = wikitext.render(wiki_contents,
                                       url_handler,
                                       options=options)
            
            # update the environ
            environ = ENVIRON.copy()
            environ['title']        = title
            environ['contents']     = contents
            environ['base_url']     = base_url
            environ['static_url']   = static_url
            environ['breadcrumbs']  = crumbstr
            environ['navigation'] %= environ
            
            url = entry.replace('.wiki', '.html')
            entry_item = '<a href="%s/%s">%s</a>' % (basepath, url, title)
            entry_contents.append( entry_item )
            
            html = page % environ
            
            html_file = open(outfilename, 'w')
            html_file.write(html)
            html_file.close()
            
            continue
        
        # copy static paths
        elif ( entry == '_static' ):
            targetpath = os.path.join(target, '_static')
            
            # python26+
            try:
                ignore   = shutil.ignore_patterns('.svn')
                shutil.copytree(filepath, targetpath, ignore=ignore)
            
            # python25-
            except AttributeError:
                shutil.copytree(filepath, targetpath)
            continue
        
        # include sub-documents that contain index.wiki
        elif ( os.path.isdir(filepath) and \
             os.path.exists(os.path.join(filepath, 'index.wiki')) ):
            base_name   = os.path.normpath(path).split(os.path.sep)[-1]
            title       = text.capitalizeWords(base_name)
            
            newtarget   = os.path.join(target, entry)
            newcrumb    = crumb_templ % {'url': '%s/index.html', 
                                         'text': main_title}
            newcrumbs   = breadcrumbs[:] + [newcrumb]
            
            entry_title = text.capitalizeWords(entry)
            opts = (basepath, entry, entry_title)
            entry_item = '<a href="%s/%s/index.html">%s</a>' % opts
            entry_contents.append( entry_item )
            
            generateUserDocs(filepath, newtarget, page, newcrumbs, basepath)
    
    # generate the main index file
    indexfilename   = os.path.join(target, 'index.html')
    base_name       = os.path.normpath(path).split(os.path.sep)[-1]
    
    # generate the entry html
    entry_html = ['<ul class=entries>']
    for entry in entry_contents:
        entry_html.append('<li>%s</li>' % entry)
    entry_html.append('</ul>')
    
    # base crumbs
    crumbs = []
    count  = len(breadcrumbs)
    for i, crumb in enumerate(breadcrumbs):
        crumbs.append(crumb % (basepath + '/..' * count))
    
    url_handler.setRootUrl(basepath + '/..' * count)
    
    # add the parent crumb
    crumb = crumb_templ % {'url': '#', 'text': main_title}
    crumbs.append(crumb)
    
    # generate the environ
    environ = ENVIRON.copy()
    environ['title']        = main_title
    environ['base_url']     = base_url
    environ['static_url']   = static_url
    environ['breadcrumbs']  = ''.join(crumbs)
    environ['sub_pages']    = ''.join(entry_html)
    environ['navigation'] %= environ
    
    # include a base template
    if ( not has_index_file ):
        wiki_templ = templates.template('userguide.html')
    else:
        f = open(os.path.join(path, 'index.wiki'), 'r')
        wiki_txt = f.read()
        f.close()
        
        options = RENDER_OPTIONS.copy()
        options['FILENAME'] = indexfilename
        options['ROOT'] = base_url
        wiki_templ = wikitext.render(wiki_txt,
                                     url_handler,
                                     options=options)
    
    # generate the contents
    environ['contents'] = wiki_templ % environ
    
    html = page % environ
    
    # generate the index HTML
    index_file = open(indexfilename, 'w')
    index_file.write(html)