735 def cmd_drop_attribute(self, etype, attrname, commit=True): |
735 def cmd_drop_attribute(self, etype, attrname, commit=True): |
736 """drop an existing attribute from the given entity type |
736 """drop an existing attribute from the given entity type |
737 |
737 |
738 `attrname` is a string giving the name of the attribute to drop |
738 `attrname` is a string giving the name of the attribute to drop |
739 """ |
739 """ |
740 rschema = self.repo.schema.rschema(attrname) |
740 try: |
741 attrtype = rschema.objects(etype)[0] |
741 rschema = self.repo.schema.rschema(attrname) |
|
742 attrtype = rschema.objects(etype)[0] |
|
743 except KeyError: |
|
744 print 'warning: attribute %s %s is not known, skip deletion' % ( |
|
745 etype, attrname) |
|
746 return |
742 self.cmd_drop_relation_definition(etype, attrname, attrtype, commit=commit) |
747 self.cmd_drop_relation_definition(etype, attrname, attrtype, commit=commit) |
743 |
748 |
744 def cmd_rename_attribute(self, etype, oldname, newname, commit=True): |
749 def cmd_rename_attribute(self, etype, oldname, newname, commit=True): |
745 """rename an existing attribute of the given entity type |
750 """rename an existing attribute of the given entity type |
746 |
751 |
770 in auto mode, automatically register entity's relation where the |
775 in auto mode, automatically register entity's relation where the |
771 targeted type is known |
776 targeted type is known |
772 """ |
777 """ |
773 instschema = self.repo.schema |
778 instschema = self.repo.schema |
774 eschema = self.fs_schema.eschema(etype) |
779 eschema = self.fs_schema.eschema(etype) |
775 assert eschema.final or not etype in instschema, \ |
780 if etype in instschema and (not eschema.final or eschema.eid is not None): |
776 '%s already defined in the instance schema' % etype |
781 print 'warning: %s already known, skip addition' % etype |
|
782 return |
777 confirm = self.verbosity >= 2 |
783 confirm = self.verbosity >= 2 |
778 groupmap = self.group_mapping() |
784 groupmap = self.group_mapping() |
779 cstrtypemap = self.cstrtype_mapping() |
785 cstrtypemap = self.cstrtype_mapping() |
780 # register the entity into CWEType |
786 # register the entity into CWEType |
781 execute = self._cw.execute |
787 execute = self._cw.execute |
999 creation (but not the relation definitions themselves, for which |
1005 creation (but not the relation definitions themselves, for which |
1000 committing depends on the `commit` argument value). |
1006 committing depends on the `commit` argument value). |
1001 |
1007 |
1002 """ |
1008 """ |
1003 reposchema = self.repo.schema |
1009 reposchema = self.repo.schema |
|
1010 if rtype in reporschema: |
|
1011 print 'warning: relation type %s is already known, skip addition' % ( |
|
1012 rtype) |
|
1013 return |
1004 rschema = self.fs_schema.rschema(rtype) |
1014 rschema = self.fs_schema.rschema(rtype) |
1005 execute = self._cw.execute |
1015 execute = self._cw.execute |
1006 # register the relation into CWRType and insert necessary relation |
1016 # register the relation into CWRType and insert necessary relation |
1007 # definitions |
1017 # definitions |
1008 ss.execschemarql(execute, rschema, ss.rschema2rql(rschema, addrdef=False)) |
1018 ss.execschemarql(execute, rschema, ss.rschema2rql(rschema, addrdef=False)) |
1065 schema definition file |
1075 schema definition file |
1066 """ |
1076 """ |
1067 rschema = self.fs_schema.rschema(rtype) |
1077 rschema = self.fs_schema.rschema(rtype) |
1068 if not rtype in self.repo.schema: |
1078 if not rtype in self.repo.schema: |
1069 self.cmd_add_relation_type(rtype, addrdef=False, commit=True) |
1079 self.cmd_add_relation_type(rtype, addrdef=False, commit=True) |
|
1080 if (subjtype, objtype) in self.repo.schema.rschema(rtype).rdefs: |
|
1081 print 'warning: relation %s %s %s is already known, skip addition' % ( |
|
1082 subjtype, rtype, objtype) |
|
1083 return |
1070 execute = self._cw.execute |
1084 execute = self._cw.execute |
1071 rdef = self._get_rdef(rschema, subjtype, objtype) |
1085 rdef = self._get_rdef(rschema, subjtype, objtype) |
1072 ss.execschemarql(execute, rdef, |
1086 ss.execschemarql(execute, rdef, |
1073 ss.rdef2rql(rdef, self.cstrtype_mapping(), |
1087 ss.rdef2rql(rdef, self.cstrtype_mapping(), |
1074 self.group_mapping())) |
1088 self.group_mapping())) |