https://github.com/geodynamics/citcoms
Raw File
Tip revision: 36f5b324acac508e900f74fcb6f9c7ae35fc8cbc authored by Leif Strand on 29 April 2009, 20:47:56 UTC
Merged r14275:14351 from trunk.
Tip revision: 36f5b32
utils.py
#!/usr/bin/env python

import os.path

def parsemodel(somepath):
    
    nothing = (None, None, None, None)

    # prepare...
    filepath = os.path.abspath(somepath)

    # first round
    pardir, filename = os.path.split(filepath)
    if not filename:
        return nothing

    # second round
    rootname, h5 = os.path.splitext(filename)
    if not rootname:
        return nothing
    if h5 != '.h5':
        return nothing

    # third round
    modelname, dotstep = os.path.splitext(rootname)
    if not modelname:
        return nothing

    coordfile = '%s.h5' % modelname
    coordpath = os.path.join(pardir, coordfile)

    # fourth round
    try:
        step = int(dotstep[1:])
    except ValueError:
        return (None, modelname, coordpath, None)

    return (step, modelname, coordpath, filepath)


if __name__ == '__main__':
    import sys
    if len(sys.argv) > 1:
        print parsemodel(sys.argv[1])

back to top