Example #1
0
def git(config):
    logger.info("Deploying your site via git")

    cwd = os.path.abspath(config.config.output)

    def _call(*args, **kwargs):
        return call(*args, cwd=cwd, **kwargs)

    dot_git_path = os.path.join(cwd, '.git')

    if os.path.exists(dot_git_path) and \
            _call('git remote -v | grep %s' % config.deploy.git.repo) == 0:
        if os.path.exists(dot_git_path):
            shutil.rmtree(dot_git_path)
        _call('git init', silence=True)
        _call('git remote add origin %s' % config.deploy.git.repo)
        if config.deploy.git.branch != 'master':
            _call('git branch -m %s' % config.deploy.git.branch, silence=True)
        _call('git pull origin %s' % config.deploy.git.branch)
        _call('rm -rf *')

        from catsup.generator import Generator

        generator = Generator(config.path)
        generator.generate()

    _call('git add .', silence=True)
    _call('git commit -m "Update at %s"' % str(datetime.datetime.utcnow()),
          silence=True)
    _call('git push origin %s' % config.deploy.git.branch)
Example #2
0
def git(config):
    logger.info("Deploying your site via git")

    cwd = os.path.abspath(config.config.output)

    def _call(*args, **kwargs):
        return call(*args, cwd=cwd, **kwargs)

    dot_git_path = os.path.join(cwd, '.git')

    if os.path.exists(dot_git_path):
        if _call('git remote -v | grep %s' % config.deploy.git.repo) == 0:
            shutil.rmtree(dot_git_path)
    if not os.path.exists(dot_git_path):
        _call('git init')
        _call('git remote add origin %s' % config.deploy.git.repo)
    if _call('git checkout %s' % config.deploy.git.branch) != 0:
        _call('git branch -m %s' % config.deploy.git.branch)
    if config.deploy.git.delete:
        _call('rm -rf *')

    from catsup.generator import Generator

    generator = Generator(config.path)
    generator.generate()

    _call('git add .', silence=True)
    _call('git commit -m "Update at %s"' % str(datetime.datetime.utcnow()),
          silence=True)
    _call('git push origin %s --force' % config.deploy.git.branch)
Example #3
0
    def load_post(self, filename, ext):
        logger.info('Loading file %s' % filename)

        post = Post(filename, ext)
        if post.type == "page":
            self.pages.append(post)
        else:
            self.posts.append(post)
Example #4
0
def search_and_install(name):
    logger.info("Searching theme {name} on GitHub..".format(name=name))
    item = search_github(name=name)
    if not item:
        logger.error("Can't find theme {name}.".format(name=name))
        exit(1)

    logger.info("Fount {name} on GitHub.".format(name=item["name"]))
    install_from_git(item["clone_url"])
Example #5
0
def search_and_install(name):
    logger.info("Searching theme {name} on GitHub..".format(name=name))
    item = search_github(name=name)
    if not item:
        logger.error("Can't find theme {name}.".format(name=name))
        exit(1)

    logger.info("Fount {name} on GitHub.".format(name=item["name"]))
    install_from_git(item["clone_url"])
Example #6
0
 def run(self):
     self.generate()
     self.prepare()
     application = self.application
     application.settings["log_function"] = lambda x: None
     application.settings["static_handler_class"] = StaticFileHandler
     http_server = tornado.httpserver.HTTPServer(application,
                                                 io_loop=self.ioloop)
     http_server.listen(self.port)
     logger.info("Start server at port %s" % self.port)
     self.ioloop.start()
Example #7
0
def rsync(config):
    logger.info("Deploying your site via rsync")
    if config.deploy.rsync.delete:
        args = "--delete"
    else:
        args = ""
    cmd = RSYNC_COMMAND.format(
        ssh_port=config.deploy.rsync.ssh_port,
        args=args,
        deploy_dir=config.config.output,
        ssh_user=config.deploy.rsync.ssh_user,
        ssh_host=config.deploy.rsync.ssh_host,
        document_root=config.deploy.rsync.document_root
    )
    call(cmd)
Example #8
0
def rsync(config):
    logger.info("Deploying your site via rsync")
    if config.deploy.rsync.delete:
        args = "--delete"
    else:
        args = ""
    cmd = RSYNC_COMMAND.format(
        ssh_port=config.deploy.rsync.ssh_port,
        args=args,
        deploy_dir=config.config.output,
        ssh_user=config.deploy.rsync.ssh_user,
        ssh_host=config.deploy.rsync.ssh_host,
        document_root=config.deploy.rsync.document_root
    )
    call(cmd)
Example #9
0
def install_theme(name):
    theme = find_theme(theme_name=name, silence=True)
    if theme:
        # Update theme
        if not os.path.exists(os.path.join(theme.path, '.git')):
            logger.warn("%s is not installed via git."
                        "Can't update it." % theme.name)
        else:
            logger.info("Updating theme %s" % theme.name)
            call("git pull", cwd=theme.path)
        exit(0)

    if ".git" in name or "//" in name:
        install_from_git(name)
    else:
        search_github(name)
Example #10
0
def install_theme(name):
    theme = find_theme(theme_name=name, silence=True)
    if theme:
        # Update theme
        if not os.path.exists(os.path.join(theme.path, '.git')):
            logger.warn("%s is not installed via git."
                        "Can't update it." % theme.name)
        else:
            logger.info("Updating theme %s" % theme.name)
            call("git pull", cwd=theme.path)
        exit(0)

    if ".git" in name or "//" in name:
        install_from_git(name)
    else:
        search_github(name)
Example #11
0
def rsync(config):
    logger.info("Deploying your site via rsync")
    if config.deploy.rsync.delete:
        args = "--delete"
    else:
        args = ""
    cmd = "rsync -avze 'ssh -p {ssh_port}' {args}" \
          " {deploy_dir}/ {ssh_user}@{ssh_host}:{document_root}".format(
        ssh_port=config.deploy.rsync.ssh_port,
        args=args,
        deploy_dir=config.config.output,
        ssh_user=config.deploy.rsync.ssh_user,
        ssh_host=config.deploy.rsync.ssh_host,
        document_root=config.deploy.rsync.document_root
    )
    call(cmd)
Example #12
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))
Example #13
0
 def load_posts(self):
     for f in os.listdir(g.source):
         if f.startswith("."):  # hidden file
             continue
         filename, ext = os.path.splitext(f)
         ext = ext.lower()[1:]
         reader = get_reader(ext)
         if reader is not None:
             logger.info('Loading file %s' % filename)
             path = os.path.join(g.source, f)
             post = reader(path)
             if post.type == "page":
                 self.pages.append(post)
             else:
                 self.posts.append(post)
         else:
             self.non_post_files.append(f)
     self.posts.sort(key=lambda x: x.datetime, reverse=True)
Example #14
0
def clean(settings):
    """
    Usage:
        catsup clean [-s <file>|--settings=<file>]

    Options:
        -s --settings=<file>    specify a setting file. [default: config.json]
        -h --help               Show this screen and exit.
    """
    import catsup.parser.config
    import shutil
    config = catsup.parser.config(settings)
    if os.path.exists(".catsup-cache"):
        shutil.rmtree(".catsup-cache")
        logger.info("Removed cache folder.")
    output_path = config.config.output
    if os.path.exists(output_path):
        shutil.rmtree(output_path)
        logger.info("Removed output folder.")
Example #15
0
def install_theme(name):
    theme = find_theme(theme_name=name, silence=True)
    if theme:
        # Update theme
        if not os.path.exists(os.path.join(theme.path, '.git')):
            logger.warn("%s is not installed via git."
                        "Can't update it." % theme.name)
        else:
            logger.info("Updating theme %s" % theme.name)
            call("git pull", cwd=theme.path)
        exit(0)
    if ".git" in name or "//" in name:
        install_from_git(name)
    else:
        item = search_github(name)
        if not item:
            logger.error("Can't find {} on GitHub.".format(name))
            exit(1)
        install_from_git(item["clone_url"])
Example #16
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))
Example #17
0
def install_theme(name):
    theme = find_theme(theme_name=name, silence=True)
    if theme:
        # Update theme
        if not os.path.exists(os.path.join(theme.path, '.git')):
            logger.warn("%s is not installed via git."
                        "Can't update it." % theme.name)
        else:
            logger.info("Updating theme %s" % theme.name)
            call("git pull", cwd=theme.path)
        exit(0)
    if ".git" in name or "//" in name:
        install_from_git(name)
    else:
        item = search_github(name)
        if not item:
            logger.error("Can't find {} on GitHub.".format(name))
            exit(1)
        install_from_git(item["clone_url"])
Example #18
0
def install(path):
    try:
        theme = find(theme_name=path)
    except:
        pass
    else:
        # Update theme
        if not os.path.exists(os.path.join(theme.path, '.git')):
            logger.warn("%s is not installed via git."
                        "Can't update it." % theme.name)
        else:
            logger.info("Updating theme %s" % theme.name)
            call('git pull', cwd=theme.path)
        sys.exit(0)

    themes_path = os.path.abspath('themes')

    logger.info('Installing theme from %s' % path)

    if not os.path.exists(themes_path):
        os.makedirs(themes_path)

    if os.path.exists(path):
        theme = read_theme(path)
        if not theme:
            sys.exit(1)
        name = theme.name
        logger.info("Found theme %s" % name)

        install_path = os.path.join(themes_path, name)

        shutil.copytree(path, install_path)

    elif path.lower().endswith('.git'):  # a git repo
        os.chdir(themes_path)
        repo_folder = path.split('/')[-1][:-4]
        if os.path.exists(repo_folder):
            shutil.rmtree(repo_folder)
        os.system('git clone %s' % path)
        theme = read_theme(repo_folder)
        if not theme:
            shutil.rmtree(repo_folder)
            sys.exit(0)
        if os.path.exists(theme.name):
            shutil.rmtree(theme.name)

        os.rename(repo_folder, theme.name)

    else:
        logger.error("Can't install theme from %s." % path)
        sys.exit(1)

    logger.info('Theme %s successfully installed' % theme.name)
Example #19
0
 def load_posts(self):
     for f in os.listdir(g.source):
         if f.startswith("."):  # hidden file
             continue
         filename, ext = os.path.splitext(f)
         ext = ext.lower()[1:]
         reader = get_reader(ext)
         if reader is not None:
             logger.info('Loading file %s' % filename)
             path = os.path.join(g.source, f)
             post = reader(path)
             if post.type == "page":
                 self.pages.append(post)
             else:
                 self.posts.append(post)
         else:
             self.non_post_files.append(f)
     self.posts.sort(
         key=lambda x: x.datetime,
         reverse=True
     )
Example #20
0
 def generate(self):
     started_loading = time.time()
     self.reset()
     self.add_archives_and_tags()
     finish_loading = time.time()
     logger.info(
         "Loaded config and %s posts in %.3fs" %
         (len(self.posts), finish_loading - started_loading)
     )
     if self.posts:
         self.generate_posts()
         self.generate_tags()
         self.generate_archives()
         self.generate_feed()
         self.generate_pages()
     else:
         logger.warning("Can't find any post.")
     self.generate_other_pages()
     self.copy_static_files()
     self.renderer.render_sitemap()
     finish_generating = time.time()
     logger.info(
         "Generated %s posts in %.3fs" %
         (len(self.posts), finish_generating - finish_loading)
     )
     logger.info(
         "Generating finished in %.3fs" %
         (finish_generating - started_loading)
     )
Example #21
0
 def on_any_event(self, event):
     logger.info("Captured a file change. Regenerate..")
     try:
         self.generator.generate()
     except:
         logger.error("Error when generating:", exc_info=True)