oxtimeline/bin/oxinfo
2009-01-18 19:39:14 +11:00

48 lines
1.3 KiB
Python
Executable file

#!/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()
sys.exit()
inputFile = args[0]
i = Info(inputFile)
info = i.metadata
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])