From 66a7921d381bc71f7ffa769aa0d10a120b955e58 Mon Sep 17 00:00:00 2001 From: nathaniel smith Date: Mon, 11 Sep 2017 22:34:53 -0700 Subject: [PATCH] move click types to their own module --- tildewiki/click_types.py | 30 +++++++++++++++ tildewiki/{git_service.py => git_wrapper.py} | 0 tildewiki/main.py | 39 +++----------------- 3 files changed, 36 insertions(+), 33 deletions(-) create mode 100644 tildewiki/click_types.py rename tildewiki/{git_service.py => git_wrapper.py} (100%) diff --git a/tildewiki/click_types.py b/tildewiki/click_types.py new file mode 100644 index 0000000..d60d1d8 --- /dev/null +++ b/tildewiki/click_types.py @@ -0,0 +1,30 @@ +from os.path import exists as path_exists +from os.path import join as path_join + +from click.types import Path + +class GitRepo(Path): + name = 'git repository' + + def convert(self, value, param, ctx): + path = super().convert(value, param, ctx) + if not path_exists(path_join(path, '.git')): + self.fail('No .git directory found in {}'.format(path)) + + return path + + +class WikiRepo(GitRepo): + name = 'wiki repository' + invalid_wiki_error = '{} does not appear to be a wiki repository: missing {}' + + def convert(self, value, param, ctx): + path = super().convert(value, param, ctx) + + for filepath in ('articles', 'header.md', 'footer.md'): + test_path = path_join('src', filepath) + if not path_exists(path_join(path, test_path)): + self.fail(self.invalid_wiki_error.format( + path, test_path)) + + return path diff --git a/tildewiki/git_service.py b/tildewiki/git_wrapper.py similarity index 100% rename from tildewiki/git_service.py rename to tildewiki/git_wrapper.py diff --git a/tildewiki/main.py b/tildewiki/main.py index 35dd6f7..a387b21 100644 --- a/tildewiki/main.py +++ b/tildewiki/main.py @@ -2,23 +2,22 @@ import os import re from os.path import expanduser -from os.path import exists as path_exists -from os.path import join as path_join import click import pygit2 -from pygit2 import Repository from click import ClickException from click.types import Path +from shutil import rmtree + +from .click_types import ( + WikiRepo +) from .compilation import ( compile_wiki ) -from .git_service import ( - make_commit, - create_repo -) +from . import git_wrapper as git # TODO support reading from env SITE_NAME = 'tilde.town' @@ -34,32 +33,6 @@ DEFAULT_PATH_KWARGS = dict( file_okay=False, dir_okay=True) -class GitRepo(Path): - name = 'git repository' - - def convert(self, value, param, ctx): - path = super().convert(value, param, ctx) - if not path_exists(path_join(path, '.git')): - self.fail('No .git directory found in {}'.format(path)) - - return path - - -class WikiRepo(GitRepo): - name = 'wiki repository' - - def convert(self, value, param, ctx): - path = super().convert(value, param, ctx) - - # TODO check for header.md and footer.md - if not path_exists(path_join(path, 'src/articles')): - self.fail( - '{} does not appear to be a wiki repository; missing src/articles.'.format( - path)) - - return path - - class Config: def __init__(self): self.site_name = SITE_NAME