Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
organise products in subfolders based on the dataset time_coverage_start
  • Loading branch information
mortenwh committed Feb 2, 2023
commit ca18a172c7b6a791d3ec91d18aa01d6050f9622f
12 changes: 9 additions & 3 deletions geospaas/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,15 @@ def module_path(module, root):
return media_path


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

if date is not None:
for xx in [date.strftime('%Y'), date.strftime('%m'), date.strftime('%d')]:
mp = os.path.join(mp, xx)
if not os.path.exists(mp):
os.mkdir(mp)

# Get the path of media files created from <filename>
basename = os.path.split(filename)[-1].split('.')[0]
dataset_path = os.path.join(mp, basename)
Expand All @@ -39,8 +45,8 @@ def path(module, filename, root):
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 product_path(module, filename, date=None):
return path(module, filename, settings.PRODUCTS_ROOT, date=date)

def validate_uri(uri):
""" Validation of URI and its existence
Expand Down