You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
41 lines
1.2 KiB
Python
41 lines
1.2 KiB
Python
import os
|
|
from notebook.auth import passwd
|
|
from jinja2 import Environment, FileSystemLoader
|
|
from random import shuffle
|
|
from getpass import getpass
|
|
|
|
username = input("Username: ")
|
|
port = input("Port: ")
|
|
servername = input("Servername: ")
|
|
|
|
templates_folder = "templates"
|
|
#passwords_file = "passwords.txt"
|
|
|
|
template_env = Environment(loader=FileSystemLoader(templates_folder))
|
|
nbconfig = template_env.get_template("jupyter_notebook_config.py")
|
|
|
|
#passwords = open(passwords_file).read().strip().splitlines()
|
|
#passwords = [w.lower() for w in passwords]
|
|
#shuffle(passwords)
|
|
#password = "".join(passwords[:3])
|
|
|
|
userdata = {}
|
|
userdata['username'] = username
|
|
userdata['port'] = port
|
|
userdata['servername'] = servername
|
|
|
|
password = getpass(f"New password: ")
|
|
|
|
userdata['password'] = password
|
|
userdata['password_sha1'] = passwd(password)
|
|
|
|
with open("jupyter_notebook_config.temp.py", "w") as f:
|
|
print(nbconfig.render(**userdata), file=f)
|
|
os.system(f"sudo mv jupyter_notebook_config.temp.py /home/{username}/.jupyter/jupyter_notebook_config.py")
|
|
os.system(f"sudo chown -R {username}:{username} /home/{username}/.jupyter")
|
|
|
|
os.system(f"sudo service jupyterlab@{username} restart")
|
|
|
|
print("Done!")
|
|
|