Commit 7539e50b authored by Guillaume's avatar Guillaume
Browse files

Bugfixes

parent e87e8b19
......@@ -60,71 +60,69 @@ class DRSParser(object):
self.fx_file_parser = pyessv.create_template_parser(file_template, self.file_drs[:-1], strictness=1,
seperator='_')
def get_facets_from_path(self, path):
"""
Deserialize pathlib.Path object against a DRS.
def get_facets_from_path(self, path):
"""
Deserialize pathlib.Path object against a DRS.
"""
# Check vocabulary.
try:
self.dir_parser.parse(path.parent.as_posix())
"""
# Check vocabulary.
try:
self.dir_parser.parse(path.parent.as_posix())
# Deserialize p.parent in dict excluding project.
facets = dict((zip(self.dir_keys, path.parent.parts[1:])))
# Deserialize p.parent in dict excluding project.
facets = dict((zip(self.dir_keys, path.parent.parts[1:])))
return facets
return facets
# Vocabulary error handling.
except TemplateParsingError as e:
print(e)
return None
# Vocabulary error handling.
except TemplateParsingError as e:
print(e)
return None
# Catch any other exception.
except Exception as e:
print(e)
return None
# Catch any other exception.
except Exception as e:
print(e)
return None
def get_facets_from_filename(self, basename):
"""
Deserialize a filename string against a DRS.
def get_facets_from_filename(self, basename):
"""
Deserialize a filename string against a DRS.
"""
# Initialize tstart & tend
tstart, tend, clim = '', '', 'False'
"""
# Initialize tstart & tend
tstart, tend, clim = '', '', 'False'
# Set clim to True and rename basename to match usual template in case of climatology file.
if basename.endswith('-clim.nc'):
basename, clim = basename.replace('-clim', ''), 'True'
# Set clim to True and rename basename to match usual template in case of climatology file.
if basename.endswith('-clim.nc'):
basename, clim = basename.replace('-clim', ''), 'True'
# Check vocabulary.
try:
self.file_parser.parse(basename)
timerange = TimeRange(basename.split('_')[-1])
tstart, tend = timerange.start, timerange.end
# Check vocabulary.
try:
self.file_parser.parse(basename)
timerange = TimeRange(basename.split('_')[-1])
tstart, tend = timerange.start, timerange.end
# Parsing error handling.
except TemplateParsingError:
# Parsing error handling.
except TemplateParsingError:
# Try parsing with "fixed" template.
try:
self.fx_file_parser.parse(basename)
# Try parsing with "fixed" template.
try:
self.fx_file_parser.parse(basename)
# Set no timerange and no climatology.
tstart, tend, clim = '', '', 'False'
# Set no timerange and no climatology.
tstart, tend, clim = '', '', 'False'
# Catch any other exception.
except Exception as e:
print(e)
# Catch any other exception.
except Exception as e:
print(e)
# Catch any other exception.
except Exception as e:
print(e)
# Deserialize filename and add time range facets.
facets = dict(zip(self.file_keys[:-1], basename.split('_')[:-1]))
facets['period_start'] = tstart
facets['period_end'] = tend
facets['climatology'] = clim
return facets
# Deserialize filename and add time range facets.
facets = dict(zip(self.file_keys[:-1], basename.split('_')[:-1]))
facets['period_start'] = tstart
facets['period_end'] = tend
facets['climatology'] = clim
return facets
......@@ -2,15 +2,15 @@
# -*- coding: utf-8 -*-
import glob
import re
import subprocess
import tarfile
from argparse import ArgumentParser
from datetime import date
from glob import glob
from glob import iglob
from multiprocessing import Pool
from pathlib import Path
from shutil import copy, copyfileobj
from glob import glob
from DRSParser import DRSParser
from utils import *
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment