Forked from
R3 / school / courses
870 commits behind the upstream repository.
-
Laurent Heirendt authoredLaurent Heirendt authored
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
contribute.py 1.88 KiB
import click
import datetime
import os
@click.command()
@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 main(date, name):
"""Copies the template folder"""
# validate the date
validateDate(date)
# 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(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:
print('The date {} is invalid'.format(input))
raise
if __name__ == '__main__':
main()