From: Thierry Parmentelat Date: Fri, 5 Jun 2015 10:06:23 +0000 (+0200) Subject: Record.todict behaves suspisciously X-Git-Tag: sfa-3.1-17~6 X-Git-Url: http://git.onelab.eu/?p=sfa.git;a=commitdiff_plain;h=c7c7ed1178348445dc4ae70ea0fd905625e95421 Record.todict behaves suspisciously no change for now, but we disambiguate between XML.todict() and Record.todict() so we can more easily spot which is which --- diff --git a/clientbin/getNodes.py b/clientbin/getNodes.py index 71d17f02..d77bbbcf 100644 --- a/clientbin/getNodes.py +++ b/clientbin/getNodes.py @@ -51,13 +51,18 @@ def print_dict(rdict, options, counter=1): if keys: print tab * (counter) + "(children: %s)" % (",".join(keys)) +# +# this code probably is obsolete +# RSpec is not imported, it does not have a toDict() method anyway +# plus, getNodes.py is not exposed in packaging +# def main(): parser = create_parser(); (options, args) = parser.parse_args() if not options.infile: print "RSpec file not specified" return - + rspec = RSpec() try: rspec.parseFile(options.infile) diff --git a/sfa/client/sfi.py b/sfa/client/sfi.py index dce1ac2d..dbf14a9f 100644 --- a/sfa/client/sfi.py +++ b/sfa/client/sfi.py @@ -1054,12 +1054,12 @@ use this if you mean an authority instead""") try: record_filepath = args[0] rec_file = self.get_record_file(record_filepath) - record_dict.update(load_record_from_file(rec_file).todict()) + record_dict.update(load_record_from_file(rec_file).record_to_dict()) except: print "Cannot load record file {}".format(record_filepath) sys.exit(1) if options: - record_dict.update(load_record_from_opts(options).todict()) + record_dict.update(load_record_from_opts(options).record_to_dict()) # we should have a type by now if 'type' not in record_dict : self.print_help() @@ -1086,9 +1086,9 @@ use this if you mean an authority instead""") if len(args) > 0: record_filepath = args[0] rec_file = self.get_record_file(record_filepath) - record_dict.update(load_record_from_file(rec_file).todict()) + record_dict.update(load_record_from_file(rec_file).record_to_dict()) if options: - record_dict.update(load_record_from_opts(options).todict()) + record_dict.update(load_record_from_opts(options).record_to_dict()) # at the very least we need 'type' here if 'type' not in record_dict or record_dict['type'] is None: self.print_help() diff --git a/sfa/managers/registry_manager.py b/sfa/managers/registry_manager.py index 6049ebbd..8e8eb783 100644 --- a/sfa/managers/registry_manager.py +++ b/sfa/managers/registry_manager.py @@ -235,7 +235,7 @@ class RegistryManager: # xxx somehow here calling dict(record) issues a weird error # however record.todict() seems to work fine # records.extend( [ dict(record) for record in local_records ] ) - records.extend( [ record.todict(exclude_types=(InstrumentedList,)) for record in local_records ] ) + records.extend( [ record.record_to_dict(exclude_types=(InstrumentedList,)) for record in local_records ] ) if not records: raise RecordNotFound(str(hrns)) @@ -296,7 +296,7 @@ class RegistryManager: # record.todict() is the place where __dict__ is used print "DO NOT REMOVE ME before augment_with_sfa_builtins, record=%s"%record augment_with_sfa_builtins(record) - record_dicts = [ record.todict(exclude_types=(InstrumentedList,)) for record in records ] + record_dicts = [ record.record_to_dict(exclude_types=(InstrumentedList,)) for record in records ] return record_dicts diff --git a/sfa/storage/model.py b/sfa/storage/model.py index 347012d7..7ce83457 100644 --- a/sfa/storage/model.py +++ b/sfa/storage/model.py @@ -469,9 +469,9 @@ def make_record_dict (record_dict): # register non-db attributes in an extensions field return result -def make_record_xml (xml): - xml_record = XML(xml) - xml_dict = xml_record.todict() +def make_record_xml (xml_str): + xml = XML(xml_str) + xml_dict = xml.todict() logger.info("load from xml, keys=%s"%xml_dict.keys()) return make_record_dict (xml_dict) diff --git a/sfa/storage/record.py b/sfa/storage/record.py index a4a87b49..59317651 100644 --- a/sfa/storage/record.py +++ b/sfa/storage/record.py @@ -8,12 +8,12 @@ from sfa.util.sfalogging import logger class Record: - def __init__(self, dict=None, xml=None): + def __init__(self, dict=None, xml_str=None): if dict: self.load_from_dict(dict) - elif xml: - xml_record = XML(xml) - xml_dict = xml_record.todict() + elif xml_str: + xml = XML(xml_str) + xml_dict = xml.todict() self.load_from_dict(xml_dict) @@ -39,7 +39,7 @@ class Record: # need to filter out results, esp. wrt relationships # exclude_types must be a tuple so we can use isinstance # - def todict (self, exclude_types=None): + def record_to_dict (self, exclude_types=None): if exclude_types is None: exclude_types = () d = self.__dict__