Netrecv function beta version

This commit is contained in:
2019-12-15 11:32:54 +08:00
parent 04da406157
commit 87081c9149
6 changed files with 63 additions and 5 deletions

View File

@@ -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)

11
mswp.py
View File

@@ -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

47
plugins/compress.py Normal file
View File

@@ -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()

View File

@@ -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)

View File

@@ -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()