"""
Utility functions to retrieve information about available services and setting up security for the Hops platform.

These utils facilitates development by hiding complexity for programs interacting with Hops services.
"""

import socket
import subprocess
import os
import pydoop.hdfs as hdfs

logdir = os.getcwd() + "/tensorboard"

def register():

    global logdir
    if not os.path.exists(logdir):
        os.makedirs(logdir)

    pypath = os.getenv("PYSPARK_PYTHON")
    pydir = os.path.dirname(pypath)

    #find free port
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    s.bind(('',0))
    addr, port = s.getsockname()
    s.close()

    subprocess.Popen([pypath, "%s/tensorboard"%pydir, "--logdir=%s"%logdir, "--port=%d"%port, "--debug"])
    host = socket.gethostname()
    tb_url = "http://{0}:{1}".format(host, port)

    #dump tb host:port to hdfs
    #Current applicationId
    app_id = os.getenv("APP_ID")
    hdfs.dump(tb_url, hdfs.project_path() + "/Jupyter/." + app_id + ".tensorboard", user=hdfs.project_user())


def get_logdir():
    return logdir

@@ -265,29 +265,28 @@
  os%0A
-import pydoop.hdfs as
+from hopsutil import
  hdf
@@ -936,16 +936,52 @@
     hdfs
+_handle = hdfs.get()%0A    hdfs_handle
 .dump(tb

fix bug where wrong hdfs module is being used