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

66 lines
2.6 KiB
Python
Raw Permalink Normal View History

# Small program to put a custom.css file from the course material
# directory to the correct location on the students machines.
#
2022-04-20 07:50:29 +00:00
# Since the directory structure for the custom.css file changed
# this set-up only works for IPython and Jupyter versions after
2024-10-22 07:18:36 +00:00
# the so called the "big split" (version 4 and higher).
import os
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)
2021-10-19 15:19:03 +00:00
proceed = input('''Would you either like to delete the already existing custom.css file (d),
or stop the custom.css set up? (s)''')
if proceed == 's':
2022-04-20 07:50:29 +00:00
print('The installation will be stopped.')
elif proceed == 'd':
os.remove(custom_file)
else:
2022-04-20 07:50:29 +00:00
print('Wrong keyboard input the installation will be stopped.')
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)
2021-10-19 15:19:03 +00:00
print(r'Done! Your custom.css file is now allocated at %s'% custom_file)