コード例 #1
0
ファイル: visit.py プロジェクト: goerz/pyala
    def writeout(self, filename):
        tp = TemplateProcessor(template = self.html_template)
        if not os.path.isdir(self.outdir):
            os.makedirs(self.outdir)
        def pagedata(index, varname):
            loopreplacements = {
                'iteration' : str(index+1),
                'file': self.pages[index].file,
                'time': str(self.durations[index]),
                'reload': str(self.reloads[index]),
                'code': self.pages[index].code_description,
                'full_line': cgi.escape(self.pages[index].full_line)
            }
            try:
                return loopreplacements[varname]
            except:
                return None
        replacements = {}
        for (key, item) in self.__dict__.items():
            if isinstance(item, basestring):
                replacements[key] = item
            elif isinstance(item, int):
                replacements[key] = str(item)
        replacements['transferred_kb'] = "%.1f" % (float(self.transferred_bytes) / float(1024))
        replacements['transferred_mb'] = "%.1f" % (float(self.transferred_bytes) / float(1048576))
        tp.replacements = replacements
        tp.loops = {'pages' : LoopData(length=len(self.pages), datafunction=pagedata) }
        tp.output = os.path.join(self.outdir, filename)

        tp.run()
コード例 #2
0
ファイル: DetailedStatComponent.py プロジェクト: goerz/pyala
    def _write_toc(self):
        """ Write the main table of contents file with a calendar"""
        tp = TemplateProcessor(template = self.get_option('html_toc_template'))
        # build list of the months, so that we can index it
        # we need three lists:
        monthlist = [] # to keep the dict that maps days to anchors for each month
        monthnamelist = [] # the names (number) of the corresponding months
        yearnamelist = [] # the names (number) of the corresponding years
        minyear = min(self._anchors.keys())
        maxyear = max(self._anchors.keys())
        for year in xrange(minyear, maxyear+1):
            if self._anchors.has_key(year):
                # try each month in every year, and see if an entry exists
                for month in xrange(1,13):
                    if self._anchors[year].has_key(month):
                        monthlist.append(self._anchors[year][month])
                        monthnamelist.append(month)
                        yearnamelist.append(year)

        def calendarloop(index, varname):
            loopreplacements = {
                'calendar'  : HTMLCalendar.MonthCal().render(yearnamelist[index], \
                                                             monthnamelist[index], \
                                                             monthlist[index])
            }
            if len(monthlist) > 2:
                loopreplacements['calendar'] = "<div style=\"float: left; width: 33%\">\n" \
                                               + loopreplacements['calendar']
            else:
                loopreplacements['calendar'] = "<div style=\"float: left; width: %s" % (100/len(monthlist)) \
                                               + "%\">\n" + loopreplacements['calendar']
            loopreplacements['calendar'] += "</div>\n"
            try:
                return loopreplacements[varname]
            except:
                return None

        replacements = {
            'headrow' : self.get_option('title') + "&nbsp;&nbsp;-&nbsp;&nbsp;TOC",
            'total_visits': str(self._number_of_visits),
            'link_to_prev': self._outfilename.replace( ".html", \
                            str(self._number_of_pages-1).zfill(6) +".html" ),
            'link_to_next': self._outfilename.replace( ".html", \
                            str(self._number_of_pages+1).zfill(6) +".html" )
        }
        tp.replacements = replacements
        tp.loops = {'calendars' : LoopData(\
                                  length=len(monthlist), \
                                  datafunction=calendarloop) }
        tp.output = os.path.join(self.get_option('outdir'), self._outfilename)

        tp.run()
コード例 #3
0
ファイル: DetailedStatComponent.py プロジェクト: goerz/pyala
    def _writeout(self, is_last=False):
        """ Write out all registered visits and clear the list """
        self._number_of_pages += 1
        is_first = (self._number_of_pages == 1)
        filename = self._outfilename.replace( ".html", \
                   str(self._number_of_pages).zfill(6) +".html" )
        tp = TemplateProcessor(template = self.get_option('html_template'))
        def visitloop(index, varname):
            loopreplacements = {
                'id'                : str(self._visits[index].number),
                'time'              : ApacheLogParser.stringdate( \
                                          self._visits[index].begin_time, \
                                          pattern="%m/%d/%y %H:%M:%S", \
                                          offset=self._visits[index].pages[-1].serveroffset),
                'countryicon'       : self._visits[index].country_icon,
                'countryname'       : self._visits[index].countryname,
                'countryextension'  : self._visits[index].countryextension,
                'hostname'          : self._visits[index].hostname,
                'hostname_short'    : self._visits[index].hostname[-27:],
                'number_of_pages'   : str(len(self._visits[index].pages)),
                'visitpage'         : os.path.join(
                                       self._visit_page_folder,
                                       str(self._visits[index].number).zfill(\
                                                  self._visit_filename_length) + ".html" ),
                'os_icon'           : self._visits[index].os_icon,
                'full_os'           : self._visits[index].os + ' ' + self._visits[index].os_version,
                'os'                : self._visits[index].os,
                'browser_icon'      : self._visits[index].browser_icon,
                'full_browser'      : self._visits[index].browser + ' ' \
                                      + self._visits[index].browser_version \
                                      + ' (' +  self._visits[index].fullbrowser + ')',
                'browser'           : self._visits[index].browser,
                'referer_url'       : self._visits[index].referer,
                'referer_site'      : self._visits[index].referer_site,
                'referer_page'      : self._visits[index].referer_page,
                'last_page'         : self._visits[index].pages[-1].file,
                'last_page_short'   : self._visits[index].pages[-1].file[\
                                            self._visits[index].pages[-1].file.rfind("/", 0, -2)+1:],
                'search_term'       : self._visits[index].search.replace(r'"',r'&quot;'),
                'search_term_short' : self._visits[index].search[:27],
                'is_bot'            : str(self._visits[index].is_bot),
                'anchor_name'       : 'a' + str(self._visits[index].number)
            }
            if len(loopreplacements['last_page_short']) > 30:
                loopreplacements['last_page_short'] = \
                    loopreplacements['last_page_short'][:27] + "..."
            if len(self._visits[index].search) > 27:
                loopreplacements['search_term_short'] = loopreplacements['search_term_short'] + "..."
            if len(self._visits[index].hostname) > 27:
                loopreplacements['hostname_short'] = "..." +  loopreplacements['hostname_short']
            if self._visits[index].is_bot == "Yes":
                loopreplacements['os_icon'] =  self._visits[index].bot_icon
                loopreplacements['os'] =  self._visits[index].botname
                loopreplacements['full_os'] =  self._visits[index].botname + self._visits[index].bot_version
                loopreplacements['browser_icon'] =  self._visits[index].bot_icon
                loopreplacements['browser'] =  self._visits[index].botname
                loopreplacements['full_browser'] =  self._visits[index].botname + self._visits[index].bot_version
            try:
                return loopreplacements[varname]
            except:
                return None
        replacements = {
            'headrow' : self.get_option('title'),
            'visits_per_page': str(self.get_option('visits_per_page')),
            'link_to_prev': self._outfilename.replace( ".html", \
                            str(self._number_of_pages-1).zfill(6) +".html" ),
            'link_to_next': self._outfilename.replace( ".html", \
                            str(self._number_of_pages+1).zfill(6) +".html" ),
            'link_to_toc' : self._outfilename,
            'write_visit_pages' : str(self.get_option('write_visit_pages'))
        }
        if is_first:
            replacements['link_to_prev'] = self._outfilename
        if is_last:
            replacements['link_to_next'] = self._outfilename
        tp.replacements = replacements
        tp.loops = {'visits' : LoopData(length=len(self._visits), datafunction=visitloop) }
        tp.output = os.path.join(self.get_option('outdir'), filename)

        tp.run()
コード例 #4
0
ファイル: new_plugin.py プロジェクト: Dar13/lightship
            print('special characters are not allowed')
            continue
        return line.strip('\r\n')


if __name__ == '__main__':

    # get name of new plugin
    if not len(sys.argv) == 2:
        print('Usage: ' + sys.argv[0] + ' <new_plugin_name>')
        print('Note: Paths are allowed. They are relative to the working directory.')
        sys.exit(0)
    plugin_name = os.path.basename(sys.argv[1])
    plugin_path = sys.argv[1]

    tp = TemplateProcessor()
    tp.set_destination_path(plugin_path)
    tp.set_source_path('plugins/plugin_template')

    # prepare template files
    header_dir = os.path.join('include', 'plugin_' + plugin_name)
    source_dir = os.path.join('src')
    TemplateProcessor.ensure_path(os.path.join(plugin_path, header_dir))
    TemplateProcessor.ensure_path(os.path.join(plugin_path, source_dir))
    (tp.add_template('config.h.in.in', os.path.join(header_dir, 'config.h.in'))
       .add_template('events.c.in',    os.path.join(source_dir, 'events.c'))
       .add_template('events.h.in',    os.path.join(header_dir, 'events.h'))
       .add_template('plugin.c.in',    os.path.join(source_dir, 'plugin_' + plugin_name + '.c'))
       .add_template('services.c.in',  os.path.join(source_dir, 'services.c'))
       .add_template('services.h.in',  os.path.join(header_dir, 'services.h'))
       .add_template('glob.c.in',      os.path.join(source_dir, 'glob.c'))