Example #1
0
def main(argv=sys.argv[1:]):
    parser = get_parser()
    try:
        args = parser.parse_known_args(argv)[0]
        d = vars(args)
        d = dict((k, v) for k, v in d.items() if not (v is None))
        notebook_dir = d['notebook_dir']
        ip = d['ip']
        port = d['port']

        if notebook_dir == '.':
            if not exists(pjoin(notebook_dir, "iclientpy")):
                notebook_dir = '.\iclientpy'
            else:
                i = 1
                while exists(pjoin(notebook_dir, "iclientpy-%s" % i)):
                    i += 1
                notebook_dir = ".\iclientpy-%s" % i

        current_path = abspath(dirname(__file__))
        sample_path = pjoin(current_path, '..', 'sample')
        shutil.copytree(sample_path, notebook_dir)
        template_path = pjoin(current_path, 'iclientpy_template.ipynb')
        tgt_path = pjoin(notebook_dir, 'iclientpy_start.ipynb')
        shutil.copy(template_path, tgt_path)

        sys.argv = sys.argv[:1]
        nbmain(notebook_dir=notebook_dir, ip=ip, port=port)
    except SystemExit as err:
        return err.code
    return 0
Example #2
0
def run():
    rootdir = pjoin(dirname(abspath(__file__)), '..', '..')
    uninstall_nbextension()
    uninstall_develop()
    install_develop()
    install_nbextension()
    nbmain(notebook_dir=rootdir)
def main(argv=sys.argv[1:]):
    parser = get_parser()
    try:
        args = parser.parse_known_args(argv)[0]
        d = vars(args)
        d = dict((k, v) for k, v in d.items() if not (v is None))
        notebook_dir = d['notebook_dir']
        ip = d['ip']
        port = d['port']
        param = []
        if "username" in d:
            param.append(d["username"])
        if "password" in d:
            param.append(d["password"])
        if notebook_dir == '.':
            notebook_dir = '.\iclientpy'
        if not exists(notebook_dir):
            mkdir(notebook_dir)
        if not exists(pjoin(notebook_dir, "preliminary_online.ipynb")):
            with open(pjoin(abspath(dirname(__file__)), 'online_template.ipynb'), mode='r',
                      encoding='utf8') as src:
                with open(pjoin(notebook_dir, 'preliminary_online.ipynb'), mode='w+', encoding='utf8') as tar:
                    for line in src.readlines():
                        line = line.replace('{param}', ','.join(["'" + p + "'" for p in param]))
                        tar.write(line)
        sys.argv = sys.argv[:1]
        nbmain(notebook_dir=notebook_dir, ip=ip, port=port)
    except SystemExit as err:
        return err.code
    return 0
Example #4
0
def main(argv=sys.argv[1:]):
    parser = get_parser()
    try:
        if not argv:
            parser.print_usage()
            parser.exit(1)
        args = parser.parse_known_args(argv)[0]
        d = vars(args)
        d = dict((k, v) for k, v in d.items() if not (v is None))
        notebook_dir = d['notebook_dir']
        ip = d['ip']
        port = d['port']
        param = [d["address"]]
        if "username" in d:
            param.append(d["username"])
        if "password" in d:
            param.append(d["password"])
        server = Server(*param)
        services = server.services
        first_map_service_name = 'map-world/rest'
        for index, name in services:
            service = services[index]
            if hasattr(service, 'maps'):
                first_map_service_name = name
                break
        map_service = services[first_map_service_name]
        maps = map_service.maps
        first_map_name = 'World'
        for map_index, map_name in maps:
            first_map_name = map_name
            break

        if notebook_dir == '.':
            if not exists(pjoin(notebook_dir, "iclientpy")):
                notebook_dir = '.\iclientpy'
            else:
                i = 1
                while exists(pjoin(notebook_dir, "iclientpy-%s" % i)):
                    i += 1
                notebook_dir = ".\iclientpy-%s" % i
        with open(pjoin(abspath(dirname(__file__)), 'server_template.ipynb'),
                  mode='r',
                  encoding='utf8') as src:
            with open(pjoin(notebook_dir, 'preliminary_server.ipynb'),
                      mode='w+',
                      encoding='utf8') as tar:
                for line in src.readlines():
                    line = line.replace(
                        '{param}', ','.join(["'" + p + "'" for p in param]))
                    line = line.replace('{map_service}',
                                        "'" + first_map_service_name + "'")
                    line = line.replace('{map_name}', first_map_name)
                    tar.write(line)
        sys.argv = sys.argv[:1]
        nbmain(notebook_dir=notebook_dir, ip=ip, port=port)
    except SystemExit as err:
        return err.code
    return 0
Example #5
0
def main(argv=sys.argv[1:]):
    parser = get_parser()
    try:
        args = parser.parse_known_args(argv)[0]
        d = vars(args)
        d = dict((k, v) for k, v in d.items() if not (v is None))
        notebook_dir = d['notebook_dir']
        ip = d['ip']
        port = d['port']
        if notebook_dir == '.':
            notebook_dir = '.\iclientpy'
        if not exists(notebook_dir):
            current_path = abspath(dirname(__file__))
            sample_path = pjoin(current_path, '..', 'sample')
            shutil.copytree(sample_path, notebook_dir)
        sys.argv = sys.argv[:1]
        nbmain(notebook_dir=notebook_dir,
               ip=ip,
               port=port,
               token='',
               password='')
    except SystemExit as err:
        return err.code
    return 0
Example #6
0
def nbmain(argv):
    """Wrapper around a Jupyter Notebook server entry point. Invoked by the
    :class:`NotebookServer`, via a hook in :func:`fsleyes.main.main`.
    """

    if argv[:2] != ['notebook', 'server']:
        raise RuntimeError('argv does not look like notebook main arguments '
                           '(first args are not \'notebook server\')')

    argv = argv[2:]

    # run the notebook server
    from notebook.notebookapp import main as nbmain

    # first argument is a path
    # to add to the PYTHONPATH.
    # See NotebookServer.run.
    sys.path.insert(0, argv[0])

    # remaining arguments are passed
    # through to notebookapp.main
    return nbmain(argv=argv[1:])