PK OWnI),z z nbopen/__init__.py"""Open a notebook from the command line in the best available server"""
__version__ = '0.4.1'
from .nbopen import main
PK "RnI}
2 nbopen/__main__.pyfrom .nbopen import main
main()
PK QnIqw
# nbopen/application-x-ipynb+json.xml
IPython notebook
PK RnIi97 nbopen/install_win.py"""Install GUI integration on Windows"""
import sys
try:
import winreg
except ImportError:
import _winreg as winreg
SZ = winreg.REG_SZ
with winreg.CreateKey(winreg.HKEY_CURRENT_USER, "Software\Classes\.ipynb") as k:
winreg.SetValue(k, "", SZ, "Jupyter.nbopen")
winreg.SetValueEx(k, "Content Type", 0, SZ, "application/x-ipynb+json")
winreg.SetValueEx(k, "PerceivedType", 0, SZ, "document")
with winreg.CreateKey(k, "OpenWithProgIds") as openwith:
winreg.SetValueEx(openwith, "Jupyter.nbopen", 0, winreg.REG_NONE, b'')
executable = sys.executable
if executable.endswith("python.exe"):
executable = executable[:-10] + 'pythonw.exe'
launch_cmd = '"{}" -m nbopen "%1"'.format(executable)
with winreg.CreateKey(winreg.HKEY_CURRENT_USER, "Software\Classes\Jupyter.nbopen") as k:
winreg.SetValue(k, "", SZ, "IPython notebook")
with winreg.CreateKey(k, "shell\open\command") as launchk:
winreg.SetValue(launchk, "", SZ, launch_cmd)
try:
from win32com.shell import shell, shellcon
shell.SHChangeNotify(shellcon.SHCNE_ASSOCCHANGED, shellcon.SHCNF_IDLIST, None, None)
except ImportError:
print("You may need to restart for association with .ipynb files to work")
print(" (pywin32 is needed to notify Windows of the change)")
PK UnI[W W nbopen/install_xdg.py"""Install GUI integration on XDG platforms (primarily Linux)"""
import os
from pathlib import Path
import shutil
from subprocess import run
_PKGDIR = Path(__file__).resolve().parent
if not os.environ.get('XDG_DATA_HOME'):
os.environ['XDG_DATA_HOME'] = os.path.expanduser('~/.local/share')
print("Installing data files to:", os.environ['XDG_DATA_HOME'])
#export XDG_UTILS_DEBUG_LEVEL=1 #DEBUG
print('Installing mimetype data...')
run(['xdg-mime', 'install', str(_PKGDIR / 'application-x-ipynb+json.xml')],
check=True)
print('Installing icons...')
for s in [16, 24, 32, 48, 64, 128, 256, 512]:
src = _PKGDIR / "icons/ipynb_icon_{s}x{s}.png".format(s=s)
run(['xdg-icon-resource', 'install', '--noupdate', '--size', str(s),
'--context', 'mimetypes', str(src), 'application-x-ipynb+json'],
check=True)
run(['xdg-icon-resource', 'forceupdate'], check=True)
print('Installing desktop file...')
apps_dir = os.path.join(os.environ['XDG_DATA_HOME'], "applications/")
shutil.copy2(str(_PKGDIR / 'nbopen.desktop'), apps_dir)
run(['update-desktop-database', apps_dir], check=True)
PK QnIL nbopen/nbopen.desktop[Desktop Entry]
Type=Application
Version=1.0
Name=IPython Notebook
# This is for opening files, not launching the notebook from a menu
NoDisplay=true
Exec=nbopen %f
Terminal=false
MimeType=application/x-ipynb+json;
PK VnIք3 nbopen/nbopen.py#!/usr/bin/python3
import argparse
import os.path
import webbrowser
from notebook import notebookapp
from notebook.utils import url_path_join, url_escape
__version__ = '0.4'
def find_best_server(filename):
servers = [si for si in notebookapp.list_running_servers() \
if filename.startswith(si['notebook_dir'])]
try:
return max(servers, key=lambda si: len(si['notebook_dir']))
except ValueError:
return None
def nbopen(filename):
filename = os.path.abspath(filename)
home_dir = os.path.expanduser('~')
server_inf = find_best_server(filename)
if server_inf is not None:
print("Using existing server at", server_inf['notebook_dir'])
path = os.path.relpath(filename, start=server_inf['notebook_dir'])
url = url_path_join(server_inf['url'], 'notebooks', url_escape(path))
na = notebookapp.NotebookApp.instance()
na.load_config_file()
browser = webbrowser.get(na.browser or None)
browser.open(url, new=2)
else:
if filename.startswith(home_dir):
nbdir = home_dir
else:
nbdir = os.path.dirname(filename)
print("Starting new server")
notebookapp.launch_new_instance(file_to_run=os.path.abspath(filename),
notebook_dir=nbdir,
open_browser=True,
argv=[], # Avoid it seeing our own argv
)
def main(argv=None):
ap = argparse.ArgumentParser()
ap.add_argument('filename', help='The notebook file to open')
args = ap.parse_args(argv)
nbopen(args.filename)
if __name__ == '__main__':
main()
P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