Ejemplo n.º 1
0
def add (title, body):
    html = rst_html.process_rst('quotes', body)
    html = re.sub('<!--.*?--><!--.*?-->', '', html)
    html = html.strip()
    item = PyRSS2Gen.RSSItem(title=title, 
                             description=html)
    rss.items.append(item)
Ejemplo n.º 2
0
def read_event ():
    """Read the newsindex.yml file, returning a list of dictionaries
       that contain information about each news item.
    """

    input = open(os.path.join(options.data, 'eventindex.yml'), 'r')
    data = yaml.load(input, pyramid_yaml.PyramidLoader)
    input.close()
    result = []
    for mapping_node in data.globals['news']:
        d = {}
        L = list(mapping_node.value)
        for key_node, value_node in L:
            key = key_node.value
            item_html = value_node.value

            if key == 'description':
                item_html = rst_html.process_rst('newsindex.yml', item_html)
                item_html = item_html.strip()

                if item_html.startswith('<p>'): item_html = item_html[3:]
                if item_html.endswith('<p>'): item_html = item_html[:-3]

            d[key_node.value] = item_html
        result.append(d)

    return result
Ejemplo n.º 3
0
def add (url, title, body, categories=[]):
    html = rst_html.process_rst('success', body)
    item = PyRSS2Gen.RSSItem(title=title, 
                             description=html)
    for cat in categories:
        item.categories.append(cat)
    
    rss.items.append(item)
Ejemplo n.º 4
0
def read_news ():
    """Read the newsindex.yml file, returning a list of dictionaries
       that contain information about each news item.
    """

    yamls = jp_build.read_files('jp_data')
    result = []
    for rec in yamls[:40]:
        item_html = rst_html.process_rst('newsindex.yml', rec['text'])
        item_html = item_html.strip()

        if item_html.startswith('<p>'): item_html = item_html[3:]
        if item_html.endswith('<p>'): item_html = item_html[:-3]
        dir = '/community/event/#' if rec['type'] == 'event' else '/news/#'
        d = {
            'url': rec['path'],
            'title': rec['title'],
            'date': rec['date'],
            'text': item_html
        }
        result.append(d)



#    input = open(os.path.join(options.data, 'newsindex.yml'), 'r')
#    data = yaml.load(input, pyramid_yaml.PyramidLoader)
#    input.close()
#    result = []
#    for mapping_node in data.globals['news']:
#        d = {}
#        L = list(mapping_node.value)
#        for key_node, value_node in L:
#            key = key_node.value
#            item_html = value_node.value
#
#            if key == 'description':
#                item_html = rst_html.process_rst('newsindex.yml', item_html)
#                item_html = item_html.strip()
#
#                if item_html.startswith('<p>'): item_html = item_html[3:]
#                if item_html.endswith('<p>'): item_html = item_html[:-3]
#
#            d[key_node.value] = item_html
#        result.append(d)

    return result
Ejemplo n.º 5
0
    def parse (self, input):
        self.body = ""
        while 1:
            L = input.readline()
            if L == "":
                raise RuntimeError('No bibliographic data: ' + self.filename)
            if re.match('^-{2,}$', L):
                break
            self.body += L

        self.body = self.body.strip()
        self.body = rst_html.process_rst(self.filename, self.body)

        # Read metadata fields
        self.field_text = ""
        self.fields.clear()
        while True:
            L = input.readline()
            if L == "":
                break
            self.field_text += L
            m = re.match('\s*%([A-Za-z@\*])\s*(.*)\s*', L)
            if m is None:
                continue
            field, value = m.group(1,2)
            field = field.upper()
            if field in self.multiple:
                fl = self.fields.setdefault(field, [])
                fl.append(value.strip())
            else:
                self.fields[field] = value

        self.field_text = self.field_text.strip()

        # Fix the fields
        L = self.fields.get('K', '').split(',')
        L = [x.strip().lower() for x in L]
        L = [x for x in L if x]
        self.fields['K'] = L

        self.review_date = self.fields.get('@')
        if self.review_date:
            self.review_date = self.review_date.strip()
        self.updated = True
Ejemplo n.º 6
0
 def _grokbody(self):
     if self.__body is None:
         data = self._parser.fp.read()
         # convert to Unicode:
         text = data.decode(self.get_encoding())
         if self.get_content_type() == 'text/x-rst':
             if rst_html is None:
                 print 'ReST-to-HTML conversion not available'
             else:
                 text = rst_html.process_rst(self.filename, text)
         # convert Unicode back to 8-bit string:
         text = text.encode(self.get_charset(), 'xmlcharrefreplace')
         i = text.find('<!--table-stop-->')
         if i >= 0:
             self.__body = text[:i]
             self.__cont = text[i+17:]
         else:
             # there is no wide body
             self.__body = text
Ejemplo n.º 7
0
 def _grokbody(self):
     if self.__body is None:
         data = self._parser.fp.read()
         # convert to Unicode:
         text = data.decode(self.get_encoding())
         if self.get_content_type() == 'text/x-rst':
             if rst_html is None:
                 print 'ReST-to-HTML conversion not available'
             else:
                 text = rst_html.process_rst(self.filename, text)
         # convert Unicode back to 8-bit string:
         text = text.encode(self.get_charset(), 'xmlcharrefreplace')
         i = text.find('<!--table-stop-->')
         if i >= 0:
             self.__body = text[:i]
             self.__cont = text[i+17:]
         else:
             # there is no wide body
             self.__body = text
Ejemplo n.º 8
0
    kw['fragments'] = msg.get('Fragments', '').split()

    template_name = msg.get('Template')

    # Figure out title
    title = msg.get('Title', kw['title'])
    if title == 'None' or title is None:
        title = 'python.org'
    kw['title'] = title

    # Process the textual contents of the page.
    if content_type == 'text/html' or content_type == 'text/x-ht':
        text = decode_string(text)
    elif content_type == 'text/x-rst':
        text = decode_string(text)
        text = rst_html.process_rst(filename, text)
    elif content_type == 'text/plain':
        text = decode_string(text)
        text = '<pre>' + cgi.escape(text) + '</pre>'
    else:
        log('Unknown content-type %r in %s', content_type, dirpath)
        return

    kw['text'] = text

    # Process sidebar navigation.
    kw['quicklinks'] = []
    if msg.has_key('Quick-links'):
        kw['quicklinks'] = parse_nav_list(trim_nav_links(msg.get('Quick-links')))
    elif nav_yml is not None:
        aux = nav_yml.globals.get('aux')
Ejemplo n.º 9
0
def add (title, body):
    html = rst_html.process_rst('quotes', body)
    item = PyRSS2Gen.RSSItem(title=title, 
                             description=html)
    rss.items.append(item)
Ejemplo n.º 10
0
def process_file (filename):
    input = open(filename, 'rt')
    headers = rfc822.Message(input)
    headers.rewindbody()
    fn, ext = os.path.splitext(filename)
    output_filename = fn + '.html'
    content_type = headers.get('content-type', None)
    if content_type not in [None, 'text/html', 'text/x-rst']:
        raise RuntimeError("Unknown content-type %r" % content_type)
    is_text = (filename.endswith('.rst') or 
	       content_type == 'text/x-rst')
	
        
    if is_text:
        # Transform using docutils
        from docutils import core, io
        output_file = StringIO.StringIO()
        body = rst_html.process_rst(filename, input.read())

        # Hackery to make the HTML fit into the page better
        body = re.sub('.*<body[^>]*>', '', body)
        body = re.sub('</body>.*', '', body)
        # Transpose <Hn> headers down by 1: <h1> -> <h2>
	#        for i in [5, 4, 3,2,1]:
	#            body = body.replace('h%i>' % i, 'h%i>' % (i+1))
    else:
        body = input.read()

    input.close()

    path = os.getcwd().split('/')
    index = path.index('sites')
    domain = path[index+1]
    template = open(os.path.join(wwwdir, 'sites/quotations.amk.ca/bin/%s.html' % domain), 'rt').read()

    t = time.localtime( os.stat(filename)[8] )
    (date_year, date_month, date_day,
     date_hour, date_minute, date_second) = t[0:6]
    date_month_name = MONTHS[date_month]

    links = parse_links(filename, headers)
    links = format_linklist(links)

    pagelinks = ""
    if 'Page' in headers and 'Total-Page' in headers:
        page_num = int(headers.get('Page'))
        total_pages = int(headers.get('Total-Page'))
        for i in range(1, total_pages+1):
            if i == 1:
                fn = 'index.html'
            else:
                fn = '%i.html' % i
            if i == page_num:
                pagelinks += '<span class="pagenumber">%i</span>' % i
            else:
                pagelinks += '<a class="pagelink" href="%s">[%i]</a>' % (fn,i)
            pagelinks += ' '

    vars = {
        'content' : body,
        'namespaces':headers.get('namespaces', ''),
        'title':headers.get('title', ''),
        'keywords':headers.get('keywords', ''),
        'description':headers.get('description', ''),
        'meta':headers.get('meta', ''),
        'otherlinks': links,
        'date_day': str(date_day),
        'date_year': str(date_year),
        'date_month_name': date_month_name,
        'endif': '[endif]',
        'pagelinks': pagelinks,
        }

    t = time.localtime( os.stat(filename)[8] )
    (vars['date_year'], vars['date_month'], vars['date_day'],
     vars['date_hour'], vars['date_minute'], vars['date_second']) = t[0:6]
    vars['date_month_name'] = MONTHS[vars['date_month']]

    vars['tree_info'] = build_tree_info(filename)
    vars['temporary'] = headers.getheader('temporary') or ''
    vars['rss_link'] = headers.getheaders('RSS-File') or ""
    vars['rdf_link'] = headers.getheaders('RDF-File') or ""
    rss_files = vars['rss_link']
    if rss_files:
        v = ""
        for file in rss_files:
            v += '<link rel="meta" type="application/rss+xml" href="%s" >' % file
        vars['rss_link'] = v
    rdf_files = vars['rdf_link']
    if rdf_files:
        v = ""
        for file in rdf_files:
            v += '<link rel="meta" type="application/rdf+xml" href="%s" >' % file
        vars['rdf_link'] = v

    for hdr in ['description', 'keywords']:
        if vars.get(hdr):
            vars[hdr] = ('<meta name="%s" content="%s" >'
                            % (hdr, vars[hdr]))

    root, urlpath = get_full_path()
    url = os.path.join('/'.join(urlpath)) + '/' + output_filename
    url = url.replace('./', '')
    url = url.lstrip('/')
    url = url.replace('.html', '')
    vars['url'] = url
        
    t = template
    pos = 0
    blocks = []
    while 1:
        m = variable_pat.search(t, pos)
        if m is None: break
        blocks.append(t[pos:m.start()])
        name = m.group(1)
        if vars.has_key(name):
            blocks.append(str(vars[name]))
        else:
            print 'unknown variable:', repr(name)
        pos = m.end()

    blocks.append(t[pos:])
    output = open(output_filename, 'w')
    output.write(''.join(blocks))
    output.close()