Ejemplo n.º 1
0
 def extract_meta(cls, file_path):
     """
     Extract meta from YAML file header.
     """
     with fs.open(file_path, 'r') as in_file:
         return meta.extract(in_file)
     return {}
Ejemplo n.º 2
0
 def load_content(self):
     """
     Load content. Meta have to be loaded before loading content!
     """
     if self.file_path:
         with fs.open(self.file_path, 'r') as in_file:
             self.content_raw = meta.stripped(in_file)
             self.content_html = md.html(self.content_raw)
Ejemplo n.º 3
0
Archivo: log.py Proyecto: 05bit/docta
def traceback(out=None):
    """
    Dump traceback to error log file.
    """
    import traceback as tb

    need_close = False
    if out is None:
        out = fs.open(ERROR_LOGFILE, 'w')
        need_close = True

    out.write('-' * 60 + '\n')
    tb.print_exc(limit=20, file=out)
    out.write('-' * 60 + '\n')

    if need_close:
        out.close()
Ejemplo n.º 4
0
Archivo: html.py Proyecto: 05bit/docta
    def render_chapter(self, chapter, home=False):
        # print("Render: %s" % str(chapter))
        output_dir = self.project.output_dir(self.out_format)

        # dir for index
        # if chapter.is_index:
        #     # print(fs.path_for_dir(output_dir, chapter.rel_dir_path))
        #     fs.mkdirs(fs.path_for_dir(output_dir, chapter.rel_dir_path))

        # load content - render - flush content
        chapter.load_content()

        if not chapter.content_raw is None:
            out_file_path = fs.join(output_dir, chapter.rel_dir_path,
                                    self.get_html_name(chapter))
            fs.mkdirs(fs.dirname(out_file_path))
            # print(out_file_path)

            if 'template' in chapter.meta:
                template = self.get_template(chapter.meta['template'])
            elif home:
                template = self.get_template('home.html')
            elif chapter.is_index:
                template = self.get_template('index.html')
            else:
                template = self.get_template('page.html')

            with fs.open(out_file_path, 'w') as out_file:
                context = self.template_context(chapter)
                html = template.render(**context)
                out_file.write(html)
        
        chapter.flush_content()

        # render children
        for child in chapter.children:
            self.render_chapter(child)
Ejemplo n.º 5
0
    def current_config(self):
        if not hasattr(self, '_config'):
            config_path = fs.join(self.current_dir(), self.args.config)
            config_format = (self.args.config.rsplit('.', 1)[-1]).lower()

            try:
                config_file = fs.open(config_path, 'r')
            except:
                raise Exception("can't load config file: %s" % config_path)

            if config_format == 'json':  # JSON config
                try:
                    self._config = json.load(config_file)
                except Exception as e:
                    raise Exception("bad JSON format in config! %s" % log.exc_to_str(e))
            else:  # try YAML by default
                try:
                    self._config = yaml.load(config_file)
                except Exception as e:
                    raise Exception("bad YAML format in config %s" % log.exc_to_str(e))

            config_file.close()

        return self._config