def yaml_import(self, user, yaml_string): """Imports a YAML export string into a new Map.""" yaml_dict = yaml.safe_load(yaml_string) map_name = yaml_dict['map_name'] root_system = yaml_dict['systems'][0] root_sys = System.objects.get(name=root_system['system']) new_map = Map(name=map_name, root=root_sys) new_map.save() root_mapsys = new_map.add_system(user=user, system=root_sys, friendlyname=root_system['tag']) for sig in root_system['signatures']: sig_id = sig['id'] info = sig['info'] if sig['type']: sig_type = SignatureType.objects.get(shortname=sig['type']) else: sig_type = None if not Signature.objects.filter( sigid=sig_id, system=root_mapsys.system).exists(): Signature(sigid=sig_id, sigtype=sig_type, system=root_mapsys.system, info=info, updated=bool(sig_type)).save() from POS.models import POS POS.update_from_import_list(root_mapsys.system, root_system['starbases']) root_mapsys.add_children_from_list(root_system['children']) return new_map
def add_children_from_list(self, children=None): """Adds child systems from list generated by the YAML importer.""" if not children: children = [] print "Adding %s children to %s" % (len(children), self.system.name) for child in children: new_sys = System.objects.get(name=child['system']) friendlyname = child['tag'] new_mapsys = MapSystem(map=self.map, system=new_sys, friendlyname=friendlyname, parentsystem=self) new_mapsys.save() parent_wh = child['parent_wh'] top_type = WormholeType.objects.get(name=parent_wh['near_type']) bottom_type = WormholeType.objects.get(name=parent_wh['far_type']) top_bubbled = parent_wh['top_bubbled'] bottom_bubbled = parent_wh['bottom_bubbled'] mass_status = parent_wh['mass_status'] time_status = parent_wh['time_status'] wh = new_mapsys.connect_to(system=self, top_type=top_type, bottom_type=bottom_type, top_bubbled=top_bubbled, bottom_bubbled=bottom_bubbled, time_status=time_status, mass_status=mass_status) wh.save() for sig in child['signatures']: sig_id = sig['id'] info = sig['info'] if sig['type']: sig_type = SignatureType.objects.get(shortname=sig['type']) else: sig_type = None if sig_type: updated = True else: updated = False if not Signature.objects.filter(system=self.system, sigid=sig_id).exists(): Signature(sigid=sig_id, sigtype=sig_type, system=self.system, info=info, updated=updated).save() from POS.models import POS POS.update_from_import_list(self.system, child['starbases']) new_mapsys.add_children_from_list(child['children'])
def add_children_from_list(self, children=None): """Adds child systems from list generated by the YAML importer.""" if not children: children = [] print "Adding %s children to %s" % (len(children), self.system.name) for child in children: new_sys = System.objects.get(name=child['system']) friendlyname = child['tag'] new_mapsys = MapSystem(map=self.map, system=new_sys, friendlyname=friendlyname, parentsystem=self) new_mapsys.save() parent_wh = child['parent_wh'] top_type = WormholeType.objects.get(name=parent_wh['near_type']) bottom_type = WormholeType.objects.get(name=parent_wh['far_type']) top_bubbled = parent_wh['top_bubbled'] bottom_bubbled = parent_wh['bottom_bubbled'] mass_status = parent_wh['mass_status'] time_status = parent_wh['time_status'] wh = new_mapsys.connect_to( system=self, top_type=top_type, bottom_type=bottom_type, top_bubbled=top_bubbled, bottom_bubbled=bottom_bubbled, time_status=time_status, mass_status=mass_status) wh.save() for sig in child['signatures']: sig_id = sig['id'] info = sig['info'] if sig['type']: sig_type = SignatureType.objects.get(shortname=sig['type']) else: sig_type = None if sig_type: updated = True else: updated = False if not Signature.objects.filter( system=self.system, sigid=sig_id).exists(): Signature(sigid=sig_id, sigtype=sig_type, system=self.system, info=info, updated=updated).save() from POS.models import POS POS.update_from_import_list(self.system, child['starbases']) new_mapsys.add_children_from_list(child['children'])