From 1e1a72affcc63b7254ec05ead5a0583419d54142 Mon Sep 17 00:00:00 2001 From: laurentheirendt <laurent.heirendt@uni.lu> Date: Thu, 20 Jun 2019 21:05:49 +0200 Subject: [PATCH] generate folders from template --- contribute.py | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/contribute.py b/contribute.py index 5d77ac7b..35884eba 100644 --- a/contribute.py +++ b/contribute.py @@ -1,6 +1,7 @@ import click import datetime import os +from distutils.dir_util import copy_tree @click.command() @click.option('--date', default=datetime.datetime.today().strftime('%Y-%m-%d'), help='Date of the presentation - format: YYYY-MM-DD') @@ -15,11 +16,15 @@ def main(date, name): # get the directory mainDir = date[:4] + # get the root directory + rootDir = os.path.dirname(os.path.realpath(__file__)) + # generate the full name of the presentation fullName = date + "_" + name # generate the full path fullPath = os.path.join(os.getcwd(), mainDir, fullName) + slidesPath = os.path.join(fullPath, 'slides') # print out a summary click.echo(' > Date: {0}' . format(date)) @@ -29,9 +34,13 @@ def main(date, name): # create the directory if not os.path.exists(fullPath): os.mkdir(fullPath) - click.echo(' > Empty directory {0} created.' . format(fullPath)) + # create an empty slides folder inside + if not os.path.exists(slidesPath): + os.mkdir(slidesPath) + + click.echo(' > Directory for slides {0} created.' . format(slidesPath)) else: - click.echo(' > Directory {0} already exists.' . format(fullPath)) + click.echo(' > Directory for slides{0} already exists.' . format(slidesPath)) # change to the root directory of the presentation os.chdir(fullPath) @@ -50,8 +59,12 @@ def main(date, name): else: click.echo(' > Symlink to package.json already exists.') - - + # copy the contents of the template folder + if not os.path.isfile(os.path.join(fullPath, 'slides', 'index.md')): + copy_tree(os.path.join(rootDir, 'template', 'slides'), slidesPath) + click.echo(' > Template slides copied.') + else: + click.echo(' > Slide deck already exists.') -- GitLab