|
@@ -19,6 +19,11 @@
|
|
|
import math
|
|
import math
|
|
|
import datetime
|
|
import datetime
|
|
|
|
|
|
|
|
|
|
+from django.urls import reverse
|
|
|
|
|
+
|
|
|
|
|
+from hadoop.fs.hadoopfs import Hdfs
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
def big_filesizeformat(bytes):
|
|
def big_filesizeformat(bytes):
|
|
|
if bytes is None or bytes is "":
|
|
if bytes is None or bytes is "":
|
|
|
return "N/A"
|
|
return "N/A"
|
|
@@ -78,3 +83,27 @@ def format_duration_in_millis(duration=0):
|
|
|
output.append("%dm" % minutes)
|
|
output.append("%dm" % minutes)
|
|
|
output.append("%ds" % seconds)
|
|
output.append("%ds" % seconds)
|
|
|
return ":".join(output)
|
|
return ":".join(output)
|
|
|
|
|
+
|
|
|
|
|
+def location_to_url(location, strict=True, is_embeddable=False):
|
|
|
|
|
+ """
|
|
|
|
|
+ If possible, returns a file browser URL to the location.
|
|
|
|
|
+ Prunes HDFS URI to path.
|
|
|
|
|
+ Location is a URI, if strict is True.
|
|
|
|
|
+
|
|
|
|
|
+ Python doesn't seem to have a readily-available URI-comparison
|
|
|
|
|
+ library, so this is quite hacky.
|
|
|
|
|
+ """
|
|
|
|
|
+ if location is None:
|
|
|
|
|
+ return None
|
|
|
|
|
+ split_path = Hdfs.urlsplit(location)
|
|
|
|
|
+ if strict and not split_path[1] or not split_path[2]:
|
|
|
|
|
+ # No netloc not full url or no URL
|
|
|
|
|
+ return None
|
|
|
|
|
+ path = location
|
|
|
|
|
+ if split_path[0] == 'hdfs':
|
|
|
|
|
+ path = split_path[2]
|
|
|
|
|
+
|
|
|
|
|
+ filebrowser_path = reverse("filebrowser.views.view", kwargs=dict(path=path))
|
|
|
|
|
+ if is_embeddable and not filebrowser_path.startswith('/hue'):
|
|
|
|
|
+ filebrowser_path = '/hue' + filebrowser_path
|
|
|
|
|
+ return filebrowser_path
|