612 |
612 |
613 export_storage.unload(configuration.get_full_path(),configuration) |
613 export_storage.unload(configuration.get_full_path(),configuration) |
614 for child in configuration._traverse(type=Configuration): |
614 for child in configuration._traverse(type=Configuration): |
615 export_storage.unload(child.get_full_path(),child) |
615 export_storage.unload(child.get_full_path(),child) |
616 |
616 |
|
617 ruleml_eval_globals_files = [] |
|
618 for child in configuration._traverse(type=RulemlEvalGlobals): |
|
619 if child.file != None: |
|
620 ruleml_eval_globals_files.append(RulemlEvalGlobals.get_script_file_full_path(child)) |
|
621 |
617 #If the configuration is not in the root of the project adding the path |
622 #If the configuration is not in the root of the project adding the path |
618 #to final exporting source path. |
623 #to final exporting source path. |
619 #l = [] |
624 #l = [] |
|
625 empty_folders = kwargs.get('empty_folders',False) |
|
626 layer = configuration.get_layer() |
|
627 all_resources = [] |
|
628 layer_content = layer.list_content(empty_folders) |
|
629 layer_doc = layer.list_doc(empty_folders) |
|
630 layer_implml = layer.list_implml(empty_folders) |
|
631 |
|
632 include_filters = kwargs.get('include_filters',{}) |
|
633 exclude_filters = kwargs.get('exclude_filters',{}) |
|
634 |
|
635 include_content_filter = include_filters.get('content') |
|
636 exclude_content_filter = exclude_filters.get('content') |
|
637 |
|
638 # perform filtering of content files |
|
639 if exclude_content_filter: |
|
640 f = lambda x: not re.search(exclude_content_filter, x, re.IGNORECASE) |
|
641 layer_content = filter(f,layer_content) |
|
642 |
|
643 if include_content_filter: |
|
644 f = lambda x: re.search(include_content_filter, x, re.IGNORECASE) |
|
645 layer_content = filter(f,layer_content) |
|
646 |
|
647 all_resources.extend(layer_content) |
|
648 all_resources.extend(layer_doc) |
|
649 all_resources.extend(layer_implml) |
|
650 |
620 cpath = utils.resourceref.get_path(configuration.get_path()) |
651 cpath = utils.resourceref.get_path(configuration.get_path()) |
621 resr = [utils.resourceref.join_refs([cpath,related]) \ |
652 resr = [utils.resourceref.join_refs([cpath,related]) \ |
622 for related in configuration.get_layer().list_all_related(**kwargs)] |
653 for related in all_resources] |
|
654 resr.extend(ruleml_eval_globals_files) |
623 |
655 |
624 self.storage.export_resources(resr ,export_storage, kwargs.get("empty_folders", False)) |
656 self.storage.export_resources(resr ,export_storage, kwargs.get("empty_folders", False)) |
625 return |
657 return |
626 |
658 |
627 def get_configuration_class(self): |
659 def get_configuration_class(self): |
907 self.name = kwargs.get('name',utils.resourceref.to_objref(self.path)) |
939 self.name = kwargs.get('name',utils.resourceref.to_objref(self.path)) |
908 self.version = kwargs.get('version') |
940 self.version = kwargs.get('version') |
909 super(Configuration, self).__init__(utils.resourceref.to_objref(self.path), **kwargs) |
941 super(Configuration, self).__init__(utils.resourceref.to_objref(self.path), **kwargs) |
910 self.container = True |
942 self.container = True |
911 |
943 |
912 def __reduce_ex__(self, protocol_version): |
|
913 """ |
|
914 Make the Configuration pickle a ConfigurationProxy object that would load this configuration |
|
915 """ |
|
916 proxy = ConfigurationProxy(self.path, store_interface = self.get_project()) |
|
917 tpl = proxy.__reduce_ex__(protocol_version) |
|
918 return tpl |
|
919 |
|
920 def __getstate__(self): |
944 def __getstate__(self): |
921 return None |
945 state = self.__dict__.copy() |
|
946 if state.has_key('_children'): |
|
947 childs = state.get('_children') |
|
948 if childs.has_key('?default_view'): |
|
949 childs.pop('?default_view') |
|
950 state['_children'] = childs |
|
951 return state |
922 |
952 |
923 def _default_object(self, name): |
953 def _default_object(self, name): |
924 return self._default_class()(name) |
954 return self._default_class()(name) |
925 |
955 |
926 def _default_class(self): |
956 def _default_class(self): |
1374 The ConfigurationProxy trust to get the store_interface from the parent object with get_storage() function. |
1404 The ConfigurationProxy trust to get the store_interface from the parent object with get_storage() function. |
1375 |
1405 |
1376 """ |
1406 """ |
1377 super(ConfigurationProxy,self).__init__(path, **kwargs) |
1407 super(ConfigurationProxy,self).__init__(path, **kwargs) |
1378 self.set('_name', utils.resourceref.to_objref(path)) |
1408 self.set('_name', utils.resourceref.to_objref(path)) |
1379 |
|
1380 def __reduce_ex__(self, protocol_version): |
|
1381 """ |
|
1382 Make the Configuration pickle a ConfigurationProxy object that would load this configuration |
|
1383 """ |
|
1384 return super(ConfigurationProxy, self).__reduce_ex__(protocol_version) |
|
1385 |
1409 |
1386 def _clone(self, **kwargs): |
1410 def _clone(self, **kwargs): |
1387 """ |
1411 """ |
1388 A ConfigurationProxy specific implementation for cloning. |
1412 A ConfigurationProxy specific implementation for cloning. |
1389 Copies all (public) members in dictionary. |
1413 Copies all (public) members in dictionary. |
1660 self.name = kwargs.get('name', None) |
1684 self.name = kwargs.get('name', None) |
1661 self.type = kwargs.get('type', None) |
1685 self.type = kwargs.get('type', None) |
1662 self.relevant = kwargs.get('relevant', None) |
1686 self.relevant = kwargs.get('relevant', None) |
1663 self.constraint = kwargs.get('constraint', None) |
1687 self.constraint = kwargs.get('constraint', None) |
1664 self._dataproxy = None |
1688 self._dataproxy = None |
|
1689 self.extensionAttributes = [] |
1665 |
1690 |
1666 def __copy__(self): |
1691 def __copy__(self): |
1667 dict = {} |
1692 dict = {} |
1668 for key in self.__dict__.keys(): |
1693 for key in self.__dict__.keys(): |
1669 if key.startswith('_') or key == 'ref': |
1694 if key.startswith('_') or key == 'ref': |
1675 |
1700 |
1676 def __getstate__(self): |
1701 def __getstate__(self): |
1677 state = super(Feature, self).__getstate__() |
1702 state = super(Feature, self).__getstate__() |
1678 # remove the dataproxy value so that it is not stored in serializings |
1703 # remove the dataproxy value so that it is not stored in serializings |
1679 state.pop('_dataproxy', None) |
1704 state.pop('_dataproxy', None) |
|
1705 # remove instancemethods so that those are not stored in serializings |
|
1706 state.pop('get_original_value', None) |
|
1707 state.pop('get_value', None) |
|
1708 state.pop('set_value', None) |
|
1709 state.pop('add_feature', None) |
1680 return state |
1710 return state |
1681 |
1711 |
1682 def __setstate__(self, state): |
1712 def __setstate__(self, state): |
1683 super(Feature, self).__setstate__(state) |
1713 super(Feature, self).__setstate__(state) |
1684 self._dataproxy = None |
1714 self._dataproxy = None |
2195 |
2225 |
2196 if cast_value: value_list = value_subsetting.get_value() |
2226 if cast_value: value_list = value_subsetting.get_value() |
2197 else: value_list = value_subsetting.get_original_value() |
2227 else: value_list = value_subsetting.get_original_value() |
2198 return value_list[key_list.index(mapping_key)] |
2228 return value_list[key_list.index(mapping_key)] |
2199 |
2229 |
|
2230 def set_extension_attributes(self, attributes): |
|
2231 self.extensionAttributes = attributes |
|
2232 |
|
2233 def get_extension_attributes(self): |
|
2234 return self.extensionAttributes |
|
2235 |
|
2236 def add_extension_attribute(self, attribute): |
|
2237 self.extensionAttributes.append(attribute) |
2200 |
2238 |
2201 class FeatureSequence(Feature): |
2239 class FeatureSequence(Feature): |
2202 POLICY_REPLACE = 0 |
2240 POLICY_REPLACE = 0 |
2203 POLICY_APPEND = 1 |
2241 POLICY_APPEND = 1 |
2204 POLICY_PREPEND = 2 |
2242 POLICY_PREPEND = 2 |
2623 super(FeatureSequenceSub, self).__init__(ref) |
2661 super(FeatureSequenceSub, self).__init__(ref) |
2624 self.name = kwargs.get('name', ref) |
2662 self.name = kwargs.get('name', ref) |
2625 self.type = 'subseq' |
2663 self.type = 'subseq' |
2626 self._index = 0 |
2664 self._index = 0 |
2627 |
2665 |
2628 def __getstate__(self): |
|
2629 state = super(FeatureSequenceSub,self).__getstate__() |
|
2630 state['_children'].pop('?datarows', None) |
|
2631 return state |
|
2632 |
|
2633 def get_index(self): |
2666 def get_index(self): |
2634 """ |
2667 """ |
2635 @return : the index of the data element for sequential data defined inside the same configuration. |
2668 @return : the index of the data element for sequential data defined inside the same configuration. |
2636 0 for normal data. |
2669 0 for normal data. |
2637 """ |
2670 """ |
3289 self.value = value |
3322 self.value = value |
3290 self.map = kwargs.get('map', None) |
3323 self.map = kwargs.get('map', None) |
3291 self.relevant = kwargs.get('relevant', None) |
3324 self.relevant = kwargs.get('relevant', None) |
3292 self.map_value = kwargs.get('map_value', None) |
3325 self.map_value = kwargs.get('map_value', None) |
3293 self.display_name = kwargs.get('display_name', None) |
3326 self.display_name = kwargs.get('display_name', None) |
|
3327 self.extensionAttributes = [] |
3294 |
3328 |
3295 @classmethod |
3329 @classmethod |
3296 def to_optref(cls, value, map): |
3330 def to_optref(cls, value, map): |
3297 """ |
3331 """ |
3298 @return: An option reference converted from value or map, depending |
3332 @return: An option reference converted from value or map, depending |
3321 elif self.ref == ref: |
3355 elif self.ref == ref: |
3322 return 0 |
3356 return 0 |
3323 else: |
3357 else: |
3324 return 1 |
3358 return 1 |
3325 |
3359 |
|
3360 def set_extension_attributes(self, attributes): |
|
3361 self.extensionAttributes = attributes |
|
3362 |
|
3363 def get_extension_attributes(self): |
|
3364 return self.extensionAttributes |
|
3365 |
|
3366 def add_extension_attribute(self, attribute): |
|
3367 self.extensionAttributes.append(attribute) |
3326 |
3368 |
3327 class Storage(object): |
3369 class Storage(object): |
3328 """ |
3370 """ |
3329 A general base class for all storage type classes |
3371 A general base class for all storage type classes |
3330 """ |
3372 """ |
3343 self.curpath = "" |
3385 self.curpath = "" |
3344 self.container = True |
3386 self.container = True |
3345 self.__opened_res__ = {} |
3387 self.__opened_res__ = {} |
3346 self.mode = mode |
3388 self.mode = mode |
3347 self.cpath_stack = [] |
3389 self.cpath_stack = [] |
3348 |
|
3349 def __reduce_ex__(self, protocol_version): |
|
3350 return (open_storage, |
|
3351 (self.path, self.mode), |
|
3352 None, |
|
3353 None, |
|
3354 None) |
|
3355 |
3390 |
3356 def __opened__(self, res): |
3391 def __opened__(self, res): |
3357 """ |
3392 """ |
3358 Internal function to add a newly opened Resource object to the list of open resources. |
3393 Internal function to add a newly opened Resource object to the list of open resources. |
3359 @param res: The resource object |
3394 @param res: The resource object |
3972 for layerpath in self.list_layers(): |
4007 for layerpath in self.list_layers(): |
3973 for respath in self.get_layer(layerpath).list_confml(): |
4008 for respath in self.get_layer(layerpath).list_confml(): |
3974 lres.append(utils.resourceref.join_refs([layerpath, respath])) |
4009 lres.append(utils.resourceref.join_refs([layerpath, respath])) |
3975 return lres |
4010 return lres |
3976 |
4011 |
3977 def list_implml(self): |
4012 def list_implml(self,empty_folders=False): |
3978 """ |
4013 """ |
3979 @return: array of implml file references. |
4014 @return: array of implml file references. |
3980 """ |
4015 """ |
3981 lres = [] |
4016 lres = [] |
3982 for layerpath in self.list_layers(): |
4017 for layerpath in self.list_layers(): |
3983 for respath in self.get_layer(layerpath).list_implml(): |
4018 for respath in self.get_layer(layerpath).list_implml(empty_folders): |
3984 lres.append(utils.resourceref.join_refs([layerpath, respath])) |
4019 lres.append(utils.resourceref.join_refs([layerpath, respath])) |
3985 return lres |
4020 return lres |
3986 |
4021 |
3987 def list_content(self): |
4022 def list_content(self,empty_folders=False): |
3988 """ |
4023 """ |
3989 @return: array of content file references. |
4024 @return: array of content file references. |
3990 """ |
4025 """ |
3991 lres = [] |
4026 lres = [] |
3992 for layerpath in self.list_layers(): |
4027 for layerpath in self.list_layers(): |
3993 for respath in self.get_layer(layerpath).list_content(): |
4028 for respath in self.get_layer(layerpath).list_content(empty_folders): |
3994 lres.append(utils.resourceref.join_refs([layerpath, respath])) |
4029 lres.append(utils.resourceref.join_refs([layerpath, respath])) |
3995 return lres |
4030 return lres |
3996 |
4031 |
3997 def list_doc(self): |
4032 def list_doc(self,empty_folders=False): |
3998 """ |
4033 """ |
3999 @return: array of document file references. |
4034 @return: array of document file references. |
4000 """ |
4035 """ |
4001 lres = [] |
4036 lres = [] |
4002 for layerpath in self.list_layers(): |
4037 for layerpath in self.list_layers(): |
4003 for respath in self.get_layer(layerpath).list_doc(): |
4038 for respath in self.get_layer(layerpath).list_doc(empty_folders): |
4004 lres.append(utils.resourceref.join_refs([layerpath, respath])) |
4039 lres.append(utils.resourceref.join_refs([layerpath, respath])) |
4005 return lres |
4040 return lres |
4006 |
4041 |
4007 def list_all_resources(self, **kwargs): |
4042 def list_all_resources(self, **kwargs): |
4008 """ |
4043 """ |
4078 """ |
4113 """ |
4079 res = self.list_resources(self.predefined['confml_path'], recurse=True) |
4114 res = self.list_resources(self.predefined['confml_path'], recurse=True) |
4080 res += super(Layer, self).list_confml() |
4115 res += super(Layer, self).list_confml() |
4081 return res |
4116 return res |
4082 |
4117 |
4083 def list_implml(self): |
4118 def list_implml(self,empty_folders=False): |
4084 """ |
4119 """ |
4085 @return: array of implml file references. |
4120 @return: array of implml file references. |
4086 """ |
4121 """ |
4087 res = self.list_resources(self.predefined['implml_path'], recurse=True) |
4122 res = self.list_resources(self.predefined['implml_path'], recurse=True,empty_folders=empty_folders) |
4088 res += super(Layer, self).list_implml() |
4123 res += super(Layer, self).list_implml(empty_folders) |
4089 return res |
4124 return res |
4090 |
4125 |
4091 def list_content(self): |
4126 def list_content(self,empty_folders=False): |
4092 """ |
4127 """ |
4093 @return: array of content file references. |
4128 @return: array of content file references. |
4094 """ |
4129 """ |
4095 res = self.list_resources(self.predefined['content_path'], recurse=True) |
4130 res = self.list_resources(self.predefined['content_path'], recurse=True,empty_folders=empty_folders) |
4096 res += super(Layer, self).list_content() |
4131 res += super(Layer, self).list_content(empty_folders) |
4097 return res |
4132 return res |
4098 |
4133 |
4099 def list_doc(self): |
4134 def list_doc(self,empty_folders=False): |
4100 """ |
4135 """ |
4101 @return: array of document file references. |
4136 @return: array of document file references. |
4102 """ |
4137 """ |
4103 res = self.list_resources(self.predefined['doc_path'], recurse=True) |
4138 res = self.list_resources(self.predefined['doc_path'], recurse=True,empty_folders=empty_folders) |
4104 res += super(Layer, self).list_doc() |
4139 res += super(Layer, self).list_doc(empty_folders) |
4105 return res |
4140 return res |
4106 |
4141 |
4107 def confml_folder(self): |
4142 def confml_folder(self): |
4108 cpath = self.get_current_path() |
4143 cpath = self.get_current_path() |
4109 spath = self.predefined['confml_path'] |
4144 spath = self.predefined['confml_path'] |
4208 Return a instance of appropriate mapper for given model. |
4243 Return a instance of appropriate mapper for given model. |
4209 """ |
4244 """ |
4210 mapmodule = __import__('cone.public.mapping') |
4245 mapmodule = __import__('cone.public.mapping') |
4211 return mapmodule.public.mapping.BaseMapper() |
4246 return mapmodule.public.mapping.BaseMapper() |
4212 |
4247 |
|
4248 class RulemlEvalGlobals(Base): |
|
4249 """ |
|
4250 Ruleml subelement of extensions element |
|
4251 """ |
|
4252 refname = "_extension" |
|
4253 def __init__(self, value = None, file = None, **kwargs): |
|
4254 """ |
|
4255 """ |
|
4256 super(RulemlEvalGlobals,self).__init__(self.refname) |
|
4257 self.value = value |
|
4258 self.file = file |
|
4259 |
|
4260 @classmethod |
|
4261 def get_script_file_full_path(self, child): |
|
4262 parent_config = child._find_parent(type=Configuration) |
|
4263 cpath = parent_config.get_full_path() |
|
4264 cpath = utils.resourceref.psplit_ref(cpath)[0] |
|
4265 path = utils.resourceref.join_refs([cpath, child.file]) |
|
4266 return path |
4213 |
4267 |
4214 class Problem(object): |
4268 class Problem(object): |
4215 SEVERITY_ERROR = "error" |
4269 SEVERITY_ERROR = "error" |
4216 SEVERITY_WARNING = "warning" |
4270 SEVERITY_WARNING = "warning" |
4217 SEVERITY_INFO = "info" |
4271 SEVERITY_INFO = "info" |