1
0
Fork 0
mirror of https://gitlab.rlp.net/pgp/pgp1-python-einfuehrung synced 2024-11-16 13:48:11 +00:00

Changed stylesheet set-up from ipynb to py.

This commit is contained in:
dwenz 2020-05-02 12:58:36 +02:00
parent a264b46501
commit 66c1fb9c54
2 changed files with 66 additions and 115 deletions

View file

@ -1,115 +0,0 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"ExecuteTime": {
"end_time": "2019-09-20T20:32:38.385152Z",
"start_time": "2019-09-20T20:32:29.330519Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Checking first your IPython version...\n",
"Setting up a custom made Jupyter Style.\n",
"Searching for the Jupyter profile directory...\n",
"Your Jupyter profile directory is allocated at C:\\Users\\Daniel\\.jupyter\n",
"Checking if either the custom directory or a custom.css file already exists.\n",
"The custom directory exists, but no custom.css file was found.\n",
"Copying data now.\n",
"Done! Your custom.css file is now allocated at C:\\Users\\Daniel\\.jupyter\\custom\\custom.css\n"
]
}
],
"source": [
"# Small program to put a custom.css file from the course material \n",
"# directory to the correct location on the students machines.\n",
"# \n",
"# Since the directory sturcture for the custom.css file changed \n",
"# this set-up only works for IPython and Jupyter versions after \n",
"# the so called the \"big splitt\" (version 4 and higher).\n",
"import os\n",
"import sys\n",
"import jupyter_core\n",
"import IPython\n",
"import shutil\n",
"from time import sleep \n",
"\n",
"\n",
"print('Checking first your IPython version...')\n",
"sleep(2)\n",
"version1,version2,__,__ = IPython.version_info # Checking for the IPython version \n",
" # Returns the version number as tuble with integer\n",
"\n",
"if (version1 + version2/10) < 4:\n",
" print('''Your IPython version is only %i.%i. \n",
"This set-up program requires an IPython version after the \"big splitt\" (4.0 or higher).\n",
"Please contact the tutor.'''% (version1,version2)) \n",
"\n",
"else:\n",
" script_dir = os.path.abspath('') # Gets the directory name of the current set-up file\n",
" custiom_source_file = os.path.join(script_dir,'custom.css')\n",
" print('''Setting up a custom made Jupyter Style.\n",
"Searching for the Jupyter profile directory...''')\n",
" sleep(2)\n",
" jupyter_path = jupyter_core.paths.jupyter_config_dir()\n",
" print(r'Your Jupyter profile directory is allocated at %s'% jupyter_path)\n",
" sleep(2)\n",
" print('Checking if either the custom directory or a custom.css file already exists.')\n",
" sleep(2)\n",
" custom_dir = os.path.join(jupyter_path,'custom')\n",
" custom_file = os.path.join(custom_dir,'custom.css')\n",
"\n",
" if os.path.isdir(custom_dir) and os.path.exists(custom_file):\n",
" print('''The custom.css file already exists. \n",
"How do you want to proceed?''')\n",
" sleep(2)\n",
"\n",
" proceed = input('''Would you either like to delte the already existing custom.css file (d), \n",
"or stop the custom.css set up? (s)''')\n",
" if proceed == 's':\n",
" print('The installation will be stoped.')\n",
" elif proceed == 'd':\n",
" os.remove(custom_file)\n",
" else:\n",
" print('Wrong keyboard input the installation will be stoped.')\n",
"\n",
" elif os.path.isdir(custom_dir):\n",
" print('''The custom directory exists, but no custom.css file was found.\n",
"Copying data now.''')\n",
" shutil.copy(custiom_source_file, custom_dir)\n",
" sleep(1)\n",
" print(r'Done! Your custom.css file is now allocated at %s'% custom_file)\n",
" else:\n",
" print('The custom directory does not exists creating a new one.')\n",
" os.makedirs(custom_dir, exist_ok = True)\n",
" sleep(2)\n",
" print('Directory has been created, copying data now.')\n",
" shutil.copy(custiom_source_file, custom_dir)\n",
" sleep(1)\n",
" print(r'Done! Your custom.css file is now allocated at %s'% custom_file)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"anaconda-cloud": {},
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
}
},
"nbformat": 4,
"nbformat_minor": 1
}

66
costum_set_up.py Normal file
View file

@ -0,0 +1,66 @@
# Small program to put a custom.css file from the course material
# directory to the correct location on the students machines.
#
# Since the directory sturcture for the custom.css file changed
# this set-up only works for IPython and Jupyter versions after
# the so called the "big splitt" (version 4 and higher).
import os
import sys
import jupyter_core
import IPython
import shutil
from time import sleep
print('Checking first your IPython version...')
sleep(2)
version1,version2,__,__ = IPython.version_info # Checking for the IPython version
# Returns the version number as tuble with integer
if (version1 + version2/10) < 4:
print('''Your IPython version is only %i.%i.
This set-up program requires an IPython version after the "big splitt" (4.0 or higher).
Please contact the tutor.'''% (version1,version2))
else:
script_dir = os.path.abspath('') # Gets the directory name of the current set-up file
custiom_source_file = os.path.join(script_dir,'custom.css')
print('''Setting up a custom made Jupyter Style.
Searching for the Jupyter profile directory...''')
sleep(2)
jupyter_path = jupyter_core.paths.jupyter_config_dir()
print(r'Your Jupyter profile directory is allocated at %s'% jupyter_path)
sleep(2)
print('Checking if either the custom directory or a custom.css file already exists.')
sleep(2)
custom_dir = os.path.join(jupyter_path,'custom')
custom_file = os.path.join(custom_dir,'custom.css')
if os.path.isdir(custom_dir) and os.path.exists(custom_file):
print('''The custom.css file already exists.
How do you want to proceed?''')
sleep(2)
proceed = input('''Would you either like to delte the already existing custom.css file (d),
or stop the custom.css set up? (s)''')
if proceed == 's':
print('The installation will be stoped.')
elif proceed == 'd':
os.remove(custom_file)
else:
print('Wrong keyboard input the installation will be stoped.')
elif os.path.isdir(custom_dir):
print('''The custom directory exists, but no custom.css file was found.
Copying data now.''')
shutil.copy(custiom_source_file, custom_dir)
sleep(1)
print(r'Done! Your custom.css file is now allocated at %s'% custom_file)
else:
print('The custom directory does not exists creating a new one.')
os.makedirs(custom_dir, exist_ok = True)
sleep(2)
print('Directory has been created, copying data now.')
shutil.copy(custiom_source_file, custom_dir)
sleep(1)
print(r'Done! Your custom.css file is now allocated at %s'% custom_file)