move click types to their own module

master
nathaniel smith 2017-09-11 22:34:53 -07:00
parent 39cfa696ac
commit 66a7921d38
3 changed files with 36 additions and 33 deletions

View File

@ -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

View File

@ -2,23 +2,22 @@
import os import os
import re import re
from os.path import expanduser from os.path import expanduser
from os.path import exists as path_exists
from os.path import join as path_join
import click import click
import pygit2 import pygit2
from pygit2 import Repository
from click import ClickException from click import ClickException
from click.types import Path from click.types import Path
from shutil import rmtree
from .click_types import (
WikiRepo
)
from .compilation import ( from .compilation import (
compile_wiki compile_wiki
) )
from .git_service import ( from . import git_wrapper as git
make_commit,
create_repo
)
# TODO support reading from env # TODO support reading from env
SITE_NAME = 'tilde.town' SITE_NAME = 'tilde.town'
@ -34,32 +33,6 @@ DEFAULT_PATH_KWARGS = dict(
file_okay=False, file_okay=False,
dir_okay=True) 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: class Config:
def __init__(self): def __init__(self):
self.site_name = SITE_NAME self.site_name = SITE_NAME