"""Archive and storage policy utilities for site_pipeline."""
import os
[docs]
class ArchivePolicy: # make_hwp_solutions, make_source_flags, make_uncal_beam_map, preprocess_obs
"""Storage policy assistance. Helps to determine the HDF5
filename and dataset name for a result.
Make me better!
"""
[docs]
@staticmethod
def from_params(params):
if params['type'] == 'simple':
return ArchivePolicy(**params)
if params['type'] == 'directory':
return DirectoryArchivePolicy(**params)
raise ValueError('No handler for "type"="%s"' % params['type'])
def __init__(self, **kwargs):
self.filename = kwargs['filename']
[docs]
def get_dest(self, product_id):
"""Returns (hdf_filename, dataset_addr).
"""
return self.filename, product_id
[docs]
class DirectoryArchivePolicy: # No direct usage found
"""Storage policy for stuff organized directly on the filesystem.
"""
def __init__(self, **kwargs):
self.root_dir = kwargs['root_dir']
self.pattern = kwargs['pattern']
[docs]
def get_dest(self, **kw):
"""Returns full path to destination directory.
"""
return os.path.join(self.root_dir, self.pattern.format(**kw))