forked from tildetown/tilde-wiki
first pass on committing stuff, also some cleanup. untested.
parent
05463b382c
commit
39cfa696ac
|
@ -0,0 +1,27 @@
|
||||||
|
import pygit2
|
||||||
|
|
||||||
|
def create_repo(to_clone, local_path, author_name, author_email):
|
||||||
|
repo = pygit2.clone_repository(to_clone, local_path)
|
||||||
|
repo.config['user.name'] = author_name
|
||||||
|
repo.config['user.email'] = author_email
|
||||||
|
|
||||||
|
|
||||||
|
def make_commit(repo_path, author_name, author_email):
|
||||||
|
"""Given a path to a repository, adds everything and commits it."""
|
||||||
|
repo = pygit2.Repository(repo_path)
|
||||||
|
repo.index.add_all()
|
||||||
|
repo.index.write()
|
||||||
|
tree = repo.index.write_tree()
|
||||||
|
author = pygit2.Signature(author_name, author_email)
|
||||||
|
committer = pygit2.Signature(author_name, author_email)
|
||||||
|
oid = repo.create_commit(
|
||||||
|
'refs/head/master',
|
||||||
|
author,
|
||||||
|
committer,
|
||||||
|
'wiki update'.format(author_name),
|
||||||
|
tree,
|
||||||
|
[repo.head.get_object().hex])
|
||||||
|
repo.reset(oid, pygit2.GIT_RESET_HARD)
|
||||||
|
|
||||||
|
# TODO push wrapper
|
||||||
|
# TODO
|
|
@ -7,6 +7,7 @@ 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
|
||||||
|
|
||||||
|
@ -14,6 +15,11 @@ from .compilation import (
|
||||||
compile_wiki
|
compile_wiki
|
||||||
)
|
)
|
||||||
|
|
||||||
|
from .git_service import (
|
||||||
|
make_commit,
|
||||||
|
create_repo
|
||||||
|
)
|
||||||
|
|
||||||
# TODO support reading from env
|
# TODO support reading from env
|
||||||
SITE_NAME = 'tilde.town'
|
SITE_NAME = 'tilde.town'
|
||||||
PUBLISH_PATH = '/var/www/{site_name}/wiki'.format(site_name=SITE_NAME)
|
PUBLISH_PATH = '/var/www/{site_name}/wiki'.format(site_name=SITE_NAME)
|
||||||
|
@ -61,6 +67,11 @@ class Config:
|
||||||
self.preview_path = PREVIEW_PATH
|
self.preview_path = PREVIEW_PATH
|
||||||
self.local_repo_path = LOCAL_REPOSITORY_PATH
|
self.local_repo_path = LOCAL_REPOSITORY_PATH
|
||||||
self.repo_path = REPOSITORY_PATH
|
self.repo_path = REPOSITORY_PATH
|
||||||
|
self.author_name = os.environ.get('LOGNAME')
|
||||||
|
|
||||||
|
@property
|
||||||
|
def author_email(self):
|
||||||
|
return '{}@{}'.format(self.author_name, self.site_name)
|
||||||
|
|
||||||
pass_config = click.make_pass_decorator(Config, ensure=True)
|
pass_config = click.make_pass_decorator(Config, ensure=True)
|
||||||
|
|
||||||
|
@ -72,7 +83,7 @@ pass_config = click.make_pass_decorator(Config, ensure=True)
|
||||||
type=Path(**DEFAULT_PATH_KWARGS))
|
type=Path(**DEFAULT_PATH_KWARGS))
|
||||||
@click.option('--repo-path',
|
@click.option('--repo-path',
|
||||||
default=REPOSITORY_PATH,
|
default=REPOSITORY_PATH,
|
||||||
help='Path to your clone of the shared git repository.',
|
help='Path to the shared wiki repository.',
|
||||||
type=WikiRepo(**DEFAULT_PATH_KWARGS))
|
type=WikiRepo(**DEFAULT_PATH_KWARGS))
|
||||||
@pass_config
|
@pass_config
|
||||||
def main(config, site_name, publish_path, repo_path):
|
def main(config, site_name, publish_path, repo_path):
|
||||||
|
@ -84,14 +95,10 @@ def main(config, site_name, publish_path, repo_path):
|
||||||
config.repo_path = repo_path
|
config.repo_path = repo_path
|
||||||
|
|
||||||
@main.command()
|
@main.command()
|
||||||
@click.option('--local-repo-path',
|
@click.option('--local-repo-path', default=LOCAL_REPOSITORY_PATH,
|
||||||
default=LOCAL_REPOSITORY_PATH,
|
help='Path to shared wiki git repository.', type=Path(file_okay=False))
|
||||||
help='Path to shared wiki git repository.',
|
@click.option('--preview-path', default=PREVIEW_PATH,
|
||||||
type=Path(file_okay=False))
|
help='Local path to wiki for previewing.', type=Path(file_okay=False))
|
||||||
@click.option('--preview-path',
|
|
||||||
default=PREVIEW_PATH,
|
|
||||||
help='Local path to wiki for previewing.',
|
|
||||||
type=Path(file_okay=False))
|
|
||||||
@pass_config
|
@pass_config
|
||||||
def init(config, local_repo_path, preview_path):
|
def init(config, local_repo_path, preview_path):
|
||||||
"""
|
"""
|
||||||
|
@ -109,22 +116,29 @@ def init(config, local_repo_path, preview_path):
|
||||||
raise ClickException(
|
raise ClickException(
|
||||||
'{} already exists. Have you already run wiki init?'.format(
|
'{} already exists. Have you already run wiki init?'.format(
|
||||||
preview_path))
|
preview_path))
|
||||||
|
|
||||||
click.echo('Cloning {} to {}...'.format(config.repo_path, local_repo_path))
|
click.echo('Cloning {} to {}...'.format(config.repo_path, local_repo_path))
|
||||||
pygit2.clone_repository(config.repo_path, local_repo_path)
|
create_repo(
|
||||||
|
config.repo_path,
|
||||||
|
config.local_repo_path,
|
||||||
|
config.author_name,
|
||||||
|
config.author_email
|
||||||
|
)
|
||||||
|
|
||||||
click.echo('Creating {}...'.format(preview_path))
|
click.echo('Creating {}...'.format(preview_path))
|
||||||
os.makedirs(preview_path)
|
os.makedirs(preview_path)
|
||||||
|
|
||||||
click.echo('Compiling wiki preview for the first time...')
|
click.echo('Compiling wiki preview for the first time...')
|
||||||
_preview(config, preview_path, local_repo_path)
|
_preview(config, preview_path, local_repo_path)
|
||||||
|
|
||||||
click.echo('~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~')
|
click.echo('~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~')
|
||||||
click.echo("Congrats, you are ready to contribute to {}'s wiki!".format(
|
click.echo("Congrats, you are ready to contribute to {}'s wiki!".format(
|
||||||
config.site_name
|
config.site_name
|
||||||
))
|
))
|
||||||
|
|
||||||
@main.command()
|
@main.command()
|
||||||
@click.option('--local-repo-path',
|
@click.option('--local-repo-path', default=LOCAL_REPOSITORY_PATH,
|
||||||
default=LOCAL_REPOSITORY_PATH,
|
help='Path to local clone of wiki repository.', type=WikiRepo(**DEFAULT_PATH_KWARGS))
|
||||||
help='Path to shared wiki git repository.',
|
|
||||||
type=WikiRepo(**DEFAULT_PATH_KWARGS))
|
|
||||||
@click.option('--preview-path',
|
@click.option('--preview-path',
|
||||||
default=PREVIEW_PATH,
|
default=PREVIEW_PATH,
|
||||||
help='Local path to wiki for previewing.',
|
help='Local path to wiki for previewing.',
|
||||||
|
@ -135,20 +149,18 @@ def preview(config, preview_path, local_repo_path):
|
||||||
click.confirm(
|
click.confirm(
|
||||||
preview_prompt.format(preview_path),
|
preview_prompt.format(preview_path),
|
||||||
abort=True)
|
abort=True)
|
||||||
|
# TODO actually perform removal
|
||||||
_preview(config, preview_path, local_repo_path)
|
_preview(config, preview_path, local_repo_path)
|
||||||
|
|
||||||
def _preview(config, preview_path, local_repo_path):
|
|
||||||
compile_wiki(local_repo_path, preview_path)
|
|
||||||
click.echo('Your wiki preview is ready! navigate to ~{}/wiki'.format(
|
|
||||||
os.getlogin()))
|
|
||||||
|
|
||||||
@main.command()
|
@main.command()
|
||||||
@click.option('--local-repo-path',
|
@click.option('--local-repo-path', default=LOCAL_REPOSITORY_PATH,
|
||||||
default=LOCAL_REPOSITORY_PATH,
|
help='Path to local clone of wiki repository.', type=WikiRepo(**DEFAULT_PATH_KWARGS))
|
||||||
help='Path to shared wiki git repository.',
|
|
||||||
type=WikiRepo(**DEFAULT_PATH_KWARGS))
|
|
||||||
@pass_config
|
@pass_config
|
||||||
def publish(config, local_repo_path):
|
def publish(config, local_repo_path):
|
||||||
|
# use config.repo_path and config.publish_path
|
||||||
|
make_commit(local_repo_path, config.author_name, config.author_email)
|
||||||
|
# TODO push to repository path
|
||||||
|
# TODO compile from config.repo_path to config.publish_path
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
|
|
||||||
@main.command()
|
@main.command()
|
||||||
|
@ -157,10 +169,13 @@ def get(config):
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
|
|
||||||
@main.command()
|
@main.command()
|
||||||
@click.option('--local-repo-path',
|
@click.option('--local-repo-path', default=LOCAL_REPOSITORY_PATH,
|
||||||
default=LOCAL_REPOSITORY_PATH,
|
help='Path to shared wiki git repository.', type=WikiRepo(**DEFAULT_PATH_KWARGS))
|
||||||
help='Path to shared wiki git repository.',
|
|
||||||
type=WikiRepo(**DEFAULT_PATH_KWARGS))
|
|
||||||
@pass_config
|
@pass_config
|
||||||
def reset(config, local_repo_path):
|
def reset(config, local_repo_path):
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
|
|
||||||
|
def _preview(config, preview_path, local_repo_path):
|
||||||
|
compile_wiki(local_repo_path, preview_path)
|
||||||
|
click.echo('Your wiki preview is ready! navigate to ~{}/wiki'.format(
|
||||||
|
os.environ.get('LOGNAME')))
|
||||||
|
|
Loading…
Reference in New Issue