def _checkDatasets(self, datasets, typ): """Checks and validates datasets. Reports also type of dataset (e.g. 'strds'). :param list datasets: list of temporal dataset's name :return: (mapName, mapset, type) """ validated = [] tDict = tgis.tlist_grouped(type=typ, group_type=True, dbif=self.dbif) # nested list with '(map, mapset, etype)' items allDatasets = [[[(map, mapset, etype) for map in maps] for etype, maps in etypesDict.iteritems()] for mapset, etypesDict in tDict.iteritems()] # flatten this list if allDatasets: allDatasets = reduce(lambda x, y: x + y, reduce(lambda x, y: x + y, allDatasets)) mapsets = tgis.get_tgis_c_library_interface().available_mapsets() allDatasets = [ i for i in sorted( allDatasets, key=lambda l: mapsets.index(l[1]))] for dataset in datasets: errorMsg = _("Space time dataset <%s> not found.") % dataset if dataset.find("@") >= 0: nameShort, mapset = dataset.split('@', 1) indices = [n for n, (mapName, mapsetName, etype) in enumerate( allDatasets) if nameShort == mapName and mapsetName == mapset] else: indices = [n for n, (mapName, mapset, etype) in enumerate( allDatasets) if dataset == mapName] if len(indices) == 0: raise GException(errorMsg) elif len(indices) >= 2: dlg = wx.SingleChoiceDialog( self, message=_( "Please specify the " "space time dataset " "<%s>." % dataset), caption=_("Ambiguous dataset name"), choices=[ ("%(map)s@%(mapset)s:" " %(etype)s" % { 'map': allDatasets[i][0], 'mapset': allDatasets[i][1], 'etype': allDatasets[i][2]}) for i in indices], style=wx.CHOICEDLG_STYLE | wx.OK) if dlg.ShowModal() == wx.ID_OK: index = dlg.GetSelection() validated.append(allDatasets[indices[index]]) else: continue else: validated.append(allDatasets[indices[0]]) return validated
def validateTimeseriesName(timeseries, etype='strds'): """Checks if space time dataset exists and completes missing mapset. Raises GException if dataset doesn't exist. """ trastDict = tgis.tlist_grouped(etype) if timeseries.find("@") >= 0: nameShort, mapset = timeseries.split('@', 1) if nameShort in trastDict[mapset]: return timeseries else: raise GException(_("Space time dataset <%s> not found.") % timeseries) mapsets = tgis.get_tgis_c_library_interface().available_mapsets() for mapset in mapsets: if mapset in trastDict.keys(): if timeseries in trastDict[mapset]: return timeseries + "@" + mapset raise GException(_("Space time dataset <%s> not found.") % timeseries)
def validateTimeseriesName(timeseries, etype='strds'): """Checks if space time dataset exists and completes missing mapset. Raises GException if dataset doesn't exist. """ trastDict = tgis.tlist_grouped(etype) if timeseries.find("@") >= 0: nameShort, mapset = timeseries.split('@', 1) if nameShort in trastDict[mapset]: return timeseries else: raise GException( _("Space time dataset <%s> not found.") % timeseries) mapsets = tgis.get_tgis_c_library_interface().available_mapsets() for mapset in mapsets: if mapset in trastDict.keys(): if timeseries in trastDict[mapset]: return timeseries + "@" + mapset raise GException(_("Space time dataset <%s> not found.") % timeseries)
def _checkDatasets(self, datasets): """Checks and validates datasets. Reports also type of dataset (e.g. 'strds'). :return: (mapName, mapset, type) """ validated = [] tDict = tgis.tlist_grouped('stds', group_type=True, dbif=self.dbif) # nested list with '(map, mapset, etype)' items allDatasets = [[[(map, mapset, etype) for map in maps] for etype, maps in etypesDict.iteritems()] for mapset, etypesDict in tDict.iteritems()] # flatten this list if allDatasets: allDatasets = reduce( lambda x, y: x + y, reduce( lambda x, y: x + y, allDatasets)) mapsets = tgis.get_tgis_c_library_interface().available_mapsets() allDatasets = [ i for i in sorted( allDatasets, key=lambda l: mapsets.index(l[1]))] for dataset in datasets: errorMsg = _("Space time dataset <%s> not found.") % dataset if dataset.find("@") >= 0: nameShort, mapset = dataset.split('@', 1) indices = [n for n, (mapName, mapsetName, etype) in enumerate( allDatasets) if nameShort == mapName and mapsetName == mapset] else: indices = [n for n, (mapName, mapset, etype) in enumerate( allDatasets) if dataset == mapName] if len(indices) == 0: raise GException(errorMsg) elif len(indices) >= 2: dlg = wx.SingleChoiceDialog( self, message=_( "Please specify the space time dataset <%s>." % dataset), caption=_("Ambiguous dataset name"), choices=[("%(map)s@%(mapset)s: %(etype)s" % {'map': allDatasets[i][0], 'mapset': allDatasets[i][1], 'etype': allDatasets[i][2]}) for i in indices], style=wx.CHOICEDLG_STYLE | wx.OK) if dlg.ShowModal() == wx.ID_OK: index = dlg.GetSelection() validated.append(allDatasets[indices[index]]) else: continue else: validated.append(allDatasets[indices[0]]) return validated