コード例 #1
0
ファイル: storage.py プロジェクト: planetlab/sfa
 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()
コード例 #2
0
ファイル: getRecord.py プロジェクト: planetlab/sfa
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)
コード例 #3
0
ファイル: setRecord.py プロジェクト: planetlab/sfa
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)
コード例 #4
0
ファイル: storage.py プロジェクト: planetlab/sfa
 def write(self):
     data = RecordSpec()
     data.parseDict(self)
     db_file = open(self.db_filename, 'w')
     db_file.write(data.toprettyxml())
     db_file.close()