Page MenuHomec4science

xmlmarclint.in
No OneTemporary

File Metadata

Created
Sun, Nov 10, 19:57

xmlmarclint.in

#!@PYTHON@
## -*- mode: python; coding: utf-8; -*-
##
## $Id$
##
## This file is part of the CERN Document Server Software (CDSware).
## Copyright (C) 2002, 2003, 2004, 2005 CERN.
##
## The CDSware is free software; you can redistribute it and/or
## modify it under the terms of the GNU General Public License as
## published by the Free Software Foundation; either version 2 of the
## License, or (at your option) any later version.
##
## The CDSware is distributed in the hope that it will be useful, but
## WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
## General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with CDSware; if not, write to the Free Software Foundation, Inc.,
## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
"""
XML MARC lint - check your XML MARC files
"""
import getopt
import string
import sys
try:
import sys
pylibdir = "@prefix@/lib/python"
sys.path.append('%s' % pylibdir)
from cdsware.bibrecord import *
except ImportError, e:
print "Error: %s" % e
import sys
sys.exit(1)
cmdusage = """command usage:
%s [-v <verbosity>] xmlfile
or
%s --help
""" % (sys.argv[0], sys.argv[0])
helpmsg = cmdusage
try:
opts,args=getopt.getopt(sys.argv[1:], "c:v:h:",["-help"])
except getopt.GetoptError:
print cmdusage
sys.exit(2)
badrecords = []
listofrecs=[]
verbose= 0
if len(args)==1:
xmlfile = args[0]
elif len(args)==0:
if len(opts)==1:
if opts[0][0] in ['-help','-h']:
print helpmsg
else:
print cmdusage
sys.exit(2)
else:
print cmdusage
sys.exit(2)
for opt in opts:
if not opt[0] in ['-v']:
print cmdusage
sys.exit(2)
if opt[0] == '-v':
try:
verbose = string.atoi(opt[1])
except ValueError:
print 'Verbose must be an integer'
sys.exit(2)
global parser
try:
f = open(xmlfile,'r')
xmltext = f.read()
f.close()
except IOError:
print 'File not found\n Please check the name'
import sys
sys.exit(1)
parser = parser
listofrecs = create_records(xmltext,0,1)
badr = filter((lambda x: x[1]==0),listofrecs)
badrecords = map((lambda x:x[0]),badr)
s=''
e=''
if verbose:
if verbose <=3:
e=print_errors(concat(map((lambda x:x[2]),listofrecs)))
else:
s=print_recs(badrecords)
e=print_errors(concat(map((lambda x:x[2]),listofrecs)))
else:
if badrecords !=[]:
print 'Bad records detected! For more information, set verbosity.'
sys.exit(1)
if s!='' or e!='':
print s
print e
sys.exit(1)

Event Timeline