diff --git a/forwarder.py b/forwarder.py index c6f32ba..d78a90b 100644 --- a/forwarder.py +++ b/forwarder.py @@ -21,13 +21,12 @@ def send_queue_function(): global send_queue, receive_queues while True: dp = send_queue.get() - print('dp.app is', dp.app) + dp.encode() if dp.app == 'all': for q in receive_queues: receive_queues[q].put(dp) elif ',' in dp.app: applist = dp.app.split(',') - print(applist) dp_list = [] for i in range(len(applist)): # split dp new_dp = copy.copy(dp) diff --git a/mswp.py b/mswp.py index 236cdf9..5bf3d62 100644 --- a/mswp.py +++ b/mswp.py @@ -11,6 +11,7 @@ class Datapack: self.encode_data = b'' def encode(self): + self.head['length': str(len(self.body))] first_line = self.method.encode() + b' ' + self.app.encode() + b' ' + self.version.encode() heads = ''.encode() for i in self.head: @@ -29,4 +30,14 @@ class Datapack: i, ii = line.split(': ') self.head[i] = ii + def is_enough(self): + body_length = len(self.body) + head_length = int(self.head['length']) + if head_length == body_length: + return True + elif head_length > body_length: + return False + else: + print("Error: length is larger than the body") + raise IOError diff --git a/plugins/compress.py b/plugins/compress.py new file mode 100644 index 0000000..6090931 --- /dev/null +++ b/plugins/compress.py @@ -0,0 +1,47 @@ +import threading +import tarfile +import os +from mswp import Datapack +from forwarder import receive_queues, send_queue +receive_queue = receive_queues[__name__] + + +remove_file_list = ['__init__.py'] +remove_dir_list = ['.git', '.idea', '__pycache__'] + + +def main(): + while True: + dp = receive_queue.get() + dp.encode() + print(dp.encode_data.decode()) + + + +class Compresser: + def __init__(self): + self.filelist = [] + + def compress_files(self, filelist): + with tarfile.open('update.tar.xz', 'w:xz') as f: + for name in filelist: + f.add(name) + + def get_filelist(self): + filelist = [] + for root, dirs, files in os.walk('.'): + for name in remove_file_list: + if name in files: + files.remove(name) + for name in remove_dir_list: + if name in dirs: + dirs.remove(name) + for name in files: + filelist.append(os.path.join(root, name)) + for name in dirs: + pass + return filelist + + +thread = threading.Thread(target=main, args=()) +thread.start() diff --git a/plugins/input.py b/plugins/input.py index 20f2db5..6ee5e93 100644 --- a/plugins/input.py +++ b/plugins/input.py @@ -14,7 +14,6 @@ def main(): app = app.replace(' ', '') dp = Datapack(head={'from': __name__}) dp.app = app - print(body) dp.body = body.encode() send_queue.put(dp) @@ -25,7 +24,6 @@ def find_the_last(indata): # find the last ":" index try: next_index = indata[first_index+1:].index(':') first_index += next_index + 1 - print(first_index) except Exception as e: break last_index = copy.copy(first_index) diff --git a/plugins/logger.py b/plugins/log.py similarity index 100% rename from plugins/logger.py rename to plugins/log.py diff --git a/plugins/net.py b/plugins/net.py index d6be9a2..4c5d8f4 100644 --- a/plugins/net.py +++ b/plugins/net.py @@ -61,7 +61,7 @@ class Netrecv: while True: conn, addr = self.s.accept() self.connection_list.append((conn, addr)) - connection_thread = threading.Thread(target=self.process_connection, args=()) + connection_thread = threading.Thread(target=self.process_connection, args=(conn, addr)) self.connection_process_thread_list.append(connection_thread) connection_thread.start() @@ -69,6 +69,9 @@ class Netrecv: print('Connection accpet %s' % str(addr)) while True: data = conn.recv(RECV_BUFF) # here needs to check whether the package is continued + if not data: + conn.close() + return dp = Datapack(check_head=False) dp.encode_data = data dp.decode()