def _spit_scp(self, desiredcfg, output, depth=""): if depth == "": output._write_output("<SystemConfiguration>\n") for fqdd in desiredcfg: _comp = self.get_comp_from_fqdd(fqdd) if _comp == "invalid": logger.debug("Invalid Component defined!") continue if not "registry" in self.complist[_comp]: logger.debug("Invalid Registry defined!") continue comp = self.complist[_comp]["registry"] grps = self.get_groups(comp) output._write_output(depth + " <Component FQDD=\"" + fqdd + "\">\n") for compen in desiredcfg[fqdd]: props = self.defs[comp]["definitions"][comp]["properties"] compen = UnicodeHelper.stringize(compen) if isinstance(compen, str): self._spit_scp({compen: desiredcfg[fqdd][compen]}, output, depth + " ") continue if not TypeHelper.resolve(compen) in props: logger.debug(TypeHelper.resolve(compen) + " is not found in props") continue cvalue = TypeHelper.resolve(compen) idx = 1 if not isinstance(desiredcfg[fqdd][compen], list): idx = self._attr_print(output, depth, _comp, cvalue, props, desiredcfg[fqdd][compen], idx) else: for ent in desiredcfg[fqdd][compen]: idx = self._attr_print(output, depth, _comp, cvalue, props, ent, idx) output._write_output(depth + " </Component>\n") if depth == "": output._write_output("</SystemConfiguration>\n")
def __init__(self, remote, mount_point = None, common_path = None, isFolder=False, creds = None, fd=None): if PY2: super(FileOnShare, self).__init__() else: super().__init__() if creds is not None and creds.username is not None and "@" in creds.username: username_domain = creds.username.split("@") creds.username = username_domain[0] creds.domain = username_domain[1] self.creds = creds self.isFolder = isFolder remote = UnicodeHelper.stringize(remote) mount_point = UnicodeHelper.stringize(mount_point) common_path = UnicodeHelper.stringize(common_path) if remote == "vFlash": self.remote = vFlash() else: self.remote = self._get_path_object(Share.ShareType, remote, common_path, isFolder) if mount_point and mount_point == "vFlash": self.mount_point = vFlash() elif mount_point: self.mount_point = self._get_path_object(Share.LocalFolderType, mount_point, common_path, isFolder) else: self.mount_point = None if remote is not None and self.remote and isinstance(self.remote, InvalidPath): logger.error("Share path is not valid : {}".format(repr(remote))) raise ValueError("Share path is not valid : {}".format(repr(remote))) if mount_point is not None and self.mount_point and isinstance(self.mount_point, InvalidPath): logger.error("Mount point is not valid : {}".format(repr(mount_point))) raise ValueError("Mount point is not valid : {}".format(repr(mount_point))) self.mounted = False self.fd = fd self.valid = False self.is_template = False if Share.TemplateSpec.match(self.remote_full_path) is not None: self.is_template = True
def __init__(self, remote, mount_point=None, common_path=None, isFolder=False, creds=None, fd=None): if PY2: super(FileOnShare, self).__init__() else: super().__init__() self.creds = creds self.isFolder = isFolder remote = UnicodeHelper.stringize(remote) mount_point = UnicodeHelper.stringize(mount_point) common_path = UnicodeHelper.stringize(common_path) if remote == "vFlash": self.remote = vFlash() else: self.remote = self._get_path_object(Share.ShareType, remote, common_path, isFolder) if mount_point and mount_point == "vFlash": self.mount_point = vFlash() elif mount_point: self.mount_point = self._get_path_object(Share.LocalFolderType, mount_point, common_path, isFolder) else: self.mount_point = None self.mounted = False self.fd = fd self.valid = False self.is_template = False if Share.TemplateSpec.match(self.remote_full_path) is not None: self.is_template = True
def __init__(self, local, isFolder = False, fd = None): if PY2: super(LocalFile, self).__init__() else: super().__init__() self.local = local local = UnicodeHelper.stringize(local) self.local = self._get_local_path_object(Share.LocalFolderType, local, isFolder) self.isFolder = isFolder if self.isFolder and not os.path.isdir(self.local.full_path): print("WARN: Changing isFolder to false, as it is directory") self.isFolder = False elif not self.isFolder and os.path.isdir(self.local.full_path): print("WARN: Changing isFolder to false, as it is not directory") self.isFolder = True self.valid = False self.fd = fd self.is_template = False if Share.TemplateSpec.match(self.local_full_path) is not None: self.is_template = True
def __setattr__(self, name, value): # Do not allow access to internal variables if name in ['_orig_value', '_state']: raise AttributeError('Invalid attribute ' + name) # Freeze mode: No sets allowed if '_freeze' in self.__dict__ and self._freeze: raise ValueError('object in freeze mode') # allow updates to other fields except _value # should we allow updates to '_type', '_alias', '_fname'? if name not in ['_value']: self.__dict__[name] = value return # Create-only attribute : No updates allowed if not self._modifyAllowed and \ self._state in [TypeState.Committed, TypeState.Changing]: raise ValueError('updates not allowed to this object') # CompositeField : sets not allowed in composite fields if self._composite: raise AttributeError('composite objects cannot be modified') # value is None, object was committed; ==> no change if value is None and \ self._state in [TypeState.Committed, TypeState.Precommit, TypeState.Changing]: return # Validate value and convert it if needed valid = False msg = None if value is None or TypeHelper.belongs_to(self._type, value): valid = True elif type(self) == type(value): value = value._value valid = True elif UnicodeHelper.is_string(value): value = UnicodeHelper.stringize(value) # expected value is int if self._type == int: value = int(value) valid = True # expected value is bool elif self._type == bool: value = bool(value) valid = True # expected value is str elif self._type == str: valid = True # expected value is enumeration elif TypeHelper.is_enum(self._type): newvalue = TypeHelper.convert_to_enum(value, self._type) if newvalue is not None: value = newvalue valid = True else: msg = str(value) + " is not " + str(self._type) else: msg = str(value) + " cannot be converted to " + str(self._type) else: msg = "No type conversion found for '" + str(value) + "'. "\ "Expected " + str(self._type.__name__) + ". Got " +\ type(value).__name__ if valid and not self.my_accept_value(value): msg = type(self).__name__ + " returned failure for " + str(value) valid = False # if invalid, raise ValueError exception if not valid: raise ValueError(msg) # same value - no change if name in self.__dict__ and self._value == value: return # List fields, simply append the new entry! if self._list and name in self.__dict__ and self.__dict__[name]: value = self.__dict__[name] + "," + value # modify the value self.__dict__[name] = value if self._state in [ TypeState.UnInitialized, TypeState.Precommit, TypeState.Initializing ]: self.__dict__['_state'] = TypeState.Initializing elif self._state in [TypeState.Committed, TypeState.Changing]: if self._orig_value == self._value: self.__dict__['_state'] = TypeState.Committed else: self.__dict__['_state'] = TypeState.Changing else: print("Should not come here") if self.is_changed() and self._parent: self._parent.child_state_changed(self, self._state)