tzgrok.py
849 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/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)