Esempio n. 1
0
 def __init__(self, dict=None, xml=None):
     if dict:
         self.load_from_dict(dict)
     elif xml:
         xml_record = XML(xml)
         xml_dict = xml_record.todict()
         self.load_from_dict(xml_dict)  
Esempio n. 2
0
 def __init__(self, dict=None, xml=None):
     if dict:
         self.load_from_dict(dict)
     elif xml:
         xml_record = XML(xml)
         xml_dict = xml_record.todict()
         self.load_from_dict(xml_dict)  
Esempio n. 3
0
 def load(self):
     """
     Parse an xml file and store it as a dict
     """ 
     if os.path.exists(self.db_filename) and os.path.isfile(self.db_filename):
         xml = XML(self.db_filename)
         dict.__init__(self, xml.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. 4
0
def main():
    parser = create_parser(); 
    (options, args) = parser.parse_args()

    stdin = sys.stdin.read()
    
    record = XML(stdin)
    record_dict = record.todict()
    
    if options.DEBUG: 
        pprint(record.toxml())
        print "#####################################################"

    printRec(record_dict, args, options)
Esempio n. 5
0
def main():
    parser = create_parser()
    (options, args) = parser.parse_args()

    record = XML(sys.stdin.read())
    record_dict = record.todict()
    if args:
        editDict(args, record_dict, options)
    if options.DEBUG:
        print "New Record:\n%s" % record_dict

    record.parse_dict(record_dict)
    s = record.toxml()
    sys.stdout.write(s)
Esempio n. 6
0
def main():
    parser = create_parser(); 
    (options, args) = parser.parse_args()

    record = XML(sys.stdin.read())
    record_dict = record.todict()
    if args:
        editDict(args, record_dict, options)
    if options.DEBUG:
        print "New Record:\n%s" % record_dict
        
    record.parse_dict(record_dict)
    s = record.toxml()
    sys.stdout.write(s)
Esempio n. 7
0
 def load(self):
     """
     Parse an xml file and store it as a dict
     """
     if os.path.exists(self.db_filename) and os.path.isfile(
             self.db_filename):
         xml = XML(self.db_filename)
         dict.__init__(self, xml.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. 8
0
class ApiVersions:

    required_fields = ['version', 'url']
    
    template = """<api_versions>
<api_version name="" version="" url="" />
</api_versions>""" 

    def __init__(self, string=None, filename=None, create=False):
        self.xml = None

        if create:
            self.create()
        elif string:
            self.load(string)
        elif filename:
            self.load(filename)
        else:
            # load the default file
            c = Config()
            api_versions_file = os.path.sep.join([c.config_path, 'api_versions.xml'])
            self.load(api_versions_file)
        
    def create(self):
        self.xml = XML(string=ApiVersions.template)

    def load(self, source):
        self.xml = XML(source)

    def get_versions(self):
        versions = {}
        for value in self.xml.todict().values():
            if not value:
                continue
            if isinstance(value, list):
                for item in value:
                    if isinstance(item, dict) and \
                       set(ApiVersions.required_fields).issubset(item.keys()) and \
                       item['version'] != '' and item['url'] != '':
                        versions[str(item['version'])] = item['url']
        return versions  
                
           
Esempio n. 9
0
class ApiVersions:

    required_fields = ['version', 'url']
    
    template = """<api_versions>
<api_version name="" version="" url="" />
</api_versions>""" 

    def __init__(self, string=None, filename=None, create=False):
        self.xml = None

        if create:
            self.create()
        elif string:
            self.load(string)
        elif filename:
            self.load(filename)
        else:
            # load the default file
            c = Config()
            api_versions_file = os.path.sep.join([c.config_path, 'api_versions.xml'])
            self.load(api_versions_file)
        
    def create(self):
        self.xml = XML(string=ApiVersions.template)

    def load(self, source):
        self.xml = XML(source)

    def get_versions(self):
        versions = {}
        for value in self.xml.todict().values():
            if not value:
                continue
            if isinstance(value, list):
                for item in value:
                    if isinstance(item, dict) and \
                       set(ApiVersions.required_fields).issubset(item.keys()) and \
                       item['version'] != '' and item['url'] != '':
                        versions[str(item['version'])] = item['url']
        return versions  
Esempio n. 10
0
File: model.py Progetto: aquila/sfa
def make_record_xml (xml):
    xml_record = XML(xml)
    xml_dict = xml_record.todict()
    logger.info("load from xml, keys=%s"%xml_dict.keys())
    return make_record_dict (xml_dict)
Esempio n. 11
0
def make_record_xml(xml):
    xml_record = XML(xml)
    xml_dict = xml_record.todict()
    logger.info("load from xml, keys=%s" % xml_dict.keys())
    return make_record_dict(xml_dict)