def hostname(self, hostname): """ Sets the hostname of the node. :param str hostname: The new Hostname of the Node. :return: None :raises TypeError: If Hostname is not a str. """ if type(hostname) == str and re_name.match(hostname): self.send('uci set system.@system[0].hostname={}'.format(hostname)) self.send('uci commit') else: raise TypeError("Hostname must be a string.")
def __read_process(self, file_raw): self.__del_msgs(70, 51, 52, 60, 71, 61, 72, 62, 73, 80) line_no = 0 self.__read_done = False cache_name = None cache_mac = None cache_key = None cache_comment = None cache_script_name = None cache_script_version = None cache_script_last_edit_date = None cache_script_used_found = False cache_script_verified = None for line in file_raw: check_matches_found = 0 line_no += 1 # ToDo: Detect supernodes!!!!! # Check: Name (perfect match) if re_name_line.match(line): l = line.rstrip().split(' ')[1] if re_name.match(l): if self.__filename == l: if not cache_name: cache_name = (l, line_no) check_matches_found += 1 else: # Already found self.__error.update({70: self.__msg[70].format(line_no, cache_name[1])}) else: self.__name_inconsistent = True cache_name = (l, line_no) # Inconsistent Name (name != filename) self.__debug.update({52: self.__msg[52].format(self.__filename, l, line_no)}) else: # Not match pattern self.__error.update({60: self.__msg[60].format(line_no)}) # Check: MAC (perfect match) if re_mac_line.match(line): l = line.rstrip().split(' ')[1] if re_mac.match(l): if not cache_mac: cache_mac = (l, line_no) check_matches_found += 1 else: # Already found self.__error.update({71: self.__msg[71].format(line_no, cache_mac[1])}) else: # Not match pattern self.__error.update({61: self.__msg[61].format(line_no)}) # Check: key (perfect match) if re_key_line.match(line): l = line.rstrip().split('\"')[1] if re_key.match(l): if not cache_key: cache_key = (l, line_no) check_matches_found += 1 else: # Already found self.__error.update({72: self.__msg[72](line_no, cache_key[1])}) else: # Not match pattern self.__error.update({62: self.__msg[62].format(line_no)}) # Check: Comment (perfect match) if re_comment_line.match(line): l = line.rstrip().split(':', 1)[1].lstrip() if not cache_comment: cache_comment = (l, line_no) check_matches_found += 1 else: # Already found self.__error.update({73: self.__msg[73].format(line_no, cache_comment[1])}) # Check: Peer Line (perfect match) (#gwconfig: v0.1.0, 2015-08-20 #Verification: Name, MAC) if re_peer_line.match(line): l = line.rstrip().split('#') try: l.remove('') except ValueError: pass # ToDo: Use RegEx and remove this!!!! Where is this *** duck? try: cache_script_version = l[0].split(',')[0].split(':')[1].rstrip().lstrip().split('v')[1].split('.') cache_script_last_edit_date = l[0].split(',')[1].rstrip().lstrip() # ToDo: Use date cache_script_verified = [x.rstrip().lstrip() for x in l[1].split(':')[1].split(',')] cache_script_name = (l[0].split(',')[0].split(':')[0].rstrip().lstrip()) cache_script_used_found = True except: # ToDo: Add exceptions (PEP8) self.__debug.update(self.__msg[51]) cache_script_version = None cache_script_last_edit_date = None cache_script_verified = None cache_script_name = None cache_script_used_found = False # True? Script was found but with None in script_* = err if check_matches_found > 1: pass # ToDo: Add err # Write cache into variables if cache_name: self.__name = cache_name[0] else: # Name not found & Filename is now Name self.__debug.update({80: self.__msg[80].format(self.__filename)}) self.__name = self.__filename if cache_mac: self.__mac = cache_mac[0] if cache_key: self.__key = cache_key[0] if cache_comment: self.__comment = cache_comment[0] self.__script_version = cache_script_version self.__script_last_edit_date = cache_script_last_edit_date self.__script_verified = cache_script_verified self.__script_Name = cache_script_name self.__script_use_found = cache_script_used_found self.__read_done = True