Esempio n. 1
0
    def __init__(self, indent_level=3, indent_to_curr_level=1, init_pos=0,
                 init_selection = None, initial_contents="",
                 global_selection = 1, instance_reporting = 0,
                 **attrs):
        
        self.init_attrs({'lang_srv': sb_services.SB_ServiceLangServerSide(buff=self),
                         'line_srv': sb_services.SB_ServiceLineManip(buff=self),
                         'indent_srv': sb_services.SB_ServiceIndent(buff=self, indent_level=3, indent_to_curr_level = 1)
                         })

        self.deep_construct(SourceBuffEdSim,
                            {'pos': init_pos, 
                             'selection': init_selection, 
                             'content': initial_contents, 
                             'global_selection': global_selection,
                             'indent_level': indent_level,
                             'indent_to_curr_level': indent_to_curr_level,
                             'instance_reporting': instance_reporting }, 
                            attrs
                            )

        self.add_owned_list(['indent_srv', 'line_srv', 'lang_srv'])

        if self.instance_reporting:
            print 'SourceBuff.__init__:', util.within_VCode(self.name())
        self.pos = self.make_within_range(self.pos)
        if not self.selection:
            self.selection = (self.pos, self.pos)
        s, e = self.get_selection()
        if (s < e):
            self.selection = (self.pos, self.pos)
Esempio n. 2
0
    def do_test_resulting_website(self, lang, all_lang=None, curr_context=None, comment=None):
        """make the website for these paramters and check against previous result.

         if curr_context = 1, a context should have been setup first, and comment gives a clue
         to the correct folder to check against.

         only test html files         

         if no html files present in folder, copy result into the folder and assume the result is correct

         if language has changed/added, recopy from  (...)\\Data\whatCanISay to
                  (...)\Data\Benchmark\WhatCanISayTestResults, and to subdir all_lang or other...
         to: 

        """         
        html_folder= self.wciSay.html_folder

        html_files = glob.glob(os.path.join(html_folder, "*.html"))
        for f in html_files:
            os.remove(f)
        
        self.wciSay.load_commands_from_interpreter(self._app(), self.interp, lang,
                                                    all_lang=all_lang, curr_context=curr_context)
        self.wciSay.create_cmds()
        self.wciSay.create_html_pages()

        test_home = vc_globals.wcisay_test_folder
        self.assert_(os.path.isdir(test_home), "No valid folder for testing the resulting websites")
        if all_lang:
            test_folder = os.path.join(test_home, "all_lang")
        elif curr_context:
            test_folder = os.path.join(test_home, lang + "_curr_context_" + comment or "")
        else:
            test_folder = os.path.join(test_home, lang)
           
        if os.path.isdir(test_folder):
##            print 'using test folder: %s'% test_folder
            old_files = glob.glob(os.path.join(test_folder , "*.html"))
            if not old_files:
                print 'empty folder for language %s assume correct results, copy to %s'% \
                      (lang, util.within_VCode(test_folder))
                self.copy_html_files(html_folder, test_folder)
                return
        else:
            print 'no test folder yet for language %s, assume correct results, copy to %s'% \
                  (lang, test_folder)
            self.copy_html_files(html_folder, test_folder)
            return
        
        self.assert_equal_html_files(test_folder, html_folder,
                                      'WhatCanISay website of language %s (with all_lang: %s, curr_context: %s, comment: %s'%
                                      (lang, all_lang, curr_context, comment))
Esempio n. 3
0
    def create_html_folder(self):
        """create a folder for the WhatCanISay website

        this foldername is also returned
        """
        self.html_folder = vc_globals.wcisay_html_folder

        try:
            os.makedirs(self.html_folder)
            print 'WARNING: whatCanISay folder did not exist, stylesheet will not be available'
        except:
            pass
        if not os.path.isdir(self.html_folder):
            raise Exception('not a valid directory for What Can I Say website: %s'% \
                            util.within_VCode(self.html_folder))
        return self.html_folder
Esempio n. 4
0
    def remove_other_references(self):
        """additional cleanup to ensure that this object's references to
        its owned objects are the last remaining references

        **INPUTS**

        *none*

        **OUTPUTS**

        *none*
        """
# subclasses must call their parent class's remove_other_references
# function, after performing their own duties
        if self.instance_reporting:
            print 'SourceBuff.remove_other_references:', util.within_VCode(self.name())
        SourceBuffNonCached.SourceBuffNonCached.remove_other_references(self)
Esempio n. 5
0
    def html_command_index(self):
        """make the index page of the website"""
        doc = SimpleDocument()
        doc.stylesheet = "vc.css"
        page = "index.html"
        page_type = "index"
        page_html = "index.html"
        doc.append(self.html_header(page, part=page_type, detail="home"))
        tlpage = FullTable(Class="page")
        trpage = TR()
        tdpage = TD(Class="body")
        # produce the menu (left):
        # produce the body:
        VcodeWebsite = Href(
            "http://voicecode.iit.nrc.ca/VoiceCode/public/ywiki.cgi", "Voice Code website", target="_blank"
        )

        text = [
            "This is the What Can I Say (actual) information of your VoiceCode instance.",
            "",
            'By default (with "yo what can I say") you get information for the current programming language, excluding common commands like punctuation and navigation on punctuation.',
            "",
            'If you call "yo what can I say now" only commands that apply at the moment you call this command will be shown.<br>(Note: this information does not go through exactly the same routine, so could differ from the real information.)',
            ""
            'If you call "yo what can I say all" all information is shown, including "common" commands, and for all languages available.',
            "",
            "",
            "",
            "",
            "For the general information please consult the " + VcodeWebsite + ".",
            "",
            "",
        ]
        for t in text:
            if t:
                tdpage.append(Paragraph(t))
            else:
                tdpage.append(Paragraph("&nbsp;", Class="blank"))
        doc.append(tlpage(trpage(tdpage)))
        doc.append(self.html_footer(page, part=page_type, nice_name="home"))
        outfile = os.path.join(self.html_folder, "index.html")

        trace("WhatCanISay.files", "making page: %s" % util.within_VCode(outfile))
        doc.write(outfile)
        return outfile
Esempio n. 6
0
def compilation_test(interp, source):
    
    """Does a compilation test on file *source*        
    """
    print '*** Compiling symbols from file: %s ***' % util.within_VCode(source)
    interp.cleanup_dictionary()
    interp.parse_symbols_from_file(source)
    print '\n\nParsed symbols are: '
    interp.print_symbols()
    print 'Unresolved abbreviations are:'
    unresolved = interp.peek_at_unresolved()
    sorted_unresolved = unresolved.keys()
    sorted_unresolved.sort()
    for an_abbreviation in sorted_unresolved:
        symbol_list = unresolved[an_abbreviation].keys()
        symbol_list.sort()
        print '\'%s\': appears in %s' % (an_abbreviation, str(symbol_list))
        
    print '\n*** End of compilation test ***\n'
Esempio n. 7
0
    def html_detail_page(self, page, part, detail):
        """generate a detail page on one setname"""
        
        doc = SimpleDocument()
        doc.stylesheet = "vc.css"
        page_type = part
        page_html = page


        
        trace('WhatCanISay.html_detail_page', 'page: %s, part: %s, detail: %s'%
              (page, part, detail))

        content = self.index[part]
        keys = [k for (k, v) in content.items() if self.has_setname(v, detail)]
        keys.sort()
        trace('WhatCanISay.html_detail_page', 'keys:  %s'% keys)
        doc.append(self.html_header(page, part=page_type, detail=detail))

        if 1:
            tlpage = FullTable(Class="page")
##            doc.append(Header(1, 'begin of csc commands, python'))
            trpage = TR()

            # produce the menu (left):
            leftMenu = self.get_left_menu(page, part)
            trpage.append(leftMenu)
            
            # now the contents:        
            tl = FullTable(Class="body")
            tr = TR()
            cell_num = 0
            tdspacer = TD("&nbsp;", Class="spacer")
            all_meanings = {}  #of tuples 1: list of keys
                               #          2: the item
            # collect in all_meanings:            
            for k in keys:
                the_key = ''
                item = content[k]
                for meaning in item:
                    if self.info_is_csc(meaning):
                        m = meaning[0]
                        cont = m['equiv']
                        scope = m['scope']
                        action = m['action']
                        if action == 'no docstring available':
                            if m['doc']:
                                action = m['doc']
                    elif self.info_is_lsa(meaning):
                        cont = 'lsa'
                        scope = ''
                        action = meaning.get('written_form','')
                    the_key += action + scope + cont
                if the_key in all_meanings:
                    all_meanings[the_key][0].append(k)
                else:
                    all_meanings[the_key] = ([k], item)


            meaning_keys = all_meanings.keys()
            meaning_keys.sort()
            for k in meaning_keys:
                Keys, Meanings = all_meanings[k]
                
                cell_num += 1
                class_name = "written%s"% (cell_num%2,)
                
                trmeanings = []
                rows_inside = 0
                meaning_num = 0
                for meaning in Meanings:
                    if self.info_is_csc(meaning):
                        for m in meaning:
                            meaning_num += 1
                            class_name_meanings = "%s%s"% (class_name, meaning_num%2)
                            cont = m['equiv']
                            scope = m['scope']
                            action = m['action']
                            if action == 'no docstring available':
                                if m['doc']:
                                    action = m['doc']

                            trmeanings.append(self.fill_row(cont, scope, action, class_name_meanings))
                            rows_inside += 1
                    elif self.info_is_lsa(meaning):
                        meaning_num += 1
                        class_name_meanings = "%s%s"% (class_name, meaning_num%2)
                        cont = 'lsa'
                        scope = ''
                        action = meaning.get('written_form','')
                        trmeanings.append(self.fill_row(cont, scope, action, class_name_meanings))
                        rows_inside += 1

                    else:
                        raise ValueError("WhatCanISay, invalid meaning at key: %s (%s)"%
                                         (Keys, `meaning`))
                key_part = []
                Keys.sort()
                for spoken in Keys:
                    anchorname = self.get_anchor(spoken)
                    anchor = '<a name="%s">'% anchorname
                    spoken = spoken.replace(' ', "&nbsp;")
                    key_part.append(anchor+spoken+"</a>")
                trmeanings[0].prepend(TD('<br>'.join(key_part), Class=class_name, rowspan=rows_inside))
                for tr in trmeanings:
                    tl.append(tr)
        
            trpage.append(TD(tl, Class="body"))
            tlpage.append(trpage)
            doc.append(tlpage)
            doc.append(self.html_footer(page, part=page_type, nice_name=detail))
        outfile = os.path.join(self.html_folder, page_html)
        trace('WhatCanISay.files', 'making page: %s'% util.within_VCode(outfile))
        doc.write(outfile)
Esempio n. 8
0
    def html_overview_page(self, page, part):
        """generate a overview page of all commands in a language"""
        doc = SimpleDocument()
        doc.stylesheet = "vc.css"

        index = self.index[part]
        names = index.keys()
        names.sort()
        left_menu = self.left_menu[part]
        page_html = page
        
        content = names
        
        doc.append(self.html_header(page, part, 'overview'))
        tlpage = FullTable(Class="page")
        trpage = TR()
        # produce the menu (left):
        leftMenu = self.get_left_menu(page, part)
        trpage.append(leftMenu)

        # now the contents:        
        tl = FullTable(Class="body")
        tr = TR()
        # define in top, possibly configure in vc_config or user_config.
        per_col = self.number_of_columns
        tdspacer = TD("&nbsp;", Class="spacer")
        rows = len(content)/per_col
        if len(content)%per_col:
            rows += 1
        cell_num = 0
        
        for start in range(rows):
            cell_num = start % 2
            for col in range(start, len(content), rows):
                cell_num += 1
                k = content[col]
                setnames = self.get_setnames(index[k])
                links = []
                nice_names = []
                for s in setnames:
                    if s in left_menu:
                        links.append(left_menu[s])
                        nice_names.append(s)
                    else:
                        raise ValueError("WhatCanISay, setname not in left menu: %s (key: %s)"%
                                         (s, k))
                if not links:
                    tr.append(TD(k, Class="written%s"% (cell_num%2,)))
                elif len(links) == 1:
                    anchor = self.get_anchor(k)
                    link = '%s#%s'% (links[0], anchor)
                    link = Href(link, k)
                    tr.append(TD(link, Class="written%s"% (cell_num%2,)))
                else:
                    to = []
                    for link, nice in zip(links, nice_names):
                        # more entries!!!!!
                        anchor = self.get_anchor(k)
                        the_link = '%s#%s'% (link, anchor)
                        text = "%s (%s)"% (k, nice)
                        link = Href(link, text)
                        to.append(str(link))
                    tr.append(TD('<br>'.join(to), Class="written%s"% (cell_num%2,)))
                        
                tr.append(tdspacer())
            tl.append(tr)
            tr.empty()
        
        trpage.append(TD(tl, Class="body"))
        tlpage.append(trpage)
        doc.append(tlpage)
        doc.append(self.html_footer(page, part=part, nice_name=part))
        outfile = os.path.join(self.html_folder, page_html)
        trace('WhatCanISay.files', 'making page: %s'% util.within_VCode(outfile))
        doc.write(outfile)
        return outfile
Esempio n. 9
0
 def __del__(self):
     "destructor"
     if self.instance_reporting:
         print 'SourceBuff.__del__:', util.within_VCode(self.name())