Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added description for init readme #163

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/hangar/cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 ----------------------------------
Expand Down
9 changes: 7 additions & 2 deletions src/hangar/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -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())

Expand Down
3 changes: 2 additions & 1 deletion src/hangar/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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,
Expand Down
4 changes: 3 additions & 1 deletion src/hangar/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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')
Expand Down