def trans_files(cmip3_path, cmip5_path): cmip3_t = cmip3.make_translator(cmip3_path) cmip5_t = cmip5.make_translator(cmip5_path) log.info('Dry run is %s' % dry_run) log.info('Copying is %s' % copy_trans) for dirpath, filenames in walk_cmip3(cmip3_path): log.info('Processing directory %s' % dirpath) try: drs = cmip3_t.path_to_drs(dirpath) path = cmip5_t.drs_to_path(drs) except TranslationError, e: log.error('Failed to translate path %s: %s' % (dirpath, e)) continue except:
# All rights reserved. # # See the LICENSE file in the source distribution of this software for # the full license text. """ Tests compatible with nosetests """ import os from drslib import cmip3, cmip5 translator = cmip3.make_translator('/') cmip5_translator = cmip5.make_translator('cmip5') def test_1(): p = '/20c3m/atm/da/rsus/gfdl_cm2_0/run1/rsus_A2.19610101-19651231.nc' p2 = convert(p) assert p2 == 'cmip5/output/GFDL/CM2/20c3m/day/atmos/A2/r1/v1/rsus/rsus_A2_CM2_20c3m_r1_19610101-19651231.nc' def test_listing(): """ Test successful conversion of part of the CMIP3 listing """ fh = open(os.path.join(os.path.dirname(__file__), 'cmip3_test_ls')) for line in fh:
# the full license text. """ Translate a stream of filepaths from CMIP3 to CMIP5 syntax """ import sys, os, re import logging log = logging.getLogger(__name__) from drslib import cmip3, cmip5 from drslib.translate import TranslationError cmip3_translator = cmip3.make_translator('') cmip5_translator = cmip5.make_translator('') # Redefined in main include = None exclude = None dry_run = True copy_trans = False def walk_cmip3(base_path): """ Walk through the CMIP3 archive @yield: (dirname, filenames) for terminal directories """ for (dirpath, dirnames, filenames) in os.walk(base_path):