Exemple #1
0
 def render_to(self, template, permalink, **kwargs):
     html = self.render(template, **kwargs)
     if not html:
         return
     permalink, output_name = urljoin(g.base_url, permalink), permalink
     kwargs.setdefault("permalink", permalink)
     self.rendered_permalinks.append(permalink)
     if output_name.endswith("/") or "." not in output_name:
         output_name = output_name.rstrip("/")
         output_name += '/index.html'
     output_path = os.path.join(g.output, output_name.lstrip("/"))
     mkdir(os.path.dirname(output_path))
     with open(output_path, "w") as f:
         f.write(html)
Exemple #2
0
 def render_to(self, template, permalink, **kwargs):
     permalink, output_name = urljoin(
         g.base_url,
         permalink
     ), permalink
     kwargs.setdefault("permalink", permalink)
     html = self.render(template, **kwargs)
     if html:
         self.rendered_permalinks.append(permalink)
         if output_name.endswith("/") or "." not in output_name:
             output_name = output_name.rstrip("/")
             output_name += '/index.html'
         output_path = os.path.join(g.output, output_name.lstrip("/"))
         mkdir(os.path.dirname(output_path))
         with open(output_path, "w") as f:
             f.write(html)
Exemple #3
0
def install_from_git(clone_url):
    mkdir(THEMES_PATH)
    os.chdir(THEMES_PATH)
    tmp_dir = tempfile.mkdtemp()
    os.system('git clone {clone_url} {tmp_dir}'.format(clone_url=clone_url,
                                                       tmp_dir=tmp_dir))
    theme = read_theme(tmp_dir)
    if not theme:
        logger.error("{clone_url} is not a Catsup theme repo.".format(
            clone_url=clone_url))
        shutil.rmtree(tmp_dir)
    if os.path.exists(theme.name):
        shutil.rmtree(theme.name)

    os.rename(tmp_dir, theme.name)
    logger.info("Installed theme {name}".format(name=name))
Exemple #4
0
def install_from_git(clone_url):
    mkdir(THEMES_PATH)
    os.chdir(THEMES_PATH)
    tmp_dir = tempfile.mkdtemp()
    os.system('git clone {clone_url} {tmp_dir}'.format(
        clone_url=clone_url,
        tmp_dir=tmp_dir
    ))
    theme = read_theme(tmp_dir)
    if not theme:
        logger.error("{clone_url} is not a Catsup theme repo.".format(
            clone_url=clone_url
        ))
        shutil.rmtree(tmp_dir)
    if os.path.exists(theme.name):
        shutil.rmtree(theme.name)

    os.rename(tmp_dir, theme.name)
    logger.info("Installed theme {name}".format(name=name))
Exemple #5
0
def create_config_file(path=None):
    if path:
        os.chdir(path)

    current_dir = os.getcwd()
    config_path = os.path.join(current_dir, 'config.json')

    if os.path.exists(config_path):
        print('These is a config.json in current directory(%s), '
              'Have you run `catsup init` before?' % current_dir)
        return

    mkdir("posts")

    template = get_template()

    with open(config_path, 'w') as f:
        f.write(template)

    print('Created a new config file.'
          'Please configure your blog by editing config.json')
Exemple #6
0
def create_config_file(path=None):
    if path:
        os.chdir(path)

    current_dir = os.getcwd()
    config_path = os.path.join(current_dir, 'config.json')

    if os.path.exists(config_path):
        from catsup.logger import logger
        logger.warning("Config file already exist.")
        exit(1)

    mkdir("posts")
    mkdir("static")

    template = get_template()

    with open(config_path, 'w') as f:
        f.write(template)

    print('Created a new config file.'
          'Please configure your blog by editing config.json')
Exemple #7
0
 def __init__(self):
     self.directory = get_cache_path("jinja2")
     mkdir(self.directory)