# only text file
# F2 to send file
'''
<parameters>
<company>DSSL</company>
<title>Uvarov EG</title>
<version>1.0</version>
<parameter>
<type>server</type>
<id>SERVER</id>
<name>Сервер</name>
<value></value>
</parameter>
<parameter>
<type>string</type>
<id>NAME_FILE</id>
<name>Имя файла с расширением</name>
</parameter>
</parameters>
'''
import os
import time
class ReplaceFile():
"""send file Windows - TrassirOS and check"""
def __init__(self, file, server):
self.file = file
self.path = os.path.join(settings("system_wide_options")["screenshots_folder"], file)
self.server = server
self.guid = settings("/%s/scripts" % self.server)["script_new_guid"]
self.body_file = """
import os
rt = os.path.join(settings("system_wide_options")["screenshots_folder"],"{0}")
cop = '''{1}'''
with open(rt, 'wb') as f:
f.write(cop)
if os.path.isfile(rt):
mess = 'Файл отправлен!'
else:
mess = 'Файл не удалось передать!'
settings("scripts/{2}")["name"] = mess
"""
settings("/%s/scripts" % self.server)["script_create_now"] = 1
activate_on_shortcut("F2", self.read_send_file)
def read_send_file(self):
try:
with open(self.path, 'rb') as f:
text = self.body_file.format(self.file, f.read(), self.guid)
settings("/%s/scripts/%s" % (self.server, self.guid))["script"] = text
self.name = settings("/%s/scripts/%s" % (self.server, self.guid))["name"]
timeout(4000, self.check_send_src)
except Exception as e:
raise ValueError('Не удалось прочитать файл.\n%s' % e)
def check_send_src(self):
ch_name = settings("/%s/scripts/%s" % (self.server, self.guid))["name"]
if self.name != ch_name:
self.del_send_scr()
raise ValueError(ch_name)
else:
timeout(1000, self.check_send_src)
def del_send_scr(self):
settings("/%s/scripts" % self.server)['script_erase'] = self.guid
if not NAME_FILE or not SERVER:
raise ValueError('Заполните параметры!')
rf = ReplaceFile(NAME_FILE, SERVER)