diff --git a/.travis.yml b/.travis.yml index 38f17aea2..31219a913 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,10 +8,12 @@ jobs: python: 3.7 - os: linux python: 3.8 + - os: linux + python: 3.9 - os: osx language: generic - python: 3.6 - osx_image: xcode11.4 + python: 3.8 + osx_image: xcode12.5 cache: pip diff --git a/knowledge_repo/templates/knowledge_template.Rmd b/knowledge_repo/templates/knowledge_template.Rmd index 94816d839..3d6515369 100644 --- a/knowledge_repo/templates/knowledge_template.Rmd +++ b/knowledge_repo/templates/knowledge_template.Rmd @@ -1,13 +1,12 @@ --- title: This is a Knowledge Template Header authors: -- sally_smarts -- wesley_wisdom +- {{ author }} tags: - knowledge - example -created_at: 2016-06-29 -updated_at: 2016-06-30 +created_at: {{ current_date }} +updated_at: {{ current_date }} tldr: This is short description of the content and findings of the post. --- diff --git a/knowledge_repo/templates/knowledge_template.ipynb b/knowledge_repo/templates/knowledge_template.ipynb index 789b10a22..cb1cc4857 100644 --- a/knowledge_repo/templates/knowledge_template.ipynb +++ b/knowledge_repo/templates/knowledge_template.ipynb @@ -7,13 +7,12 @@ "---\n", "title: This is a Knowledge Template Header\n", "authors:\n", - "- sally_smarts \n", - "- wesley_wisdom\n", + "- {{ author }} \n", "tags:\n", "- knowledge\n", "- example\n", - "created_at: 2016-06-29\n", - "updated_at: 2016-06-30\n", + "created_at: {{ current_date }}\n", + "updated_at: {{ current_date }}\n", "tldr: This is short description of the content and findings of the post.\n", "---" ] diff --git a/knowledge_repo/templates/knowledge_template.md b/knowledge_repo/templates/knowledge_template.md index 5ee4132e2..ca1148d49 100644 --- a/knowledge_repo/templates/knowledge_template.md +++ b/knowledge_repo/templates/knowledge_template.md @@ -1,13 +1,12 @@ --- title: This is a Knowledge Template Header authors: -- sally_smarts -- wesly_wisdom +- {{ author }} tags: - knowledge - example -created_at: 2016-06-29 -updated_at: 2016-06-30 +created_at: {{ current_date }} +updated_at: {{ current_date }} tldr: This is short description of the content and findings of the post. --- diff --git a/run_tests.sh b/run_tests.sh index 4c01b0872..df5036cb3 100755 --- a/run_tests.sh +++ b/run_tests.sh @@ -36,9 +36,21 @@ git commit -m "Update repository config." &> /dev/null popd &> /dev/null # Add some knowledge_posts -`dirname $0`/scripts/knowledge_repo --repo="git://${test_repo_path}" --dev add `dirname $0`/knowledge_repo/templates/knowledge_template.ipynb -p projects/test/ipynb_test -m "Test commit" --branch master -`dirname $0`/scripts/knowledge_repo --repo="git://${test_repo_path}" --dev add `dirname $0`/knowledge_repo/templates/knowledge_template.Rmd -p projects/test/Rmd_test -m "Test commit" --branch master -`dirname $0`/scripts/knowledge_repo --repo="git://${test_repo_path}" --dev add `dirname $0`/knowledge_repo/templates/knowledge_template.md -p projects/test/md_test -m "Test commit" --branch master +ipynb_file=$(mktemp).ipynb +`dirname $0`/scripts/knowledge_repo --repo="git://${test_repo_path}" --dev create ipynb $ipynb_file +rmd_file=$(mktemp).Rmd +`dirname $0`/scripts/knowledge_repo --repo="git://${test_repo_path}" --dev create Rmd $rmd_file +md_file=$(mktemp).md +`dirname $0`/scripts/knowledge_repo --repo="git://${test_repo_path}" --dev create md $md_file +cat $md_file + +`dirname $0`/scripts/knowledge_repo --repo="git://${test_repo_path}" --dev add $ipynb_file -p projects/test/create_ipynb_test -m "Test create ipynb" --branch master +`dirname $0`/scripts/knowledge_repo --repo="git://${test_repo_path}" --dev add $rmd_file -p projects/test/create_Rmd_test -m "Test create rmd" --branch master +`dirname $0`/scripts/knowledge_repo --repo="git://${test_repo_path}" --dev add $md_file -p projects/test/create_md_test -m "Test create md" --branch master + +# `dirname $0`/scripts/knowledge_repo --repo="git://${test_repo_path}" --dev add `dirname $0`/knowledge_repo/templates/knowledge_template.ipynb -p projects/test/ipynb_test -m "Test commit" --branch master +# `dirname $0`/scripts/knowledge_repo --repo="git://${test_repo_path}" --dev add `dirname $0`/knowledge_repo/templates/knowledge_template.Rmd -p projects/test/Rmd_test -m "Test commit" --branch master +# `dirname $0`/scripts/knowledge_repo --repo="git://${test_repo_path}" --dev add `dirname $0`/knowledge_repo/templates/knowledge_template.md -p projects/test/md_test -m "Test commit" --branch master for post in $(ls `dirname $0`/tests/test_posts); do if [[ "${post}" == *.ipynb ]]; then @@ -57,6 +69,16 @@ echo "Synchronising database index" echo "-----------------------------" echo `dirname $0`/scripts/knowledge_repo --repo="git://${test_repo_path}" reindex --config `dirname $0`/tests/config_server.py +ipynb_file=$(mktemp).ipynb +`dirname $0`/scripts/knowledge_repo --repo="${test_repo_path}" --dev create ipynb $ipynb_file +rmd_file=$(mktemp).Rmd +`dirname $0`/scripts/knowledge_repo --repo="${test_repo_path}" --dev create Rmd $rmd_file +md_file=$(mktemp).md +`dirname $0`/scripts/knowledge_repo --repo="${test_repo_path}" --dev create md $md_file + +`dirname $0`/scripts/knowledge_repo --repo="${test_repo_path}" --dev add $ipynb_file -p projects/test/ipynb_test -m "Test commit" --branch master +`dirname $0`/scripts/knowledge_repo --repo="${test_repo_path}" --dev add $rmd_file -p projects/test/Rmd_test -m "Test commit" --branch master +`dirname $0`/scripts/knowledge_repo --repo="${test_repo_path}" --dev add $md_file -p projects/test/md_test -m "Test commit" --branch master echo echo "Running regression test suite" diff --git a/scripts/knowledge_repo b/scripts/knowledge_repo index 0b6238d04..2a2fa0f06 100755 --- a/scripts/knowledge_repo +++ b/scripts/knowledge_repo @@ -9,12 +9,31 @@ import threading import shutil import argparse import subprocess +import datetime import git import gitdb import webbrowser +import tempfile + +import jinja2 from tabulate import tabulate + +def get_login(): + """ + Try to retrieve the user login to in a + """ + try: + user_login = os.getlogin() + except OSError: + import pwd + user_login = pwd.getpwuid(os.geteuid()).pw_name + except ImportError: + import getpass + user_login = getpass.getuser() + return user_login + # Register handler for SIGTERM, so we can run cleanup code if we are terminated signal.signal(signal.SIGTERM, lambda signum, frame: sys.exit(0)) @@ -266,6 +285,17 @@ if args.action == 'create': shutil.copy(src, args.filename) print("Created a {format} knowledge post template at '{filename}'.".format(format=args.format, filename=args.filename)) sys.exit(0) + + # Replace the current timestamp + with open(src) as f: + print(f'current user is {get_login()}') + result = jinja2.Template(f.read()).render(current_date='{:%Y-%m-%d}'.format(datetime.datetime.now()), author=get_login()) + #result = jinja2.Template(f.read()).render(current_date='{:%Y-%m-%d}'.format(datetime.datetime.now()), author='krepo') + with open(args.filename, "w") as out: + out.write(result) + + #shutil.copy(src, args.filename) + print("Created a {format} knowledge post template at {filename}.".format(format=args.format, filename=args.filename)) # # Check which branches have local work if args.action == 'drafts':