Exemple #1
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"])
Exemple #2
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"])
Exemple #3
0
def parse(path):
    """
    Parser json configuration file
    """
    try:
        f = open(path, 'r')
    except IOError:
        logger.error("Can't find config file."
                     "Run `catsup init` to generate a new config file.")
        exit(1)
    return update_nested_dict(ObjectDict(), ujson.load(f))
Exemple #4
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)
Exemple #5
0
def parse(path):
    """
    Parser json configuration file
    """
    try:
        f = open(path, 'r')
    except IOError:
        print("Can't find config file %s" % path)

        if prompt_bool("Create a new config file", default=True):
            create_config_file()
        else:
            logger.error("Can't find config file. Exiting..")
        sys.exit(0)
    return update_nested_dict(ObjectDict(), ujson.load(f))
Exemple #6
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 #7
0
def find_theme(config=None, theme_name='', silence=False):
    if not theme_name:
        theme_name = config.theme.name
    theme_name = theme_name.lower()
    theme_gallery = [
        os.path.join(os.path.abspath('themes'), theme_name),
        os.path.join(g.catsup_path, 'themes', theme_name),
    ]
    for path in theme_gallery:
        theme = read_theme(path)
        if theme:
            return theme

    if not silence:
        logger.error("Can't find theme: {name}".format(name=theme_name))
        exit(1)
Exemple #8
0
def find_theme(config=None, theme_name='', silence=False):
    if not theme_name:
        theme_name = config.theme.name
    theme_name = theme_name.lower()
    theme_gallery = [
        os.path.join(os.path.abspath('themes'), theme_name),
        os.path.join(g.catsup_path, 'themes', theme_name),
    ]
    for path in theme_gallery:
        theme = read_theme(path)
        if theme:
            return theme

    if not silence:
        logger.error("Can't find theme: {name}".format(name=theme_name))
        exit(1)
Exemple #9
0
def deploy(settings):
    """
    Usage:
        catsup deploy [-s <file>|--settings=<file>]

    Options:
        -h --help               Show this screen and exit.
        -s --settings=<file>    specify a setting file. [default: config.json]
    """
    import catsup.parser
    import catsup.deploy
    config = catsup.parser.config(settings)
    if config.deploy.default == 'git':
        catsup.deploy.git(config)
    elif config.deploy.default == 'rsync':
        catsup.deploy.rsync(config)
    else:
        logger.error("Unknown deploy: %s" % config.deploy.default)
Exemple #10
0
def deploy(settings):
    """
    Usage:
        catsup deploy [-s <file>|--settings=<file>]

    Options:
        -h --help               Show this screen and exit.
        -s --settings=<file>    specify a setting file. [default: config.json]
    """
    import catsup.parser
    import catsup.deploy
    config = catsup.parser.config(settings)
    if config.deploy.default == 'git':
        catsup.deploy.git(config)
    elif config.deploy.default == 'rsync':
        catsup.deploy.rsync(config)
    else:
        logger.error("Unknown deploy: %s" % config.deploy.default)
Exemple #11
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"])
Exemple #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))
Exemple #13
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"])
Exemple #14
0
 def application(self):
     git_path = ""
     for path in ["", self.generator.config.config.source]:
         path = os.path.abspath(os.path.join(
             g.cwdpath,
             path
         ))
         if os.path.exists(os.path.join(path, ".git")):
             git_path = path
             break
     if not git_path:
         logger.error("Can't find git repository.")
         exit(1)
     params = {
         "path": git_path,
         "generate": self.generate
     }
     return tornado.web.Application([
         (r"/.*?", WebhookHandler, params),
     ])
Exemple #15
0
def open_file(path):
    try:
        return codecs.open(path, "r", encoding="utf-8")
    except IOError:
        logger.error("Can't open file %s" % path)
        exit(1)
Exemple #16
0
def not_valid(path):
    logger.error("%s is not a valid post." % path)
    exit(1)
Exemple #17
0
def open_file(path):
    try:
        return open(path, "r")
    except IOError:
        logger.error("Can't open file %s" % path)
        exit(1)
Exemple #18
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)