From e07a3547f90efaf57e9663da18d4b154610c0b3c Mon Sep 17 00:00:00 2001 From: laurentheirendt <laurent.heirendt@uni.lu> Date: Thu, 20 Jun 2019 20:50:58 +0200 Subject: [PATCH] add symlinks and echo messages --- contribute.py | 42 ++++++++++++++++++++++++++++++++++++++---- 1 file changed, 38 insertions(+), 4 deletions(-) diff --git a/contribute.py b/contribute.py index 56e4815f..5d77ac7b 100644 --- a/contribute.py +++ b/contribute.py @@ -6,8 +6,7 @@ import os @click.option('--date', default=datetime.datetime.today().strftime('%Y-%m-%d'), help='Date of the presentation - format: YYYY-MM-DD') @click.option('--name', default='myPresentation', help='Short name of the presentation.') - -def copyTemplate(date, name): +def main(date, name): """Copies the template folder""" # validate the date @@ -16,13 +15,48 @@ def copyTemplate(date, name): # get the directory mainDir = date[:4] + # generate the full name of the presentation + fullName = date + "_" + name + + # generate the full path + fullPath = os.path.join(os.getcwd(), mainDir, fullName) + # print out a summary click.echo(' > Date: {0}' . format(date)) click.echo(' > Name: {0}' . format(name)) - click.echo(' > Directory: {0}' . format(os.path.join(os.getcwd(), mainDir, name))) + click.echo(' > Directory: {0}' . format(fullPath)) + + # create the directory + if not os.path.exists(fullPath): + os.mkdir(fullPath) + click.echo(' > Empty directory {0} created.' . format(fullPath)) + else: + click.echo(' > Directory {0} already exists.' . format(fullPath)) + + # change to the root directory of the presentation + os.chdir(fullPath) + + # generate the symlink to the theme + if not os.path.islink('theme'): + os.symlink('../../theme', 'theme') + click.echo(' > Symlink to theme created.') + else: + click.echo(' > Symlink to theme already exists.') + + # generate the symlink to the package.json file + if not os.path.islink('package.json'): + os.symlink('../../theme/package.json', 'package.json') + click.echo(' > Symlink to package.json created.') + else: + click.echo(' > Symlink to package.json already exists.') + + + + def validateDate(input): + """Validate a date string to fit the ISO format""" try: datetime.datetime.strptime(input, '%Y-%m-%d') except ValueError: @@ -30,4 +64,4 @@ def validateDate(input): raise if __name__ == '__main__': - copyTemplate() + main() -- GitLab