From 2a5caff259ad699db56676f14a70cb94e75d8a5b Mon Sep 17 00:00:00 2001 From: Karen Date: Mon, 11 Nov 2019 21:42:19 +0530 Subject: [PATCH] Added description for init readme --- src/hangar/cli/cli.py | 5 +++-- src/hangar/context.py | 9 +++++++-- src/hangar/repository.py | 3 ++- src/hangar/utils.py | 4 +++- 4 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/hangar/cli/cli.py b/src/hangar/cli/cli.py index ccca1c5e..589586d8 100644 --- a/src/hangar/cli/cli.py +++ b/src/hangar/cli/cli.py @@ -42,16 +42,17 @@ def main(ctx): # pragma: no cover @main.command() @click.option('--name', prompt='User Name', help='first and last name of user') @click.option('--email', prompt='User Email', help='email address of the user') +@click.option('--description', prompt='Description', help='description', default=False) @click.option('--overwrite', is_flag=True, default=False, help='overwrite a repository if it exists at the current path') @pass_repo -def init(repo: Repository, name, email, overwrite): +def init(repo: Repository, name, email, overwrite, description=None): """Initialize an empty repository at the current path """ if repo.initialized and (not overwrite): click.echo(f'Repo already exists at: {repo.path}') else: - repo.init(user_name=name, user_email=email, remove_old=overwrite) + repo.init(user_name=name, user_email=email, remove_old=overwrite, description=description) # -------------------------- Checkout Writer ---------------------------------- diff --git a/src/hangar/context.py b/src/hangar/context.py index ce84c205..03ae87ce 100644 --- a/src/hangar/context.py +++ b/src/hangar/context.py @@ -235,6 +235,7 @@ def _startup(self) -> bool: def _init_repo(self, user_name: str, user_email: str, + description: str = None, remove_old: bool = False) -> os.PathLike: """Create a new hangar repositiory at the specified environment path. @@ -271,13 +272,17 @@ def _init_repo(self, os.makedirs(pjoin(self.repo_path, c.DIR_DATA)) print(f'Hangar Repo initialized at: {self.repo_path}') - userConf = {'USER': {'name': user_name, 'email': user_email}} + if description: + userConf = {'name': user_name, 'email': user_email, 'description': description} + else: + userConf = {'name': user_name, 'email': user_email} + CFG = configparser.ConfigParser() CFG.read_dict(userConf) with open(pjoin(self.repo_path, c.CONFIG_USER_NAME), 'w') as f: CFG.write(f) - readmeTxt = readme_contents(user_name, user_email) + readmeTxt = readme_contents(user_name, user_email, description) with open(pjoin(self.repo_path, c.README_FILE_NAME), 'w') as f: f.write(readmeTxt.getvalue()) diff --git a/src/hangar/repository.py b/src/hangar/repository.py index 1eec35b7..8d25c31f 100644 --- a/src/hangar/repository.py +++ b/src/hangar/repository.py @@ -297,6 +297,7 @@ def clone(self, user_name: str, user_email: str, remote_address: str, def init(self, user_name: str, user_email: str, + description: str = None, *, remove_old: bool = False) -> os.PathLike: """Initialize a Hangar repository at the specified directory path. @@ -320,7 +321,7 @@ def init(self, initialized on disk. """ pth = self._env._init_repo( - user_name=user_name, user_email=user_email, remove_old=remove_old) + user_name=user_name, user_email=user_email, remove_old=remove_old, description=description) return pth def log(self, diff --git a/src/hangar/utils.py b/src/hangar/utils.py index 771d8da6..81b3ce99 100644 --- a/src/hangar/utils.py +++ b/src/hangar/utils.py @@ -407,7 +407,7 @@ def parse_bytes(s: str) -> int: return int(n * mult) -def readme_contents(user_name: str, user_email: str) -> StringIO: +def readme_contents(user_name: str, user_email: str, description: str = None) -> StringIO: """Create the Hangar README.txt contents used to fill out file on repo initialization Parameters @@ -428,6 +428,8 @@ def readme_contents(user_name: str, user_email: str) -> StringIO: buf.write(f'This repository was initialized by:\n') buf.write(f' User Name: {user_name}\n') buf.write(f' User Email: {user_email}\n') + if description: + buf.write(f' Description: {description}\n') buf.write(f' Creation Time: {time.asctime(time.gmtime())} UTC\n') buf.write(f' Software Version: {__version__}\n') buf.write(f'\n')