Esempio n. 1
0
def scan():
    """Scan NetCDF files and cdf2cim specific metadata to file-system.

    :returns: Tuple of scanned cdf2cim files written to file system.
    :rtype: tuple

    """
    # Parse command line args.
    parser = argparse.ArgumentParser("ES-DOC netCDF scanner.")
    parser.add_argument(
        "-i",
        "--in-dir",
        help="Path to a directory where CF files are to be found",
        dest="input_dir",
        type=str)
    args = parser.parse_args()

    # Invoke.
    try:
        for fpath in cdf2cim.scan(args.input_dir):
            cdf2cim.log("Scanned file: {}".format(fpath))
    except Exception as err:
        cdf2cim.log_error('Scan error: {}'.format(err))
        sys.exit(1)
    else:
        cdf2cim.log('Scan succeeded')
        sys.exit(0)
Esempio n. 2
0
def _assert_scan(dpath, expected_count):
    """Asserts scan inpits/outputs.

    """
    assert os.path.isdir(dpath)
    new, queued, published = cdf2cim.scan(dpath, True)
    assert len(new) == expected_count
    for fpath in new + queued + published:
        assert os.path.isfile(fpath)
Esempio n. 3
0
def _assert_scan(dpath, expected_count):
    """Asserts scan inpits/outputs.

    """
    assert os.path.isdir(dpath)
    new, queued, published = cdf2cim.scan(dpath, True)
    assert len(new) == expected_count
    for fpath in new + queued + published:
        assert os.path.isfile(fpath)
Esempio n. 4
0
def _test_publish(dpath):
    """Inner test.

    """
    scanned, _, _ = cdf2cim.scan(dpath, True)
    published, published_errors = cdf2cim.publish()
    assert len(published_errors) == 0, published_errors
    assert len(published) == len(scanned)
    for fpath in scanned:
        assert fpath.replace(IO_DIR_SCANNED, IO_DIR_PUBLISHED) in published
Esempio n. 5
0
def _main(args):
    """Write cdf2cim files to file system.

    """
    for fpath in cdf2cim.scan(args.input_dir):
        cdf2cim.logger.log("Scanned file: {}".format(fpath))