net bug fix and update function

This commit is contained in:
2019-12-19 08:09:06 +08:00
parent 9243c407a1
commit a35524eb0c
5 changed files with 80 additions and 28 deletions

View File

@@ -6,15 +6,42 @@ from forwarder import receive_queues, send_queue
receive_queue = receive_queues[__name__]
remove_file_list = ['__init__.py']
remove_file_list = ['__init__.py', 'netlist.txt', 'config.json', 'logger.log']
remove_dir_list = ['.git', '.idea', '__pycache__']
def main():
while True:
dp = receive_queue.get()
dp.encode()
print(dp.encode_data.decode())
if dp.method == 'post':
if dp.body == b'compress':
print('Starting update')
compress = Compresser()
filelist = compress.get_filelist()
compress.compress_files(filelist)
print('Compress finished')
elif dp.body == b'all':
print('Start update other client')
compress = Compresser()
filelist = compress.get_filelist()
compress.compress_files(filelist)
print('Compress finished')
dp = Datapack(head={'from': __name__})
dp.method = 'file'
dp.app = 'net:update'
dp.head['filename'] = 'resources/update.tar.xz'
dp.encode()
send_queue.put(dp)
elif dp.method == 'file':
print('Starting update local file')
with tarfile.open(dp.head['filename'], 'r:xz') as f:
f.extractall()
@@ -23,7 +50,7 @@ class Compresser:
self.filelist = []
def compress_files(self, filelist):
with tarfile.open('update.tar.xz', 'w:xz') as f:
with tarfile.open('resources/update.tar.xz', 'w:xz') as f:
for name in filelist:
f.add(name)