def configure(self): ''' Defines the command arguments. ''' datasets = DatabaseRepository.listYears() raw_formats = FormatRepository.listExportableFormatNames() minifiable_formats = FormatRepository.listMinifiableFormatNames() self.addArgument('-d', '--datasets', metavar='DATASET', nargs='*', default=datasets, help=('Datasets to build.\n' 'Defaults to all available: {}' \ .format(', '.join(datasets)))) self.addArgument('-r', '--raw', metavar='FORMAT', nargs='*', default=raw_formats, help=('Raw formats to build the dataset.\n' 'Defaults to all available: {}' \ .format(', '.join(raw_formats)))) self.addArgument('-m', '--min', metavar='FORMAT', nargs='*', default=minifiable_formats, help=('Minifiable formats to build the dataset.\n' 'Defaults to all available: {}' \ .format(', '.join(minifiable_formats))))
def getDatasetsByLocale(locale): ''' Returns the datasets available for a given localization. Arguments: locale (str): The localization name Returns: collections.OrderedDict: The localization datasets ''' data = OrderedDict() for dataset in DatabaseRepository.listYears(): dataset_file = DATA_DIR / locale / dataset / 'places.json' if dataset_file.exists(): data[dataset] = json.load(File(dataset_file)) return data
def getDatasetsByLocale(locale): """ Returns the datasets available for a given localization. Arguments: locale (str): The localization name Returns: collections.OrderedDict: The localization datasets """ data = OrderedDict() for dataset in DatabaseRepository.listYears(): dataset_file = DATA_DIR / locale / dataset / "places.json" if dataset_file.exists(): data[dataset] = json.load(File(dataset_file)) return data
def handle(self, args): ''' Handles the command. ''' logger.info('Generating project README...') ProjectReadme().write() for language_dir in DATA_DIR.directories(): language = language_dir.name logger.info('Generating "{}" dataset READMEs...'.format(language)) for dataset in DatabaseRepository.findAll(): dataset_dir = language_dir / dataset.year min_dataset_dir = dataset_dir / 'minified' if dataset_dir.exists(): # Create raw dataset READMEs DatasetReadme(dataset, dataset_dir, language).write() if min_dataset_dir.exists(): # Create minified dataset READMEs DatasetReadme(dataset, min_dataset_dir, language).write()