Beispiel #1
0
    def post_process(self):
        protocol = getkey(self.arguments, 'protocol', 'scp')
        G.debug(''.join(['Protocol for publishing is ', protocol]))
        if protocol == 'scp':
            src = getkey(self.globalvars, 'outputfile', False)
            dst = getkey(self.arguments, 'uri', False)
            if src and dst:
                G.info(''.join(['Doing scp from ', src, ' to ', dst, '.']))
                call(['scp', src, dst])
                G.info('Done doing scp')
            else:
                G.error("You must specify a uri")

            # Also backup source if "src" param is specified
            src = getkey(self.globalvars, 'filename', False)
            dst = getkey(self.arguments, 'backup', False)
            if src and dst:
                G.info(''.join(['Doing scp from ', src, ' to ', dst, '.']))
                call(['scp', src, dst])
                G.info('Done doing scp')
            else:
                G.info("Skipping source copy, missing src param")

        else:
            G.error("Only scp is currently supported")
Beispiel #2
0
    def perform_wrapping(self):
        G.info('Starting wrapping.')
        self.globalvars['body'] = ''
        self.globalvars['style'] = ''
        self.globalvars['prescript'] = ''
        self.globalvars['script'] = ''
        for obj in self.objects:
            if not obj.removed:
                if len(obj.body): 
                    self.globalvars['body'] = u'\n'.join([self.globalvars['body'], obj.body])
                if len(obj.style): 
                    self.globalvars['style'] = u'\n'.join([self.globalvars['style'], obj.style])
                if len(obj.prescript): 
                    self.globalvars['prescript'] = u'\n'.join([self.globalvars['script'], obj.script])
                if len(obj.script): 
                    self.globalvars['script'] = u'\n'.join([self.globalvars['script'], obj.script])
        templates = getkey(self.globalvars, '$Templates', {})
        for tname in templates:
            G.debug('Adding template to style/script for '+tname)
            template = getkey(templates, tname, {})
            self.globalvars['style'] = '\n'.join([self.globalvars['style'], getkey(template, 'style')])
            self.globalvars['prescript'] = '\n'.join([self.globalvars['prescript'], getkey(template, 'prescript')])
            #self.globalvars['script'] = '\n'.join([self.globalvars['script'], getkey(template, 'script')])

        wrapper = getkey(self.globalvars, '$Wrapper', False)
        if wrapper:
            wrapper.process()
            self.document = wrapper.body
        else:
            G.critical("No wrapper registered")
            self.document = u'no wrapper'
        G.info('Finished wrapping.')
Beispiel #3
0
    def post_process(self):
        protocol = getkey(self.arguments, 'protocol', 'scp')
        G.debug(''.join(['Protocol for publishing is ', protocol]))
        if protocol == 'scp':
            src = getkey(self.globalvars, 'outputfile', False)
            dst = getkey(self.arguments, 'uri', False)
            if src and dst:
                G.info(''.join(['Doing scp from ',src,' to ',dst,'.']))
                call(['scp', src, dst])
                G.info('Done doing scp')
            else:
                G.error("You must specify a uri")

            # Also backup source if "src" param is specified
            src = getkey(self.globalvars, 'filename', False)
            dst = getkey(self.arguments, 'backup', False)
            if src and dst:
                G.info(''.join(['Doing scp from ',src,' to ',dst,'.']))
                call(['scp', src, dst])
                G.info('Done doing scp')
            else:
                G.info("Skipping source copy, missing src param")

        else:
            G.error("Only scp is currently supported")
Beispiel #4
0
 def pre_process(self):
     # Export variables
     if (u'title' in self.arguments.keys() or not u'title' in self.globalvars.keys()):
         self.globalvars['title'] = getkey(self.arguments, u'title', 'Doc') 
     if (u'subtitle' in self.arguments.keys() or not u'subtitle' in self.globalvars.keys()):
         self.globalvars[u'subtitle'] = getkey(self.arguments, u'subtitle')
     if (u'author' in self.arguments.keys() or not u'author' in self.globalvars.keys()):
         self.globalvars[u'author'] = getkey(self.arguments, u'author')
     if (u'date' in self.arguments.keys() or not u'date' in self.globalvars.keys()):
         self.globalvars[u'date'] = getkey(self.arguments, u'date', getkey(self.globalvars,u'date',''))
Beispiel #5
0
 def pre_process(self):
     _from = getkey(self.arguments, 'primary', False)
     _to = getkey(self.arguments, 'to', False)
     _lang = getkey(self.arguments, 'language', 'en')
     if (not _from and _to):
         G.error('Translate must have both from and to arguments')
         return
     if (not _lang in getkey(self.globalvars, '$i18n', {})):
         self.globalvars['$i18n'][_lang] = {_from: _to}
     else:
         self.globalvars['$i18n'][_lang][_from] = _to
Beispiel #6
0
 def post_upgrade(self):
     G.info(''.join(['Doing post upgrade when globalvars = ',str(self.globalvars)]))
     G.info(''.join(['Content -> output will be: ',self.content]))
     ss = SyntaxSugarDefinition(
             getkey(self.arguments, 'pattern'),
             getkey(self.arguments, 'params').split(','),
             self.content
             )
     if not ss.broken:
         self.globalvars['$SyntaxSugar'].append(ss)
         G.info('Added SyntaxSugar.')
     else:
         G.warn('SyntaxSugar was broken.')
Beispiel #7
0
 def post_upgrade(self):
     G.info(''.join(
         ['Doing post upgrade when globalvars = ',
          str(self.globalvars)]))
     G.info(''.join(['Content -> output will be: ', self.content]))
     ss = SyntaxSugarDefinition(getkey(self.arguments, 'pattern'),
                                getkey(self.arguments, 'params').split(','),
                                self.content)
     if not ss.broken:
         self.globalvars['$SyntaxSugar'].append(ss)
         G.info('Added SyntaxSugar.')
     else:
         G.warn('SyntaxSugar was broken.')
Beispiel #8
0
    def process(self):
        template_name = getkey(self.arguments, 'template', self.object_name)
        template = getkey(self.globalvars['$Templates'], template_name)
        self.body = unicode(getkey(template, 'body'))
        self.pre_process()

        self.body = self.body.replace('%content%', unicode(self.content))
        
        G.debug(self.globalvars['$Labels'])
        self.body = varsub(self.body, 
                           [self.localvars,
                           self.arguments,
                           self.globalvars],
                           getkey(self.globalvars, '$Templates', False),
                           recursive=getkey(self.arguments, 'substitute', 'yes') != 'no')
Beispiel #9
0
 def pre_process(self):
     # Export variables
     if (u'title' in self.arguments.keys()
             or not u'title' in self.globalvars.keys()):
         self.globalvars['title'] = getkey(self.arguments, u'title', 'Doc')
     if (u'subtitle' in self.arguments.keys()
             or not u'subtitle' in self.globalvars.keys()):
         self.globalvars[u'subtitle'] = getkey(self.arguments, u'subtitle')
     if (u'author' in self.arguments.keys()
             or not u'author' in self.globalvars.keys()):
         self.globalvars[u'author'] = getkey(self.arguments, u'author')
     if (u'date' in self.arguments.keys()
             or not u'date' in self.globalvars.keys()):
         self.globalvars[u'date'] = getkey(
             self.arguments, u'date', getkey(self.globalvars, u'date', ''))
Beispiel #10
0
    def post_upgrade(self):
        template = getkey(self.arguments, 'primary')
        G.info(''.join(['Reading template object ', template]))
        
        if not template in self.globalvars['$Templates']:
            self.globalvars['$Templates'][template] = {}

        output = getkey(self.arguments, 'output', getkey(self.globalvars, 'output', 'html'))
        place = getkey(self.arguments, 'place', 'body')

        if output == getkey(self.globalvars, 'output', 'html'):
            G.info(''.join(['Loading template object as ', template, '/', output, '/', place]))
            self.globalvars['$Templates'][template][place] = self.content

        self.removed = True
Beispiel #11
0
    def pre_process(self):
        # Do heading and toc stuff here
        if self.arguments.has_key('level'):
            self.localvars['level'] = self.arguments['level']
        else:
            self.localvars['level'] = '2'
        G.debug(''.join(['Level set to ', self.localvars['level']]))

        if self.arguments.has_key('primary'):
            self.localvars['title'] = self.arguments['primary']
        G.debug(''.join(['Title set to ', self.localvars['title']]))

        # Store title to TOC
        if u'label' in self.arguments:
            self.localvars['safe_title'] = self.arguments[u'label']
            self.globalvars['$Labels'][self.arguments[u'label']] = {
                'id': self.localvars['safe_title'],
                'caption': getkey(self.localvars, 'title', 'title missing'),
            }
        else:
            self.localvars['safe_title'] = safe_link(
                getkey(self.localvars, 'title', 'title missing'))
        counter_tick(self.globalvars['$Counters'],
                     ''.join(['toc', str(self.localvars['level'])]))
        tocitem = {
            'safe_title':
            self.localvars['safe_title'],
            'link':
            '#%s' % self.localvars['safe_title'],
            'title':
            self.localvars['title'],
            'level':
            self.localvars['level'],
            'numbering':
            varsub(''.join(['%numbering', self.localvars['level'], '%']),
                   [self.globalvars], [])
        }
        self.localvars['numbering'] = tocitem['numbering']

        if (int(self.localvars['level']) <= int(
                getkey(self.globalvars, 'toc_depth', 3))):
            self.globalvars['$TOC'].append(tocitem)
        if (int(self.localvars['level']) <= int(
                getkey(self.globalvars, 'alt_toc_depth', 3))):
            self.globalvars['$ALTTOC'].append(tocitem)

        return True
Beispiel #12
0
    def pre_process(self):
        # Do heading and toc stuff here
        if self.arguments.has_key('level'):
            self.localvars['level'] = self.arguments['level']
        else:
            self.localvars['level'] = '2'
        G.debug(''.join(['Level set to ',self.localvars['level']]))
        
        if self.arguments.has_key('primary'):
            self.localvars['title'] = self.arguments['primary']
        G.debug(''.join(['Title set to ',self.localvars['title']]))
        
        # Store title to TOC
        if u'label' in self.arguments:
            self.localvars['safe_title'] = self.arguments[u'label']
            self.globalvars['$Labels'][self.arguments[u'label']] = {
                'id':  self.localvars['safe_title'],
                'caption': getkey(self.localvars,'title','title missing'),
            }
        else:
            self.localvars['safe_title'] = safe_link(
                getkey(self.localvars,'title','title missing'))
        counter_tick(self.globalvars['$Counters'],
                     ''.join(['toc',str(self.localvars['level'])]))
        tocitem = { 'safe_title': self.localvars['safe_title'],
                    'link': '#%s' % self.localvars['safe_title'],
                    'title': self.localvars['title'],
                    'level': self.localvars['level'],
                    'numbering': varsub(
                        ''.join(['%numbering',
                                 self.localvars['level'],
                                 '%']),
                        [self.globalvars],
                        [])
                  }
        self.localvars['numbering'] = tocitem['numbering']

        if (int(self.localvars['level']) <= 
            int(getkey(self.globalvars, 'toc_depth', 3))):
            self.globalvars['$TOC'].append(tocitem)
        if (int(self.localvars['level']) <= 
            int(getkey(self.globalvars, 'alt_toc_depth', 3))):
            self.globalvars['$ALTTOC'].append(tocitem)
        

        return True
Beispiel #13
0
    def pre_process(self):
        G.debug(''.join(['Doing post upgrade when globalvars = ',str(self.globalvars)]))
        filename = getkey(self.arguments,'primary', False)
        if not filename:
            G.error('No filename specified, skipping Input')
            return
        G.info(''.join(['Inserting ', filename]))
        p = None
        if os.path.isfile(getkey(self.globalvars,'root')+filename):
            p = Processor.Processor(getkey(self.globalvars,'root'), filename, _is_main_file=False)
        if os.path.isfile(getkey(self.globalvars,'root')+'templates/'+filename):
            p = Processor.Processor(getkey(self.globalvars,'root')+'templates/', filename, _is_main_file=False)
        elif os.path.isfile(getkey(self.globalvars,'templatedir')+filename):
            p = Processor.Processor(getkey(self.globalvars,'templatedir'), filename, _is_main_file=False)
        elif os.path.isfile(G.template_dir+filename):
            p = Processor.Processor(G.template_dir, filename, _is_main_file=False)
        else:
            G.error('Could not find file requested by Input: '+filename)
            return

        # Use the uppermost globalvars dictionary
        p.globalvars = self.globalvars

        # Load the objects
        if p.init_file():
            p.load_objects()
            p.close_file()
        
        # Copy objects from the processor to the object
        self.sub_objects = p.objects
        G.debug(''.join(['Input objects are: ', p.get_objects_as_string()]))

        self.removed = True
Beispiel #14
0
 def post_upgrade(self):
     # I am not sure this is needed, they can be treated as normal objects,
     # as long as they possible to look up.
     # Register me as subprocessor
     G.info('Registering myself as inline subprocessor')
     sp = getkey(self.globalvars, '$Subprocessors', [])
     sp.append(self)
     self.globalvars['$Subprocessors'] = sp
     self.localvars['$Accepts'] = ['Paragraph']  # is this the right place?
     return
Beispiel #15
0
 def pre_process(self):
     if (getkey(self.arguments, 'primary', '') == u'figures'):
         self.localvars['caption'] = u'__table_of_figures__'
         self.localvars['tocname'] = 'TOF'
     elif (getkey(self.arguments, 'primary', '') == u'tables'):
         self.localvars['caption'] = u'__table_of_tables__'
         self.localvars['tocname'] = 'TOT'
     elif (getkey(self.arguments, 'primary', '') == u'alt'):
         self.localvars['caption'] = u'__table_of_tables__'
         self.localvars['tocname'] = 'ALTTOC'
         self.globalvars['alt_toc_depth'] = getkey(self.arguments, 'depth', 3)
     else:
         self.localvars['caption'] = u'__table_of_contents__'
         self.localvars['tocname'] = 'TOC';
         self.globalvars['toc_depth'] = getkey(self.arguments, 'depth', 3)
     if self.arguments.get('caption',False):
         self.localvars['caption'] = self.arguments.get('caption',False);
     self.needs_rerun = not self.needs_rerun
     return True
Beispiel #16
0
 def post_upgrade(self):
     # I am not sure this is needed, they can be treated as normal objects,
     # as long as they possible to look up.
     # Register me as subprocessor
     G.info('Registering myself as inline subprocessor')
     sp = getkey(self.globalvars, '$Subprocessors', [])
     sp.append(self)
     self.globalvars['$Subprocessors'] = sp
     self.localvars['$Accepts'] = ['Paragraph'] # is this the right place?
     return
Beispiel #17
0
 def process(self):
     template_name = getkey(self.arguments, 'template', self.object_name)
     template = getkey(self.globalvars['$Templates'], template_name)
     self.body = getkey(template, 'wrapper')
     self.pre_process()
     # Insert localvars
     for k in self.localvars:
         G.debug(''.join(['Replacing localvar: ',str(k),'.']))
         self.body = self.body.replace(''.join(['%',str(k),'%']),unicode(self.localvars[k])) 
     # Insert arguments
     for k in self.arguments:
         G.debug(''.join(['Replacing argument: ',str(k),'.']))
         self.body = self.body.replace(''.join(['%',str(k),'%']),unicode(self.arguments[k])) 
     # Insert globalvars
     for k in self.globalvars:
         if not k[0] == '$': # non-string start with $
             G.debug(''.join(['Replacing globalvar: ',str(k),'.']))
             self.body = self.body.replace(''.join(['%',str(k),'%']),unicode(self.globalvars[k])) 
     # Insert content
     G.debug(''.join(['Calculated body: ', self.body]))
Beispiel #18
0
    def perform_wrapping(self):
        G.info('Starting wrapping.')
        self.globalvars['body'] = ''
        self.globalvars['style'] = ''
        self.globalvars['prescript'] = ''
        self.globalvars['script'] = ''
        for obj in self.objects:
            if not obj.removed:
                if len(obj.body):
                    self.globalvars['body'] = u'\n'.join(
                        [self.globalvars['body'], obj.body])
                if len(obj.style):
                    self.globalvars['style'] = u'\n'.join(
                        [self.globalvars['style'], obj.style])
                if len(obj.prescript):
                    self.globalvars['prescript'] = u'\n'.join(
                        [self.globalvars['script'], obj.script])
                if len(obj.script):
                    self.globalvars['script'] = u'\n'.join(
                        [self.globalvars['script'], obj.script])
        templates = getkey(self.globalvars, '$Templates', {})
        for tname in templates:
            G.debug('Adding template to style/script for ' + tname)
            template = getkey(templates, tname, {})
            self.globalvars['style'] = '\n'.join(
                [self.globalvars['style'],
                 getkey(template, 'style')])
            self.globalvars['prescript'] = '\n'.join(
                [self.globalvars['prescript'],
                 getkey(template, 'prescript')])
            #self.globalvars['script'] = '\n'.join([self.globalvars['script'], getkey(template, 'script')])

        wrapper = getkey(self.globalvars, '$Wrapper', False)
        if wrapper:
            wrapper.process()
            self.document = wrapper.body
        else:
            G.critical("No wrapper registered")
            self.document = u'no wrapper'
        G.info('Finished wrapping.')
Beispiel #19
0
 def post_upgrade(self):
     primary = getkey(self.arguments, 'primary')
     if not primary == '':
         G.info(''.join(['Creating a dummy object of type ', primary]))
         obj = Generic(
                 self.globalvars,
                 [''.join([primary,':'])] + self.lines[1:]
                 )
         obj.setup()
         G.debug('\n'.join(['DUMPING DUMMY OBJECT', obj.dump()]))
     else:
         G.critical(''.join('Missing argument: primary'))
     self.removed = True # This object's purpose is done
Beispiel #20
0
 def init_file(self):
     self.first_lines = list(getkey(G.first_lines, self.output, [])) if self.is_main_file else []
     self.filepath = ''.join([self.root,self.filename])
     self.lineno = 0
     G.info(''.join(['Trying to open file "',self.filepath,'".']))
     try:
         self.file = io.open(self.filepath, 'r')
     except IOError:
         G.critical(''.join(['The file "',self.filepath,'" could not be opened.']))
         return False
     else:
         G.info(''.join(['The file "',self.filepath,'" was opened.']))
         return True
Beispiel #21
0
 def process(self):
     template_name = getkey(self.arguments, 'template', self.object_name)
     template = getkey(self.globalvars['$Templates'], template_name)
     self.body = getkey(template, 'wrapper')
     self.pre_process()
     # Insert localvars
     for k in self.localvars:
         G.debug(''.join(['Replacing localvar: ', str(k), '.']))
         self.body = self.body.replace(''.join(['%', str(k), '%']),
                                       unicode(self.localvars[k]))
     # Insert arguments
     for k in self.arguments:
         G.debug(''.join(['Replacing argument: ', str(k), '.']))
         self.body = self.body.replace(''.join(['%', str(k), '%']),
                                       unicode(self.arguments[k]))
     # Insert globalvars
     for k in self.globalvars:
         if not k[0] == '$':  # non-string start with $
             G.debug(''.join(['Replacing globalvar: ', str(k), '.']))
             self.body = self.body.replace(''.join(['%', str(k), '%']),
                                           unicode(self.globalvars[k]))
     # Insert content
     G.debug(''.join(['Calculated body: ', self.body]))
Beispiel #22
0
 def init_file(self):
     self.first_lines = list(getkey(G.first_lines, self.output,
                                    [])) if self.is_main_file else []
     self.filepath = ''.join([self.root, self.filename])
     self.lineno = 0
     G.info(''.join(['Trying to open file "', self.filepath, '".']))
     try:
         self.file = io.open(self.filepath, 'r')
     except IOError:
         G.critical(''.join(
             ['The file "', self.filepath, '" could not be opened.']))
         return False
     else:
         G.info(''.join(['The file "', self.filepath, '" was opened.']))
         return True
Beispiel #23
0
 def process_object_queue(self):
     G.info('Starting queue processing.')
     subprocessors = getkey(self.globalvars, '$Subprocessors', [])
     while(len(self.process_queue)):
         obj = self.process_queue.pop(0)
         if not obj.removed:
             G.info(''.join(['Processing object of type ', obj.object_name]))
             for sp in subprocessors:
                 new_objects = sp.run(obj)
                 if len(new_objects):
                     for no in new_objects:
                         self.objects.append(no)
                         self.process_queue.append(no)
                     obj.needs_rerun = True
             obj.process()
             if obj.needs_rerun:
                 G.debug('Reputting object %s' % obj.__class__)
                 self.process_queue.append(obj)
     G.info('Finished queue processing.')
Beispiel #24
0
    def pre_process(self):
        G.debug(''.join(
            ['Doing post upgrade when globalvars = ',
             str(self.globalvars)]))
        filename = getkey(self.arguments, 'primary', False)
        if not filename:
            G.error('No filename specified, skipping Input')
            return
        G.info(''.join(['Inserting ', filename]))
        p = None
        if os.path.isfile(getkey(self.globalvars, 'root') + filename):
            p = Processor.Processor(getkey(self.globalvars, 'root'),
                                    filename,
                                    _is_main_file=False)
        if os.path.isfile(
                getkey(self.globalvars, 'root') + 'templates/' + filename):
            p = Processor.Processor(getkey(self.globalvars, 'root') +
                                    'templates/',
                                    filename,
                                    _is_main_file=False)
        elif os.path.isfile(getkey(self.globalvars, 'templatedir') + filename):
            p = Processor.Processor(getkey(self.globalvars, 'templatedir'),
                                    filename,
                                    _is_main_file=False)
        elif os.path.isfile(G.template_dir + filename):
            p = Processor.Processor(G.template_dir,
                                    filename,
                                    _is_main_file=False)
        else:
            G.error('Could not find file requested by Input: ' + filename)
            return

        # Use the uppermost globalvars dictionary
        p.globalvars = self.globalvars

        # Load the objects
        if p.init_file():
            p.load_objects()
            p.close_file()

        # Copy objects from the processor to the object
        self.sub_objects = p.objects
        G.debug(''.join(['Input objects are: ', p.get_objects_as_string()]))

        self.removed = True
Beispiel #25
0
 def process_object_queue(self):
     G.info('Starting queue processing.')
     subprocessors = getkey(self.globalvars, '$Subprocessors', [])
     while (len(self.process_queue)):
         obj = self.process_queue.pop(0)
         if not obj.removed:
             G.info(''.join(['Processing object of type ',
                             obj.object_name]))
             for sp in subprocessors:
                 new_objects = sp.run(obj)
                 if len(new_objects):
                     for no in new_objects:
                         self.objects.append(no)
                         self.process_queue.append(no)
                     obj.needs_rerun = True
             obj.process()
             if obj.needs_rerun:
                 G.debug('Reputting object %s' % obj.__class__)
                 self.process_queue.append(obj)
     G.info('Finished queue processing.')
Beispiel #26
0
    def pre_process(self):
        if self.needs_rerun:
            self.needs_rerun = False
            return
        if not getkey(self.arguments, 'style'):
            self.arguments['style'] = getkey(self.arguments, 'primary', u'-') 

        bullet = '- '
        if self.arguments['style'] == u'-':
            bullet = '- '
        elif self.arguments['style'] == u'...':
            bullet = '...'
        
        if getkey(self.arguments, 'format', '') == 'snippet':
            if not 'bullet1' in self.arguments:
                self.arguments['bullet1'] = ''
            if not 'bullet2' in self.arguments:
                self.arguments['bullet2'] = ''
            if not 'bullet3' in self.arguments:
                self.arguments['bullet3'] = '__bullet1__'
            if not 'bullet4' in self.arguments:
                self.arguments['bullet4'] = '__bullet2__'

        # Defaults
        self.localvars['bullet1'] = getkey(self.arguments, 'bullet1', '__bullet1__') 
        self.localvars['bullet2'] = getkey(self.arguments, 'bullet2', '__bullet2__') 
        self.localvars['bullet3'] = getkey(self.arguments, 'bullet3', '__bullet3__') 
        self.localvars['bullet4'] = getkey(self.arguments, 'bullet4', '__bullet4__') 

        items = []
        for line in self.content.split("\n"):
            re_def = '^(\*+) '
            m = re.match(re_def, line)
            if m:
                level = len(m.group(1))
                caption = unicode(line[level+1:].strip())
                items.append({'level': level, 'caption': caption, 'bullet': bullet})
            elif len(items): # broken lines should be appended to the last added item
                items[len(items)-1]['caption'] = ''.join([items[len(items)-1]['caption'], ' ', line.strip()])
        self.localvars['$Items'] = items 

        self.needs_rerun = not self.needs_rerun 
Beispiel #27
0
    def pre_process(self):
        if not getkey(self.arguments, 'file'):
            self.arguments['file'] = getkey(self.arguments, 'primary', u'')
        filename = getkey(self.arguments, 'file')
        if not getkey(self.arguments, 'mode'):
            self.arguments['mode'] = getkey(self.globalvars['$Figure'], 'mode',
                                            u'')
        if not filename:
            mode = 'inline'
        else:
            mode = 'normal'
        self.arguments['caption'] = getkey(self.arguments, 'caption', u'')
        self.localvars['title'] = getkey(self.arguments, 'caption', 'Untitled')
        self.localvars['safe_title'] = getkey(
            self.arguments, 'label',
            'figure_' + safe_link(getkey(self.localvars, 'title', 'untitled')))

        # Store title to TOC
        counter_tick(self.globalvars['$Counters'], 'figure')

        tocitem = {
            'safe_title': self.localvars['safe_title'],
            'link': '#%s' % self.localvars['safe_title'],
            'title': getkey(self.localvars, 'title', 'Untitled'),
            'level': 1,
            'section': '!!toc1!!',
            'numbering': varsub('%numberingfigure%', [self.globalvars], [])
        }
        self.localvars['numbering'] = tocitem['numbering']

        self.globalvars['$TOF'].append(tocitem)

        parts = filename.split('.')
        extension = parts[-1].lower()
        if self.arguments.get('format', False):
            self.localvars['format'] = self.arguments.get('format')
        elif extension == 'png':
            self.localvars['format'] = 'image/png;base64'
        elif extension == 'jpg' or extension == 'jpeg':
            self.localvars['format'] = 'image/jpeg;base64'
        elif extension == 'gif':
            self.localvars['format'] = 'image/gif;base64'
        elif extension == 'svg':
            self.localvars['format'] = 'image/svg+xml;base64'
        else:
            G.warn('Unknown image format: ' + extension)
            self.localvars['format'] = extension

        indata = ''
        if not filename in getkey(self.globalvars, '$Base64Data', {}):
            # Caching
            # TODO This caching should be stored in css instead as well
            if mode == 'normal':
                try:
                    f = open(filename, 'r')
                    indata = f.read()
                except IOError:
                    G.error(''.join([
                        'The image file "', filename, '" could not be opened.'
                    ]))
            elif mode == 'inline':
                filename = self.localvars.get('safe_title')
                if not filename in getkey(self.globalvars, '$Base64Data', {}):
                    indata = self.content
            if 'base64' in self.localvars.get('format'):
                data = base64.b64encode(indata)
            else:
                data = ''.join([s for s in indata.splitlines() if s])
            self.globalvars['$Base64Data'][filename] = data

        self.localvars['data'] = self.globalvars['$Base64Data'][filename]

        if not 'width' in self.arguments:
            self.localvars['width'] = self.globalvars['$Figure']['width']
Beispiel #28
0
    def pre_process(self):
        root_path = self.globalvars.get('root') or '.'
        self_filename = self.filepath.replace(root_path, '')
        exclude_string = ','.join(
            [self.arguments.get('exclude', ''), self_filename])
        exclude_files = exclude_string.split(',')
        files = self.arguments.get(u'startwith', '').split(',')

        listed_files = os.listdir(root_path)
        listed_files.sort()
        for path in listed_files:
            if not path in files:
                files.append(path)

        remarks = []
        for path in files:
            if os.path.isfile(
                    os.path.join(root_path, path)
            ) and path not in exclude_files and not path.startswith('.'):
                G.info('Reading file %s' % path)

                # Load file (locally on its own)
                p = Processor.Processor(getkey(self.globalvars, 'root'), path,
                                        'no', True, '%s.html' %
                                        path)  # make them think they are main
                #p = Processor('', filename, 'html', True, outfile)
                if p.init_file():
                    p.load_objects()
                    p.close_file()
                else:
                    G.error('Skipping file "%s"' % path)
                    continue

                # Filter out objects we need
                needed_objects = []
                comment_objects = []
                doctitle = 'no title object found'
                for obj in p.objects:
                    if obj.object_name in ('Paragraph', 'Title', 'Input',
                                           'Use', 'Template', 'Heading',
                                           'TOC'):
                        needed_objects.append(obj)
                        if obj.object_name == 'Title':
                            doctitle = obj.arguments.get(u'title', 'wtf')
                    if obj.object_name == 'Comment' or obj.content.startswith(
                            "\nTODO") or obj.content.startswith("TODO"):
                        if not obj.arguments.get('state', False):
                            if obj.object_name == 'Comment':
                                obj.arguments['state'] = 'warning'
                            else:
                                obj.arguments['state'] = 'critical'
                        comment_objects.append(obj)

                p.objects = needed_objects
                p.preprocess_objects()
                p.process_objects_for_syntax_sugar()
                p.process_object_queue()

                # Take index comment objects
                for obj in comment_objects:
                    remarks.append({
                        'filename': obj.filepath,
                        'linenumber': obj.lineno,
                        'object_type': obj.object_name,
                        'note': obj.content,
                        'state': obj.arguments.get('state'),
                    })

                # Add main TOC item
                counter_tick(self.globalvars['$Counters'],
                             ''.join(['toc', str(1)]))
                tocitem = {
                    'safe_title':
                    path,
                    'link':
                    '%s.html' % path,
                    'title':
                    p.globalvars.get('title', doctitle),
                    'level':
                    1,
                    'numbering':
                    varsub(''.join(['%indexnumbering',
                                    str(1), '%']), [self.globalvars], [])
                }
                self.globalvars['$TOC'].append(dict(tocitem))
                self.globalvars['$ALTTOC'].append(dict(tocitem))

                # Extract Headings from TOC
                toc = p.globalvars.get('$TOC', False)
                if not toc:
                    G.error('The file "%s" did not have any TOC' % path)
                    continue

                for entry in toc:
                    level = entry.get('level', False)
                    if not level:
                        G.error('level missing for some entry in file "%s"' %
                                path)
                        continue
                    level = int(level) + 1
                    safe_title = entry.get('safe_title', False)
                    if not safe_title:
                        G.error(
                            'safe_title missing for some entry in file "%s"' %
                            path)
                        continue
                    title = entry.get('title', 'untitled')
                    counter_tick(self.globalvars['$Counters'],
                                 ''.join(['toc', str(level)]))
                    numbering = varsub(
                        ''.join(['%indexnumbering',
                                 str(level), '%']), [self.globalvars], [])
                    tocitem = {
                        'safe_title': '%s-%s' % (path, safe_title),
                        'link': '%s.html#%s' % (path, safe_title),
                        'title': title,
                        'level': level,
                        'numbering': numbering,
                    }
                    if (level <= int(getkey(self.globalvars, 'toc_depth', 3))):
                        self.globalvars['$TOC'].append(dict(tocitem))

                    if (level <= int(
                            getkey(self.globalvars, 'alt_toc_depth', 7))):
                        self.globalvars['$ALTTOC'].append(dict(tocitem))

        self.globalvars['$IndexedRemarks'] = remarks
        # This object is now "obselete"
        self.removed = True
Beispiel #29
0
    def pre_process(self):
        if not 'language' in self.arguments:
            self.arguments['language'] = getkey(self.arguments, 'primary', u'?') 
        self.arguments['caption'] = getkey(self.arguments, 'caption', u'')
        self.arguments['linenumbers'] = getkey(self.arguments, 'linenumbers', u'no')
        self.arguments['highlight'] = getkey(self.arguments, 'highlight', '')
        self.arguments['wrap'] = getkey(self.arguments, 'wrap', 'yes')
 
        self.localvars['id'] = 'code%i' % G.getid()
        
        if not self.content:
            G.warn("Empty Code object at %s +%d! Perhaps it starts with xxxx: Then add a - separator line before content." % (self.filepath, self.lineno))
            return

        # Clean empty lines
        self.content = self.content.replace('\n \n', '\n\n')
        
        if have_pygment:
            if getkey(self.arguments, 'language', u'') == u'':
                lexer = guess_lexer(self.content)
            else:
                try:
                    lexer = get_lexer_by_name(getkey(self.arguments, 'language', 'text'))
                except ClassNotFound:
                    G.error('Cound not find class %s at %s +%d' % (getkey(self.arguments, 'language', 'text'), self.filepath, self.lineno))
                    lexer = get_lexer_by_name('text')
            G.debug(u''.join(['Lexer is ',str(lexer)]))
 
            linenumbers = True if self.arguments['linenumbers'] == 'yes' else False
            wrap = True if self.arguments['wrap'] == 'yes' else False
            highlights = self.arguments['highlight'].split(',')
            highlight_lines = []
            for hl in highlights:
                parts = hl.split('-')
                if len(parts) == 2:
                    highlight_lines += range(int(parts[0]), int(parts[1])+ 1)
                elif hl:
                    highlight_lines.append(int(hl))
 
            formatter = HtmlFormatter(
                linenos = linenumbers,
                nowrap = not wrap,
                hl_lines = highlight_lines
            )
 
            self.localvars['code'] = unicode(highlight(unicode(self.content), lexer, formatter))
        else:
            G.debug('No highlighting done')
            self.localvars['code'] = u'\n'.join(['<pre>',unicode(self.content),'</pre>'])
 
        self.script = unicode(getkey(self.globalvars, '$Templates.Code.script', u''))
        self.script = varsub(self.script, 
                           [self.localvars,
                           self.arguments,
                           self.globalvars],
                           getkey(self.globalvars, '$Templates', False),
                           recursive=getkey(self.arguments, 'substitute', 'yes') != 'no')
Beispiel #30
0
 def pre_process(self):
     if getkey(self.arguments, 'primary', '') != '':
         self.localvars['protocol'] = self.arguments['primary']
Beispiel #31
0
 def pre_process(self):
     self.localvars['url'] = getkey(self.arguments, 'primary',
                                    'about:blank')
     self.localvars['title'] = getkey(self.arguments, 'title', False)
     if not self.localvars['title']:
         self.localvars['title'] = self.localvars['url']
Beispiel #32
0
 def pre_process(self):
     if getkey(self.arguments, 'primary', '') != '':
         self.localvars['protocol'] = self.arguments['primary']
Beispiel #33
0
    def pre_process(self):
        if not 'language' in self.arguments:
            self.arguments['language'] = getkey(self.arguments, 'primary', u'?') 
        self.arguments['caption'] = getkey(self.arguments, 'caption', u'')
        self.arguments['linenumbers'] = getkey(self.arguments, 'linenumbers', u'no')
        self.arguments['highlight'] = getkey(self.arguments, 'highlight', '')
        self.arguments['wrap'] = getkey(self.arguments, 'wrap', 'yes')
 
        self.localvars['id'] = 'code%i' % G.getid()
        
        if not self.content:
            G.warn("Empty Code object at %s +%d! Perhaps it starts with xxxx: Then add a - separator line before content." % (self.filepath, self.lineno))
            return

        # Clean empty lines
        code_result =  run(self.content)
        self.content = code_result.replace('\n \n', '\n\n')
        if have_pygment:
            if getkey(self.arguments, 'language', u'') == u'':
                lexer = guess_lexer(self.content)
            else:
                try:
                    lexer = get_lexer_by_name(getkey(self.arguments, 'language', 'text'))
                except ClassNotFound:
                    G.error('Cound not find class %s at %s +%d' % (getkey(self.arguments, 'language', 'text'), self.filepath, self.lineno))
                    lexer = get_lexer_by_name('text')
            G.debug(u''.join(['Lexer is ',str(lexer)]))
 
            linenumbers = True if self.arguments['linenumbers'] == 'yes' else False
            wrap = True if self.arguments['wrap'] == 'yes' else False
            highlights = self.arguments['highlight'].split(',')
            highlight_lines = []
            for hl in highlights:
                parts = hl.split('-')
                if len(parts) == 2:
                    highlight_lines += range(int(parts[0]), int(parts[1])+ 1)
                elif hl:
                    highlight_lines.append(int(hl))
 
            formatter = HtmlFormatter(
                linenos = linenumbers,
                nowrap = not wrap,
                hl_lines = highlight_lines
            )
            self.localvars['code'] = unicode(highlight(unicode(self.content), lexer, formatter))
        else:
            G.debug('No highlighting done')
            self.localvars['code'] = u'\n'.join(['<pre>',unicode(self.content),'</pre>'])
 
        self.script = unicode(getkey(self.globalvars, '$Templates.Exec.script', u''))
        self.script = varsub(self.script, 
                           [self.localvars,
                           self.arguments,
                           self.globalvars],
                           getkey(self.globalvars, '$Templates', False),
                           recursive=getkey(self.arguments, 'substitute', 'yes') != 'no')
Beispiel #34
0
    def pre_process(self):
        root_path = self.globalvars.get('root') or '.'
        self_filename = self.filepath.replace(root_path, '')
        exclude_string = ','.join([self.arguments.get('exclude', ''), self_filename])
        exclude_files = exclude_string.split(',')
        files = self.arguments.get(u'startwith', '').split(',')

        listed_files = os.listdir(root_path)
        listed_files.sort()
        for path in listed_files:
            if not path in files:
                files.append(path)
        
        remarks = []
        for path in files:
            if os.path.isfile(os.path.join( root_path, path)) and path not in exclude_files and not path.startswith('.'):
                G.info('Reading file %s' % path)

                # Load file (locally on its own)
                p = Processor.Processor(getkey(self.globalvars,'root'), path, 'no', True, '%s.html' % path) # make them think they are main
                #p = Processor('', filename, 'html', True, outfile)
                if p.init_file():
                    p.load_objects()
                    p.close_file()
                else:
                    G.error('Skipping file "%s"' % path)
                    continue
                
                # Filter out objects we need
                needed_objects = []
                comment_objects = []
                doctitle = 'no title object found'
                for obj in p.objects:
                    if obj.object_name in ('Paragraph', 'Title', 'Input', 'Use', 'Template','Heading', 'TOC'):
                        needed_objects.append(obj)
                        if obj.object_name == 'Title':
                            doctitle = obj.arguments.get(u'title', 'wtf')
                    if obj.object_name == 'Comment' or obj.content.startswith("\nTODO") or obj.content.startswith("TODO"):
                        if not obj.arguments.get('state', False):
                            if obj.object_name == 'Comment':
                                obj.arguments['state'] = 'warning'
                            else:
                                obj.arguments['state'] = 'critical'
                        comment_objects.append(obj)

                p.objects = needed_objects
                p.preprocess_objects()
                p.process_objects_for_syntax_sugar()
                p.process_object_queue()

                # Take index comment objects
                for obj in comment_objects:
                    remarks.append({
                        'filename': obj.filepath,
                        'linenumber': obj.lineno,
                        'object_type': obj.object_name,
                        'note': obj.content,
                        'state': obj.arguments.get('state'),
                    })

                # Add main TOC item
                counter_tick(self.globalvars['$Counters'],
                             ''.join(['toc',str(1)]))
                tocitem = { 'safe_title': path,
                            'link': '%s.html' % path,
                            'title': p.globalvars.get('title', doctitle),
                            'level': 1,
                            'numbering': varsub(
                                ''.join(['%indexnumbering',
                                         str(1),
                                         '%']),
                                [self.globalvars],
                                [])
                          }
                self.globalvars['$TOC'].append(dict(tocitem))
                self.globalvars['$ALTTOC'].append(dict(tocitem))

                # Extract Headings from TOC
                toc = p.globalvars.get('$TOC', False)
                if not toc:
                    G.error('The file "%s" did not have any TOC' % path)
                    continue

                for entry in toc:
                    level = entry.get('level', False)
                    if not level:
                        G.error('level missing for some entry in file "%s"' % path)
                        continue
                    level = int(level) + 1
                    safe_title = entry.get('safe_title', False)
                    if not safe_title:
                        G.error('safe_title missing for some entry in file "%s"' % path)
                        continue
                    title = entry.get('title', 'untitled')
                    counter_tick(self.globalvars['$Counters'],
                             ''.join(['toc',str(level)]))
                    numbering = varsub(
                        ''.join(['%indexnumbering', str(level), '%']), 
                        [self.globalvars], [])
                    tocitem = { 'safe_title': '%s-%s' % (path, safe_title),
                                'link':  '%s.html#%s' % (path, safe_title),
                                'title': title,
                                'level': level,
                                'numbering': numbering,
                              }
                    if (level <= 
                        int(getkey(self.globalvars, 'toc_depth', 3))):
                        self.globalvars['$TOC'].append(dict(tocitem))

                    if (level <= 
                        int(getkey(self.globalvars, 'alt_toc_depth', 7))):
                        self.globalvars['$ALTTOC'].append(dict(tocitem))
        
        self.globalvars['$IndexedRemarks'] = remarks
        # This object is now "obselete"
        self.removed = True
Beispiel #35
0
 def setup(self):
     if '$Heading' in self.globalvars:
         G.info("Heading already setup.")
         return
     G.info("Setting up Heading.")
     # Add SyntaxSugar
     # FIXME These could be more generalised
     self.globalvars['$SyntaxSugar'].append(SyntaxSugarDefinition('= ([\s\w\.\^\$\*\+\?\{\}\[\]\\\\\|\(\)\/@\",-]+?) =',
         ['title'], 
         'Heading: %title%\nlevel: 1'))
     self.globalvars['$SyntaxSugar'].append(SyntaxSugarDefinition('== ([\s\w\.\^\$\*\+\?\{\}\[\]\\\\\|\(\)\/@\",-]+?) ==',
         ['title'], 
         'Heading: %title%\nlevel: 2'))
     self.globalvars['$SyntaxSugar'].append(SyntaxSugarDefinition('=== ([\s\w\.\^\$\*\+\?\{\}\[\]\\\\\|\(\)\/@\",-]+?) ===',
         ['title'], 
         'Heading: %title%\nlevel: 3'))
     self.globalvars['$SyntaxSugar'].append(SyntaxSugarDefinition('==== ([\s\w\.\^\$\*\+\?\{\}\[\]\\\\\|\(\)\/@\",-]+?) ====',
         ['title'], 
         'Heading: %title%\nlevel: 4'))
     self.globalvars['$SyntaxSugar'].append(SyntaxSugarDefinition('===== ([\s\w\.\^\$\*\+\?\{\}\[\]\\\\\|\(\)\/@\",-]+?) =====',
         ['title'], 
         'Heading: %title%\nlevel: 5'))
     self.globalvars['$SyntaxSugar'].append(SyntaxSugarDefinition('====== ([\s\w\.\^\$\*\+\?\{\}\[\]\\\\\|\(\)\/@\",-]+?) ======',
         ['title'], 
         'Heading: %title%\nlevel: 6'))
     self.globalvars['$SyntaxSugar'].append(SyntaxSugarDefinition('======= ([\s\w\.\^\$\*\+\?\{\}\[\]\\\\\|\(\)\/@\",-]+?) =======',
         ['title'], 
         'Heading: %title%\nlevel: 7'))
     # Add SyntaxSugar that applies to Jira
     self.globalvars['$SyntaxSugar'].append(SyntaxSugarDefinition('h1. ([\s\w\.\^\$\*\+\?\{\}\[\]\\\\\|\(\)\/@\",-]+)',
         ['title'], 
         'Heading: %title%\nlevel: 1'))
     self.globalvars['$SyntaxSugar'].append(SyntaxSugarDefinition('h2. ([\s\w\.\^\$\*\+\?\{\}\[\]\\\\\|\(\)\/@\",-]+)',
         ['title'], 
         'Heading: %title%\nlevel: 2'))
     self.globalvars['$SyntaxSugar'].append(SyntaxSugarDefinition('h3. ([\s\w\.\^\$\*\+\?\{\}\[\]\\\\\|\(\)\/@\",-]+)',
         ['title'], 
         'Heading: %title%\nlevel: 3'))
     self.globalvars['$SyntaxSugar'].append(SyntaxSugarDefinition('h4. ([\s\w\.\^\$\*\+\?\{\}\[\]\\\\\|\(\)\/@\",-]+)',
         ['title'], 
         'Heading: %title%\nlevel: 4'))
     self.globalvars['$SyntaxSugar'].append(SyntaxSugarDefinition('h5. ([\s\w\.\^\$\*\+\?\{\}\[\]\\\\\|\(\)\/@\",-]+)',
         ['title'], 
         'Heading: %title%\nlevel: 5'))
     self.globalvars['$SyntaxSugar'].append(SyntaxSugarDefinition('h6. ([\s\w\.\^\$\*\+\?\{\}\[\]\\\\\|\(\)\/@\",-]+)',
         ['title'], 
         'Heading: %title%\nlevel: 6'))
     self.globalvars['$SyntaxSugar'].append(SyntaxSugarDefinition('h7. ([\s\w\.\^\$\*\+\?\{\}\[\]\\\\\|\(\)\/@\",-]+)',
         ['title'], 
         'Heading: %title%\nlevel: 7'))
     # Set defaults
     self.globalvars['$Heading'] = {
             'level': '2',
             }
     # Init TOC lists
     self.globalvars['$TOC'] = []
     self.globalvars['$ALTTOC'] = [] # alternate toc TOC: alt
     # Init counters
     if not getkey(self.globalvars, '$Counters', False):
         self.globalvars['$Counters'] = {}
     counter_create(self.globalvars['$Counters'], 'toc1', 'toc2')
     counter_create(self.globalvars['$Counters'], 'toc2', 'toc3')
     counter_create(self.globalvars['$Counters'], 'toc3', 'toc4')
     counter_create(self.globalvars['$Counters'], 'toc4', 'toc5')
     counter_create(self.globalvars['$Counters'], 'toc5', 'toc6')
     counter_create(self.globalvars['$Counters'], 'toc6', 'toc7')
     counter_create(self.globalvars['$Counters'], 'toc7', None)
     self.globalvars['numbering1'] = '!!toc1!!.'
     self.globalvars['numbering2'] = '!!toc1!!.!!toc2!!.'
     self.globalvars['numbering3'] = '!!toc1!!.!!toc2!!.!!toc3!!.'
     self.globalvars['numbering4'] = '!!toc1!!.!!toc2!!.!!toc3!!.!!toc4!!.'
     self.globalvars['numbering5'] = '!!toc1!!.!!toc2!!.!!toc3!!.!!toc4!!.!!toc5!!.'
     self.globalvars['numbering6'] = '.!!toc6!!.'
     self.globalvars['numbering7'] = '.!!toc6!!.!!toc7!!.'
     self.globalvars['indexnumbering1'] = ''
     self.globalvars['indexnumbering2'] = '!!toc2!!.'
     self.globalvars['indexnumbering3'] = '!!toc2!!.!!toc3!!.'
     self.globalvars['indexnumbering4'] = '!!toc2!!.!!toc3!!.!!toc4!!.'
     self.globalvars['indexnumbering5'] = '!!toc2!!.!!toc3!!.!!toc4!!.!!toc5!!.'
     self.globalvars['indexnumbering6'] = '.!!toc6!!.'
     self.globalvars['indexnumbering7'] = '.!!toc6!!.!!toc7!!.'
Beispiel #36
0
 def setup(self):
     if '$Heading' in self.globalvars:
         G.info("Heading already setup.")
         return
     G.info("Setting up Heading.")
     # Add SyntaxSugar
     # FIXME These could be more generalised
     self.globalvars['$SyntaxSugar'].append(
         SyntaxSugarDefinition(
             '= ([\s\w\.\^\$\*\+\?\{\}\[\]\\\\\|\(\)\/@\",-]+?) =',
             ['title'], 'Heading: %title%\nlevel: 1'))
     self.globalvars['$SyntaxSugar'].append(
         SyntaxSugarDefinition(
             '== ([\s\w\.\^\$\*\+\?\{\}\[\]\\\\\|\(\)\/@\",-]+?) ==',
             ['title'], 'Heading: %title%\nlevel: 2'))
     self.globalvars['$SyntaxSugar'].append(
         SyntaxSugarDefinition(
             '=== ([\s\w\.\^\$\*\+\?\{\}\[\]\\\\\|\(\)\/@\",-]+?) ===',
             ['title'], 'Heading: %title%\nlevel: 3'))
     self.globalvars['$SyntaxSugar'].append(
         SyntaxSugarDefinition(
             '==== ([\s\w\.\^\$\*\+\?\{\}\[\]\\\\\|\(\)\/@\",-]+?) ====',
             ['title'], 'Heading: %title%\nlevel: 4'))
     self.globalvars['$SyntaxSugar'].append(
         SyntaxSugarDefinition(
             '===== ([\s\w\.\^\$\*\+\?\{\}\[\]\\\\\|\(\)\/@\",-]+?) =====',
             ['title'], 'Heading: %title%\nlevel: 5'))
     self.globalvars['$SyntaxSugar'].append(
         SyntaxSugarDefinition(
             '====== ([\s\w\.\^\$\*\+\?\{\}\[\]\\\\\|\(\)\/@\",-]+?) ======',
             ['title'], 'Heading: %title%\nlevel: 6'))
     self.globalvars['$SyntaxSugar'].append(
         SyntaxSugarDefinition(
             '======= ([\s\w\.\^\$\*\+\?\{\}\[\]\\\\\|\(\)\/@\",-]+?) =======',
             ['title'], 'Heading: %title%\nlevel: 7'))
     # Add SyntaxSugar that applies to Jira
     self.globalvars['$SyntaxSugar'].append(
         SyntaxSugarDefinition(
             'h1. ([\s\w\.\^\$\*\+\?\{\}\[\]\\\\\|\(\)\/@\",-]+)',
             ['title'], 'Heading: %title%\nlevel: 1'))
     self.globalvars['$SyntaxSugar'].append(
         SyntaxSugarDefinition(
             'h2. ([\s\w\.\^\$\*\+\?\{\}\[\]\\\\\|\(\)\/@\",-]+)',
             ['title'], 'Heading: %title%\nlevel: 2'))
     self.globalvars['$SyntaxSugar'].append(
         SyntaxSugarDefinition(
             'h3. ([\s\w\.\^\$\*\+\?\{\}\[\]\\\\\|\(\)\/@\",-]+)',
             ['title'], 'Heading: %title%\nlevel: 3'))
     self.globalvars['$SyntaxSugar'].append(
         SyntaxSugarDefinition(
             'h4. ([\s\w\.\^\$\*\+\?\{\}\[\]\\\\\|\(\)\/@\",-]+)',
             ['title'], 'Heading: %title%\nlevel: 4'))
     self.globalvars['$SyntaxSugar'].append(
         SyntaxSugarDefinition(
             'h5. ([\s\w\.\^\$\*\+\?\{\}\[\]\\\\\|\(\)\/@\",-]+)',
             ['title'], 'Heading: %title%\nlevel: 5'))
     self.globalvars['$SyntaxSugar'].append(
         SyntaxSugarDefinition(
             'h6. ([\s\w\.\^\$\*\+\?\{\}\[\]\\\\\|\(\)\/@\",-]+)',
             ['title'], 'Heading: %title%\nlevel: 6'))
     self.globalvars['$SyntaxSugar'].append(
         SyntaxSugarDefinition(
             'h7. ([\s\w\.\^\$\*\+\?\{\}\[\]\\\\\|\(\)\/@\",-]+)',
             ['title'], 'Heading: %title%\nlevel: 7'))
     # Set defaults
     self.globalvars['$Heading'] = {
         'level': '2',
     }
     # Init TOC lists
     self.globalvars['$TOC'] = []
     self.globalvars['$ALTTOC'] = []  # alternate toc TOC: alt
     # Init counters
     if not getkey(self.globalvars, '$Counters', False):
         self.globalvars['$Counters'] = {}
     counter_create(self.globalvars['$Counters'], 'toc1', 'toc2')
     counter_create(self.globalvars['$Counters'], 'toc2', 'toc3')
     counter_create(self.globalvars['$Counters'], 'toc3', 'toc4')
     counter_create(self.globalvars['$Counters'], 'toc4', 'toc5')
     counter_create(self.globalvars['$Counters'], 'toc5', 'toc6')
     counter_create(self.globalvars['$Counters'], 'toc6', 'toc7')
     counter_create(self.globalvars['$Counters'], 'toc7', None)
     self.globalvars['numbering1'] = '!!toc1!!.'
     self.globalvars['numbering2'] = '!!toc1!!.!!toc2!!.'
     self.globalvars['numbering3'] = '!!toc1!!.!!toc2!!.!!toc3!!.'
     self.globalvars['numbering4'] = '!!toc1!!.!!toc2!!.!!toc3!!.!!toc4!!.'
     self.globalvars[
         'numbering5'] = '!!toc1!!.!!toc2!!.!!toc3!!.!!toc4!!.!!toc5!!.'
     self.globalvars['numbering6'] = '.!!toc6!!.'
     self.globalvars['numbering7'] = '.!!toc6!!.!!toc7!!.'
     self.globalvars['indexnumbering1'] = ''
     self.globalvars['indexnumbering2'] = '!!toc2!!.'
     self.globalvars['indexnumbering3'] = '!!toc2!!.!!toc3!!.'
     self.globalvars['indexnumbering4'] = '!!toc2!!.!!toc3!!.!!toc4!!.'
     self.globalvars[
         'indexnumbering5'] = '!!toc2!!.!!toc3!!.!!toc4!!.!!toc5!!.'
     self.globalvars['indexnumbering6'] = '.!!toc6!!.'
     self.globalvars['indexnumbering7'] = '.!!toc6!!.!!toc7!!.'
Beispiel #37
0
 def pre_process(self):
     self.localvars['url'] = getkey(self.arguments,'primary','about:blank');
     self.localvars['title'] = getkey(self.arguments,'title',False);
     if not self.localvars['title']:
         self.localvars['title'] = self.localvars['url']
Beispiel #38
0
    def pre_process(self):
        if not getkey(self.arguments, 'file'):
            self.arguments['file'] = getkey(self.arguments, 'primary', u'') 
        filename = getkey(self.arguments, 'file')
        if not getkey(self.arguments, 'mode'):
            self.arguments['mode'] = getkey(self.globalvars['$Figure'], 'mode',u'')
        if not filename:
            mode = 'inline'
        else:
            mode = 'normal'
        self.arguments['caption'] = getkey(self.arguments, 'caption', u'')
        self.localvars['title'] = getkey(self.arguments, 'caption', 'Untitled')
        self.localvars['safe_title'] = getkey(self.arguments, 
            'label', 'figure_'+safe_link(
                getkey(self.localvars,'title','untitled')))

        # Store title to TOC
        counter_tick(self.globalvars['$Counters'], 'figure')
                     
        tocitem = { 'safe_title': self.localvars['safe_title'],
                    'link': '#%s' % self.localvars['safe_title'],
                    'title': getkey(self.localvars, 'title', 'Untitled'),
                    'level': 1,
                    'section': '!!toc1!!',
                    'numbering': varsub('%numberingfigure%', [self.globalvars], [])
                  }
        self.localvars['numbering'] = tocitem['numbering']

        self.globalvars['$TOF'].append(tocitem)

        parts = filename.split('.')
        extension = parts[-1].lower()
        if self.arguments.get('format', False):
            self.localvars['format'] = self.arguments.get('format') 
        elif extension == 'png':
            self.localvars['format'] = 'image/png;base64'
        elif extension == 'jpg' or extension == 'jpeg':
            self.localvars['format'] = 'image/jpeg;base64'
        elif extension == 'gif':
            self.localvars['format'] = 'image/gif;base64'
        elif extension == 'svg':
            self.localvars['format'] = 'image/svg+xml;base64'
        else:
            G.warn('Unknown image format: '+extension)
            self.localvars['format'] = extension 

        indata = ''
        if not filename in getkey(self.globalvars,'$Base64Data',{}):
            # Caching
            # TODO This caching should be stored in css instead as well
            if mode == 'normal':
                try:
                    f = open(filename, 'r')
                    indata = f.read()
                except IOError:
                    G.error(''.join(['The image file "',filename,'" could not be opened.']))
            elif mode == 'inline':
                filename = self.localvars.get('safe_title')
                if not filename in getkey(self.globalvars,'$Base64Data',{}):
                    indata = self.content 
            if 'base64' in self.localvars.get('format'):
                data = base64.b64encode(indata)
            else:
                data = ''.join([s for s in indata.splitlines() if s])
            self.globalvars['$Base64Data'][filename] = data

        self.localvars['data'] = self.globalvars['$Base64Data'][filename]

        if not 'width' in self.arguments:
            self.localvars['width'] = self.globalvars['$Figure']['width']
Beispiel #39
0
 def pre_process(self):
     if getkey(self.globalvars, "state", "draft") == "final":
         self.removed = True
Beispiel #40
0
    def pre_process(self):
        self.needs_rerun = not self.needs_rerun 

        self.arguments['caption'] = getkey(self.arguments, 'caption', u'')
        self.localvars['title'] = getkey(self.arguments, 'caption', 'Untitled')

        if not getkey(self.arguments, 'file'):
            self.arguments['file'] = getkey(self.arguments, 'primary', u'') 
        filename = getkey(self.arguments, 'file')
        if not getkey(self.arguments, 'mode'):
            self.arguments['mode'] = getkey(self.globalvars.get('$Table', {}), 'mode',u'')
        mode = self.arguments['mode']
        self.localvars['headers'] = self.arguments.get('headers', False) or self.globalvars.get('$Table', {}).get('headers', 'yes')

        # Store title to TOT (Table of Tables)
        self.localvars['safe_title'] = 'table_'+safe_link(
                getkey(self.localvars,'title','untitled'))
        counter_tick(self.globalvars['$Counters'], 'table')
                     
        tocitem = { 'safe_title': self.localvars['safe_title'],
                    'link': '#%s' % self.localvars['safe_title'],
                    'title': getkey(self.localvars, 'title', 'Untitled'),
                    'level': 1,
                    'section': '!!toc1!!',
                    'numbering': varsub('%numberingtable%', [self.globalvars], [])
                  }
        self.localvars['numbering'] = tocitem['numbering']

        self.globalvars['$TOT'].append(tocitem)

        data = ''
        # Caching
        # TODO This caching should be stored in css instead as well
        if mode == 'normal':
            try:
                f = open(filename, 'r')
                data = f.read()
            except IOError:
                G.error(''.join(['The image file "',filename,'" could not be opened.']))
        elif mode == 'inline':
            data = self.content 

        if not 'width' in self.arguments and 'width' in self.globalvars.get('$Table', []):
            self.localvars['width'] = self.globalvars.get('$Table', []).get('width')

        splitter = re.compile("[ ]{2,}")
        rows = []
        for (nr, line) in enumerate(data.splitlines()):
            if nr == 0:
                pass
            elif nr == 1 and self.localvars.get('headers', False) in ('1', 'yes'):
                headers = []
                for header in splitter.split(line):
                    headers.append({'text': header})
                self.localvars['$Headers'] = headers
            else:
                cells = []
                for cell in splitter.split(line):
                    cells.append({'text': cell})
                rows.append({'$Cells': cells})
        self.localvars['$Rows'] = rows