12Script to create or edit your ipython config to use a port and not open a browser window
13when starting. Please ensure you have the newest jupyter notebook version installed
14(greater/equal than 4.0.0).
17from jinja2
import Template
19from subprocess
import check_output
20from basf2
import find_file
25 Main function of the script.
27 print("Please fill in the options you want to use for the notebook server.")
32 port = int(input(
'Network Port (the recommendation is a number between 8000 to 9000): '))
34 print(
"Please fill in a valid network port.")
39 print(
"Will now write your notebook config.")
41 jupyter_template_file = find_file(
"framework/examples/ipython_tools/jupyter_notebook_config.py.j2")
42 with open(jupyter_template_file)
as f:
43 template = Template(f.read())
46 jupyter_folder = check_output([
'jupyter',
'--config-dir']).decode().strip()
48 print(
'Failed to create config file. Have you a recent ipython-notebook installation?')
51 if not os.path.isdir(jupyter_folder):
53 check_output([
'jupyter',
'notebook',
'--generate-config'])
55 print(
"Could not start jupyter notebook. There are many possible reasons for this.\n"
56 "Please see https://confluence.desy.de/display/BI/Software+Jupyter+Notebooks for possible fixes \n"
57 "and feel free to contact software@belle2.org for questions.")
59 config_file = template.render(port=port)
60 jupyter_config_file = os.path.join(jupyter_folder,
'jupyter_notebook_config.py')
63 if os.path.isfile(jupyter_config_file):
65 choice = input(
'You already have a jupyter config file. Do you want to replace it? [Y/n] ').lower()
67 print(
'Not writing config file.')
69 if choice ==
'y' or choice ==
'':
70 print(
'Overwriting config file.')
73 print(
'Not a valid answer.')
76 print(
'Writing config file.')
78 with open(jupyter_config_file,
'w')
as out:
79 out.write(config_file)
82 os.chmod(jupyter_config_file, 0o600)
85if __name__ ==
'__main__':