Skip to content

Commit

Permalink
#154 removing redundant functions from utils.py
Browse files Browse the repository at this point in the history
  • Loading branch information
aanersc committed Mar 4, 2021
1 parent 1da35ca commit cd7f32c
Showing 1 changed file with 1 addition and 49 deletions.
50 changes: 1 addition & 49 deletions geospaas/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,39 +14,11 @@
except ImportError:
from urllib.parse import urlparse

from django.conf import settings

def module_path(module, root):
media_path = root
for m in module.split('.'):
media_path = os.path.join(media_path, m)
if not os.path.exists(media_path):
os.mkdir(media_path)
return media_path


def path(module, filename, root):
mp = module_path(module, root)

# Get the path of media files created from <filename>
basename = os.path.split(filename)[-1].split('.')[0]
dataset_path = os.path.join(mp, basename)
if not os.path.exists(dataset_path):
os.mkdir(dataset_path)

return dataset_path

def media_path(module, filename):
return path(module, filename, settings.MEDIA_ROOT)

def product_path(module, filename):
return path(module, filename, settings.PRODUCTS_ROOT)

def validate_uri(uri):
""" Validation of URI and its existence
URI conventions: URI = scheme:[//authority]path[?query][#fragment]
Examples:
file://localhost/some/path/filename.ext
http://www.eee.rrr/some/path
Expand All @@ -69,23 +41,3 @@ def validate_uri(uri):
ds = Dataset(uri)
except OSError:
ds = Dataset(uri+'#fillmismatch')


def nansat_filename(uri):
# Check if data should be read as stream or as file? Or just:
# open with Nansat
uri_content = urlparse(uri)
if uri_content.scheme=='file':
return uri_content.path
elif uri_content.scheme=='ftp':
return urllib.urlretrieve(uri)[0]
else:
return uri

def uris_from_args(fnames):
if len(fnames[0].split(':'))==1:
uris = ['file://localhost' + fn for fn in fnames]
else:
uris = [uri for uri in fnames]
return uris

0 comments on commit cd7f32c

Please sign in to comment.