示例#1
0
 def qPort(self):
     while True:
         enter = input("Port: ")
         checkQuit(enter)
         if enter.isdigit():
             return enter
         else:
             print("Invalid port")
示例#2
0
 def qIp(self):
     while True:
         enter = input(f'Enter a ip adress: ')
         checkQuit(enter)
         if isIp(enter):
             return enter
         else:
             print('Invalid ip')
示例#3
0
 def qUser(self):
     while True:
         enter = input("Enter a user: ")
         checkQuit(enter)
         if bool(enter.strip()):
             return enter.lower()
         else:
             print('Invalid user')
示例#4
0
 def qKeywords(self):
     while True:
         enter = input("Enter a list of names separate by ',': ")
         checkQuit(enter)
         try:
             enter = enter.replace(' ', '').split(",")
             return enter
         except:
             print('Invalid keywords')
示例#5
0
 def qDefault(self):
     while True:
         enter = input(f"Default server ([Y]es | [N]o): ")
         checkQuit(enter)
         if enter.lower() in ['y', 'yes']:
             return True
         elif enter.lower() in ['n', 'no']:
             return False
         else:
             print('Invalid')
示例#6
0
 def edit(self):
     'Edit a connection from json'
     if self.isExist(self.ip):
         connection = self.getConnection(self.ip, 'ip')
         while True:
             ip, user = connection.get('ip'), connection.get('user')
             port, keyword = connection.get('port'), connection.get('keywords')
             default = connection.get('default')
             print(f'Edit connection {self.ip}')
             print(f"ip:{ip}  user:{user}  port:{port}  keywords:{keyword}  default:{default}")
             print('')
             enter = input("What do you want to edit ([Q]uit for exit): ")
             checkQuit(enter)
             if enter.lower() in ['ip', 'user', 'port', 'keywords', 'default']:
                 editCo = CreateConnection()
                 if enter.lower() == 'ip':
                     ip = editCo.qIp()
                     if not self.isExist(ip):
                         self.update(connection, 'ip', ip)
                         self.ip = ip
                         print('Ip edited')
                     else:
                         print('Ip already exist')
                 elif enter.lower() == 'user':
                     self.update(connection, 'user', editCo.qUser())
                     print('User edited')
                 elif enter == 'port':
                     self.update(connection, 'port', editCo.qPort())
                     print('Port edited')
                 elif enter.lower() == 'keywords': 
                     self.update(connection, 'keywords', editCo.qKeywords())
                     print('Keywords edited')
                 elif enter.lower() == 'default': 
                     self.update(connection, 'default', editCo.qDefault())
                     print('Server default edited')
             connection = self.getConnection(self.ip, 'ip')
             print('')
     else:
         print("Connection not found")