oxtimeline/bin/oxinfo

49 lines
1.3 KiB
Text
Raw Normal View History

2009-01-18 08:39:14 +00:00
#!/usr/bin/python
# -*- coding: utf-8 -*-
# vi:si:et:sw=4:sts=4:ts=4
# GPL 2009
import os
import sys
import Image
from optparse import OptionParser
import xml.etree.ElementTree as ET
root = os.path.join(os.path.abspath(os.path.dirname(__file__)), '..')
if os.path.exists(os.path.join(root, 'oxgst')):
sys.path.insert(0, root)
from oxgst import Info
if __name__ == "__main__":
parser = OptionParser()
parser.add_option('-f', '--format', dest='format', help='output format: cfg, json, xml default: cfg')
(opts, args) = parser.parse_args()
if not args:
parser.print_help()
2009-01-27 09:52:25 +00:00
sys.exit(1)
2009-01-18 08:39:14 +00:00
inputFile = args[0]
2009-01-27 09:52:25 +00:00
if not os.path.exists(inputFile):
sys.exit(1)
info = Info(inputFile)
2009-01-18 08:39:14 +00:00
if opts.format == 'xml':
xml = ET.Element("gstinfo")
el = ET.SubElement(xml, "path")
el.text = inputFile
for key in sorted(info):
el = ET.SubElement(xml, key)
el.text = unicode(info[key])
print u'<?xml version="1.0" encoding="utf-8"?>\n' + ET.tostring(xml).replace('><', '>\n <').replace(' </', '</')
elif opts.format == 'json':
import simplejson
info['path'] = inputFile
print simplejson.dumps(info).replace(', ', ',\n ')
else:
print "[%s]" % inputFile
for key in sorted(info):
print "%s = %s" % (key, info[key])