Netrecv function beta version
This commit is contained in:
@@ -21,13 +21,12 @@ def send_queue_function():
|
|||||||
global send_queue, receive_queues
|
global send_queue, receive_queues
|
||||||
while True:
|
while True:
|
||||||
dp = send_queue.get()
|
dp = send_queue.get()
|
||||||
print('dp.app is', dp.app)
|
dp.encode()
|
||||||
if dp.app == 'all':
|
if dp.app == 'all':
|
||||||
for q in receive_queues:
|
for q in receive_queues:
|
||||||
receive_queues[q].put(dp)
|
receive_queues[q].put(dp)
|
||||||
elif ',' in dp.app:
|
elif ',' in dp.app:
|
||||||
applist = dp.app.split(',')
|
applist = dp.app.split(',')
|
||||||
print(applist)
|
|
||||||
dp_list = []
|
dp_list = []
|
||||||
for i in range(len(applist)): # split dp
|
for i in range(len(applist)): # split dp
|
||||||
new_dp = copy.copy(dp)
|
new_dp = copy.copy(dp)
|
||||||
|
|||||||
11
mswp.py
11
mswp.py
@@ -11,6 +11,7 @@ class Datapack:
|
|||||||
self.encode_data = b''
|
self.encode_data = b''
|
||||||
|
|
||||||
def encode(self):
|
def encode(self):
|
||||||
|
self.head['length': str(len(self.body))]
|
||||||
first_line = self.method.encode() + b' ' + self.app.encode() + b' ' + self.version.encode()
|
first_line = self.method.encode() + b' ' + self.app.encode() + b' ' + self.version.encode()
|
||||||
heads = ''.encode()
|
heads = ''.encode()
|
||||||
for i in self.head:
|
for i in self.head:
|
||||||
@@ -29,4 +30,14 @@ class Datapack:
|
|||||||
i, ii = line.split(': ')
|
i, ii = line.split(': ')
|
||||||
self.head[i] = ii
|
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
47
plugins/compress.py
Normal 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()
|
||||||
@@ -14,7 +14,6 @@ def main():
|
|||||||
app = app.replace(' ', '')
|
app = app.replace(' ', '')
|
||||||
dp = Datapack(head={'from': __name__})
|
dp = Datapack(head={'from': __name__})
|
||||||
dp.app = app
|
dp.app = app
|
||||||
print(body)
|
|
||||||
dp.body = body.encode()
|
dp.body = body.encode()
|
||||||
send_queue.put(dp)
|
send_queue.put(dp)
|
||||||
|
|
||||||
@@ -25,7 +24,6 @@ def find_the_last(indata): # find the last ":" index
|
|||||||
try:
|
try:
|
||||||
next_index = indata[first_index+1:].index(':')
|
next_index = indata[first_index+1:].index(':')
|
||||||
first_index += next_index + 1
|
first_index += next_index + 1
|
||||||
print(first_index)
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
break
|
break
|
||||||
last_index = copy.copy(first_index)
|
last_index = copy.copy(first_index)
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ class Netrecv:
|
|||||||
while True:
|
while True:
|
||||||
conn, addr = self.s.accept()
|
conn, addr = self.s.accept()
|
||||||
self.connection_list.append((conn, addr))
|
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)
|
self.connection_process_thread_list.append(connection_thread)
|
||||||
connection_thread.start()
|
connection_thread.start()
|
||||||
|
|
||||||
@@ -69,6 +69,9 @@ class Netrecv:
|
|||||||
print('Connection accpet %s' % str(addr))
|
print('Connection accpet %s' % str(addr))
|
||||||
while True:
|
while True:
|
||||||
data = conn.recv(RECV_BUFF) # here needs to check whether the package is continued
|
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 = Datapack(check_head=False)
|
||||||
dp.encode_data = data
|
dp.encode_data = data
|
||||||
dp.decode()
|
dp.decode()
|
||||||
|
|||||||
Reference in New Issue
Block a user