Example #1
0
 def valid_value(self, value):
     if super(ServerChoiceField, self).valid_value(value):
         return True
     elif book_utils.get_server_defaults(value):
         return True
     else:
         return False
Example #2
0
 def valid_value(self, value):
     if super(ServerChoiceField, self).valid_value(value):
         return True
     elif book_utils.get_server_defaults(value):
         return True
     else:
         return False
    def _parse_credits(self, force=False):
        # open the Credits chapter that has a list of authors for each chapter.
        # each chapter is listed thus (linebreaks added):
        #   <i>CHAPTER TITLE</i><br/>&copy; First Author 2007<br/>
        #   Modifications:<br/>Second Author 2007, 2008<br/>
        #   Third Author 2008<br/>Fourth Author 2008<br/><hr/>
        #
        # where "CHAPTER TITLE" is as appears in TOC.txt, and "X
        # Author" are the names TWiki has for authors.  So the thing
        # to do is look for the <i> tags and match them to the toc.
        #
        # the chapter title is not guaranteed unique (but usually is).
        if self.credits is not None and not force:
            log("not reloading metadata")
            return

        self.credits = {}
        self.contributors = set()
        self.titles = []

        credits_html = self.get_chapter_html('Credits', wrapped=True)
        try:
            tree = lxml.html.document_fromstring(credits_html, parser=utf8_html_parser)
        except UnicodeDecodeError, e:
            log("book isn't unicode! (%s)" %(e,))
            encoding = get_server_defaults(self.server)['toc-encoding']
            parser = lxml.html.HTMLParser(encoding=encoding)
            tree = lxml.html.document_fromstring(credits_html, parser=parser)
Example #4
0
    def _parse_credits(self, force=False):
        # open the Credits chapter that has a list of authors for each chapter.
        # each chapter is listed thus (linebreaks added):
        #   <i>CHAPTER TITLE</i><br/>&copy; First Author 2007<br/>
        #   Modifications:<br/>Second Author 2007, 2008<br/>
        #   Third Author 2008<br/>Fourth Author 2008<br/><hr/>
        #
        # where "CHAPTER TITLE" is as appears in TOC.txt, and "X
        # Author" are the names TWiki has for authors.  So the thing
        # to do is look for the <i> tags and match them to the toc.
        #
        # the chapter title is not guaranteed unique (but usually is).
        if self.credits is not None and not force:
            log("not reloading metadata")
            return

        self.credits = {}
        self.contributors = set()
        self.titles = []

        credits_html = self.get_chapter_html('Credits', wrapped=True)
        try:
            tree = lxml.html.document_fromstring(credits_html,
                                                 parser=utf8_html_parser)
        except UnicodeDecodeError, e:
            log("book isn't unicode! (%s)" % (e, ))
            encoding = get_server_defaults(self.server)['toc-encoding']
            parser = lxml.html.HTMLParser(encoding=encoding)
            tree = lxml.html.document_fromstring(credits_html, parser=parser)
Example #5
0
def get_default_css(server=config.DEFAULT_SERVER, mode='book'):
    """Get the default CSS text for the selected server"""
    log(server)
    cssfile = url2path(get_server_defaults(server)['css-%s' % mode])
    log(cssfile)
    f = open(cssfile)
    s = f.read()
    f.close()
    return s
def toc_iterator(server, book):
    """TOC.txt has 3 lines per chapter.  Fetch them and yield them in
    triples.
    """
    url = config.TOC_URL % (server, book)
    log('getting TOC: %s' % url)
    f = urlopen(url)
    encoding = get_server_defaults(server)['toc-encoding']
    while True:
        try:
            if encoding is not None:
                yield TocItem(f.next().decode(encoding).strip().encode('utf-8'),
                              f.next().decode(encoding).strip().encode('utf-8'),
                              f.next().decode(encoding).strip().encode('utf-8'))
            else:
                yield TocItem(f.next().strip(),
                              f.next().strip(),
                              f.next().strip())
        except StopIteration:
            break
    f.close()
Example #7
0
def toc_iterator(server, book):
    """TOC.txt has 3 lines per chapter.  Fetch them and yield them in
    triples.
    """
    url = config.TOC_URL % (server, book)
    log('getting TOC: %s' % url)
    f = urlopen(url)
    encoding = get_server_defaults(server)['toc-encoding']
    while True:
        try:
            if encoding is not None:
                yield TocItem(
                    f.next().decode(encoding).strip().encode('utf-8'),
                    f.next().decode(encoding).strip().encode('utf-8'),
                    f.next().decode(encoding).strip().encode('utf-8'))
            else:
                yield TocItem(f.next().strip(),
                              f.next().strip(),
                              f.next().strip())
        except StopIteration:
            break
    f.close()
Example #8
0
             },
    'nowhere': {'sync': (config.NOWHERE_TEMPLATE, 'text/plain; charset=utf-8'),
                'async': (config.NOWHERE_TEMPLATE, 'text/plain; charset=utf-8'),
                'poll': (config.ASYNC_TEMPLATE, 'text/plain; charset=utf-8'),
                'default': 'sync',
                },
}

DEFAULT_MODE = 'book'
DEFAULT_PDF_TYPE = 'book'
DEFAULT_MAX_AGE = -1 #negative number means server default

FORM_INPUTS = (
    # input, name, input type, contents key/input value, CSS classes, extra text, validator, default
    ("server", "FLOSS Manuals server", "select", "server_options", "", "",
     lambda x: get_server_defaults(x) is not None, config.DEFAULT_SERVER,
     ),
    # book name can be: BlahBlah/Blah_Blah
    ("book", "Manual", "input[type=text]", "book_options", "", "",
     lambda x: len(x) < 999 and is_utf8(x), None,
     ),
    ("title", "Book title", "input[type=text]", None, "", "leave blank for default",
     lambda x: len(x) < 999 and is_utf8(x), None,
     ),
    ("mode", "Document type", "select", "pdf_types", "openoffice", "",
     CGI_MODES.__contains__, DEFAULT_MODE,
     ),

    ("booksize", "Page size", "select", "size_options", "", "",
     config.PAGE_SIZE_DATA.__contains__, config.DEFAULT_SIZE,
     ),
Example #9
0
def get_default_css(server=config.DEFAULT_SERVER, mode='book'):
    """Get the default CSS text for the selected server"""
    css_file_path = os.path.join(config.STATIC_ROOT, get_server_defaults(server)['css-%s' % mode])
    return open(css_file_path, "r").read()
Example #10
0
def fetch_css(request):
    server = request.REQUEST.get("server", config.DEFAULT_SERVER)
    mode   = request.REQUEST.get("pdf_type", form_config.DEFAULT_PDF_TYPE)
    path   = book_utils.get_server_defaults(server)['css-%s' % mode]
    path   = os.path.join(config.STATIC_ROOT, path)
    return HttpResponse(file(path, "r").read())
Example #11
0
def fetch_css(request):
    server = request.REQUEST.get("server", config.DEFAULT_SERVER)
    mode = request.REQUEST.get("pdf_type", form_config.DEFAULT_PDF_TYPE)
    path = book_utils.get_server_defaults(server)['css-%s' % mode]
    path = os.path.join(config.STATIC_ROOT, path)
    return HttpResponse(file(path, "r").read())
Example #12
0
def get_default_css(server=config.DEFAULT_SERVER, mode='book'):
    """Get the default CSS text for the selected server"""
    css_file_path = os.path.join(config.STATIC_ROOT,
                                 get_server_defaults(server)['css-%s' % mode])
    return open(css_file_path, "r").read()