diff --git a/bootstrap_py/commands.py b/bootstrap_py/commands.py index 0b11660..cb41283 100644 --- a/bootstrap_py/commands.py +++ b/bootstrap_py/commands.py @@ -77,6 +77,7 @@ def main(): pkg_tree = control.PackageTree(pkg_data) pkg_tree.generate() pkg_tree.move() + pkg_tree.vcs_init() except (RuntimeError, BackendFailure, Conflict) as exc: sys.stderr.write('{0}\n'.format(exc)) sys.exit(1) diff --git a/bootstrap_py/control.py b/bootstrap_py/control.py index bca2a0b..39c9913 100644 --- a/bootstrap_py/control.py +++ b/bootstrap_py/control.py @@ -6,6 +6,7 @@ from datetime import datetime from jinja2 import PackageLoader, Environment from bootstrap_py.classifiers import Classifiers +from bootstrap_py.vcs import VCS from bootstrap_py.docs import build_sphinx @@ -140,3 +141,7 @@ def generate(self): self._generate_dirs() self._generate_init() self._generate_files() + + def vcs_init(self): + """Initialize VCS repository.""" + VCS(os.path.join(self.outdir, self.name), self.pkg_data) diff --git a/bootstrap_py/vcs.py b/bootstrap_py/vcs.py new file mode 100644 index 0000000..5163d85 --- /dev/null +++ b/bootstrap_py/vcs.py @@ -0,0 +1,44 @@ +# -*- coding: utf-8 -*- +"""bootstrap_py.vcs.""" +import git + + +class VCS(object): + """VCS class.""" + + def __init__(self, repo_dir, metadata): + """Initialize.""" + self.metadata = metadata + # repo_dir is outdir + self.repo = git.Git(repo_dir) + self.init() + self.config() + self.add_index() + self.initial_commit() + if hasattr(self.metadata, 'username') and self.metadata.username: + self.remote_add() + + def init(self): + """git init.""" + self.repo.init() + + def add_index(self): + """git add .""" + self.repo.add('.') + + def config(self): + """git config.""" + self.repo.config('user.name', self.metadata.author) + self.repo.config('user.email', self.metadata.email) + + def initial_commit(self): + """initial commit.""" + self.repo.commit('-m', 'Initial commit.') + + def remote_add(self): + """git remote add.""" + self.repo.remote('add', + 'origin', + 'git@github.com:{username}/{repo}.git'.format( + username=self.metadata.username, + repo=self.metadata.name)) diff --git a/setup.py b/setup.py index eb2403d..c0f4bcb 100644 --- a/setup.py +++ b/setup.py @@ -76,7 +76,8 @@ def read_content(filepath): requires = ['setuptools', 'Jinja2', 'Sphinx', - 'requests'] + 'requests', + 'GitPython'] extras_require = { 'reST': ['Sphinx'], }