#!/usr/bin/env python
#
# $Source: /home/blais/repos/cvsroot/arubomu/old/bin/fix-discs,v $
# $Id: fix-discs,v 1.1 2004/02/09 02:35:27 blais Exp $
#

"""fix-discs [<options>] <file>

Attempt to remove discs field from album.

"""

__version__ = "$Revision: 1.1 $"
__author__ = "Martin Blais <blais@furius.ca>"


import sys, os

from elementtree import ElementTree


def main():
    import optparse
    parser = optparse.OptionParser(__doc__.strip(), version=__version__)
    opts, args = parser.parse_args()

    if len(args) != 1:
        raise parser.error("Please specify a single input file.")
    fn = args[0]

    try:
        tree = ElementTree.parse(fn)
    except IOError, e:
        raise SystemExit("Error: couldn't read file (%s):" % fn + str(e))
    
    rv = 0
    discs = tree.find('//album/discs')
    if discs != None:
        discs = map(int, discs.text.split(','))
        discdecl = tree.findall('//album/disc')
        if len(discdecl) != len(discs):
            print fn
            ##print '%s: %s' % (fn, discs)
            rv = 1

    return rv
##     tree.write(sys.stdout, encoding='iso-8859-1')
##     print

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

