Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:

LAB6

.txt
Скачиваний:
0
Добавлен:
03.11.2023
Размер:
5.71 Кб
Скачать
class SSH:
print("Добро пожаловать в SSH клиент")


class client(SSH):
def c1(self):
c1: bool
return c1

def c2(self):
c2: bool
return c2

def h(self):
h: str
return h

def u(self):
u: str
return u

print("Введите номер компьютера")
try:
pc = int(input())
if pc == 1:
h = '192.168.0.1'
u = 'login1'
pas = 'password1'
p = 22
c1 = True
print("Вы подключились к 1 pc")
elif pc == 2:
h = '192.168.0.2'
u = 'login2'
pas = 'password2'
p = 22
c2 = True
print("Вы подключились к 2 pc")
else:
print("Компьютер не зарегестрированн в системе")
except:
c1 = False
c2 = False


class commands(client):
def host(self):
host: str
return host

def password(self):
password: str
return password

def user(self):
user: str
return user

def port(self):
port: int
return port

if client.c1 is True:
pc1 = client()
host = '192.168.0.1'
user = 'login1'
password = 'password1'
port = 22
elif client.c2 is True:
pc2 = client()
host = '192.168.0.2'
user = 'login2'
password = 'password2'
port = 22


class connect(commands):
try:
if commands.host == client.h and commands.user == client.u and \
commands.password == client.pas and commands.port == client.p:
print("Подключение прошло успешно")
else:
print("Подключитесь заново")
except:
print("Произошла ошибка, повторите попытку позже")


class edit(commands):
def value(self):
value: int
return value

def ind(self):
ind: int
return ind

def edit1(array, ind, value):
array1 = []
for j in range(len(array)):
if array[j - 1] == ind:
array1.append(value)
else:
array1.append(array[j])
return print(array1)


class add(commands):
def i(self):
i: int
return i

def add1(array, i):
array.append(i)
return True


class close(commands):
def close1(self):
return print("Подключение закрыто")


def do():
file = open('BD', 'r+')
mas = file.readlines()
file.close()
print("Исходные данные:\n", mas)
print("Выберите действие:\n 1 - редактирование\n 2 - удаление\n 3 - добавление\n 4 - отключиться\n")
count = int(input())
if count == 1:
file = open('BD', 'r+')
mas = file.readlines()
file.close()
result = str(mas)
num = 0 # Количество цифр в списке
for el in range(len(result)):
if result[el] != '[' and result[el] != ']' and result[el] != ' ' and result[el] != ',' \
and result[el] != "'" and result[el] != ' ':
num += 1
else:
pass
print("Введите индекс элемента для редактирования")
ind = int(input())
if error(ind, num) is True:
print("Введите на что меняем элемент")
value = int(input())
else:
do()
val = str(value)
file = open('BD', 'w')
c = 0 # Позиция при переборе списка
for j in range(len(result)):
if result[j] == '[' or result[j] == ']' or result[j] == ' ' or result[j] == ',' \
or result[j] == "'" or result[j] == ' ':
pass
else:
if c == ind:
if c == num - 1:
file.write(val)
elif c == 0:
file.write(val + ', ')
else:
file.write(val + ', ')
else:
if num - 1 == c:
file.write(result[j])
else:
file.write(result[j] + ', ')
c += 1
file.close()
return do()
elif count == 2:
file = open('BD', 'w+')
file.seek(0)
file.close()
return do()
elif count == 3:
file = open('BD', 'r')
mas = file.readlines()
file.close()
print("Введите элемент для добавления")
dop = int(input())
add.add1(mas, dop)
file = open('BD', 'w')
result = str(mas)
for j in range(len(result)):
if result[j] == '[' or result[j] == ']' or result[j] == "'":
pass
else:
file.write(result[j])
file.close()
return do()
elif count == 4:
return close.close1(True)
else:
print("Действие невозможно")


def error(id, n):
if id > n - 1:
print("Не существует такого индекса")
return False
else:
return True


do()
Соседние файлы в предмете Языки программирования