tzgrok.py 849 Bytes
#!/bin/env python
""" tzgrok.py -- convert timezone data to RDF
"""

import sys, os
from os.path import join

Command = 'python fromIcal.py %s > %s'

def convert(sd, curdir, names):
    srcd, dest = sd

    reldir = curdir[len(srcd):]

    dest = join(dest, reldir)
    try:
        os.mkdir(dest)
    except OSError: #already exists. @@other errs use same exception?
        pass

    for n in names:
        if n[-4:] <> '.ics': continue

        out = n[:-4] + '.rdf'

        cmd = Command % (join(curdir, n), join(dest, out))
        print >>sys.stderr, "running: ", cmd
        status = os.system(cmd)
        if status <> 0:
            raise IOError, "Exit status %d from command: %s" % (status, cmd)


def main(argv):
    srcd, destd = argv[1:]

    os.path.walk(srcd, convert, (srcd, destd))

if __name__ == '__main__':
    main(sys.argv)