# Licensed to the Apache Software Foundation (ASF) under one# or more contributor license agreements. See the NOTICE file# distributed with this work for additional information# regarding copyright ownership. The ASF licenses this file# to you under the Apache License, Version 2.0 (the# "License"); you may not use this file except in compliance# with the License. You may obtain a copy of the License at## http://www.apache.org/licenses/LICENSE-2.0## Unless required by applicable law or agreed to in writing,# software distributed under the License is distributed on an# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY# KIND, either express or implied. See the License for the# specific language governing permissions and limitations# under the License."""DolphinScheduler Base object."""fromtypingimportDict,Optional# from pydolphinscheduler.models.user import Userfrompydolphinscheduler.utils.stringimportattr2camel
[docs]classBase:"""DolphinScheduler Base object."""# Object key attribute, to test whether object equals and so on._KEY_ATTR:set={"name","description"}# Object defines attribute, use when needs to communicate with Java gateway server._DEFINE_ATTR:set=set()# Object default attribute, will add those attribute to `_DEFINE_ATTR` when init assign missing._DEFAULT_ATTR:Dict={}def__init__(self,name:str,description:Optional[str]=None):self.name=nameself.description=descriptiondef__repr__(self)->str:returnf'<{type(self).__name__}: name="{self.name}">'def__eq__(self,other):returntype(self)==type(other)andall(getattr(self,a,None)==getattr(other,a,None)forainself._KEY_ATTR)
[docs]defget_define_custom(self,camel_attr:bool=True,custom_attr:set=None)->Dict:"""Get object definition attribute by given attr set."""content={}forattrincustom_attr:val=getattr(self,attr,None)ifcamel_attr:content[attr2camel(attr)]=valelse:content[attr]=valreturncontent
[docs]defget_define(self,camel_attr:bool=True)->Dict:"""Get object definition attribute communicate to Java gateway server. use attribute `self._DEFINE_ATTR` to determine which attributes should including when object tries to communicate with Java gateway server. """content=self.get_define_custom(camel_attr,self._DEFINE_ATTR)update_default={k:self._DEFAULT_ATTR.get(k)forkinself._DEFAULT_ATTRifknotincontent}content.update(update_default)returncontent