Esempio n. 1
0
 def load(self):
     """
     Parse an xml file and store it as a dict
     """ 
     data = RecordSpec()
     if os.path.exists(self.db_filename) and os.path.isfile(self.db_filename):
         data.parseFile(self.db_filename)
         dict.__init__(self, data.toDict())
     elif os.path.exists(self.db_filename) and not os.path.isfile(self.db_filename):
         raise IOError, '%s exists but is not a file. please remove it and try again' \
                        % self.db_filename
     else:
         self.write()
         self.load()
Esempio n. 2
0
def main():
    parser = create_parser(); 
    (options, args) = parser.parse_args()

    stdin = sys.stdin.read()
    
    record = RecordSpec(xml = stdin)
    
    if not record.dict.has_key("record"):
        raise "RecordError", "Input record does not have 'record' tag."

    if options.DEBUG: 
        record.pprint()
        print "#####################################################"

    printRec(record, args, options)
Esempio n. 3
0
def main():
    parser = create_parser(); 
    (options, args) = parser.parse_args()

    record = RecordSpec(xml = sys.stdin.read())

    if args:
        editDict(args, record.dict["record"], options)
    if options.DEBUG:
        print "New Record:\n%s" % record.dict
        record.pprint()

    record.parseDict(record.dict)
    s = record.toxml()
    sys.stdout.write(s)
Esempio n. 4
0
 def write(self):
     data = RecordSpec()
     data.parseDict(self)
     db_file = open(self.db_filename, 'w')
     db_file.write(data.toprettyxml())
     db_file.close()