auto update
This commit is contained in:
@@ -1 +1 @@
|
|||||||
127.0.0.1:3900
|
127.0.0.1:3900
|
||||||
@@ -8,8 +8,10 @@ import os
|
|||||||
class Print_controller:
|
class Print_controller:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.padding_queue = queue.Queue()
|
self.padding_queue = queue.Queue()
|
||||||
self.thread = threading.Thread(target=self.start_printing, args=(), daemon=True)
|
|
||||||
self.original_print = print
|
self.original_print = print
|
||||||
|
|
||||||
|
self.thread = threading.Thread(target=self.start_printing, args=(), daemon=True)
|
||||||
|
self.thread.start()
|
||||||
|
|
||||||
def start_printing(self):
|
def start_printing(self):
|
||||||
while True:
|
while True:
|
||||||
@@ -60,4 +62,4 @@ msw_queue = queue.Queue()
|
|||||||
jsondata = Jsondata()
|
jsondata = Jsondata()
|
||||||
|
|
||||||
print_controller = Print_controller()
|
print_controller = Print_controller()
|
||||||
print = print_controller.print_function
|
dprint = print_controller.print_function
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import time
|
|||||||
from mswp import Datapack
|
from mswp import Datapack
|
||||||
from forwarder import receive_queues, send_queue
|
from forwarder import receive_queues, send_queue
|
||||||
from config import jsondata
|
from config import jsondata
|
||||||
|
from config import dprint as print
|
||||||
receive_queue = receive_queues[__name__]
|
receive_queue = receive_queues[__name__]
|
||||||
|
|
||||||
BUFFSIZE = jsondata.try_to_read_jsondata('buffsize', 4096)
|
BUFFSIZE = jsondata.try_to_read_jsondata('buffsize', 4096)
|
||||||
@@ -217,15 +218,8 @@ class Connection:
|
|||||||
length = int(dp.head.get('length'))
|
length = int(dp.head.get('length'))
|
||||||
still_need = length
|
still_need = length
|
||||||
|
|
||||||
if still_need <= len(self.buff): # first download complete setuation
|
if still_need > len(self.buff):
|
||||||
if dp.method == 'file':
|
# writing tmp data
|
||||||
with open(dp.head['filename'], 'ab') as f:
|
|
||||||
f.write(self.buff[:still_need])
|
|
||||||
else:
|
|
||||||
dp.body = self.buff[:still_need]
|
|
||||||
self.buff = self.buff[still_need:]
|
|
||||||
still_need = 0
|
|
||||||
else: # writing tmp data
|
|
||||||
if dp.method == 'file':
|
if dp.method == 'file':
|
||||||
with open(dp.head['filename'], 'ab') as f:
|
with open(dp.head['filename'], 'ab') as f:
|
||||||
still_need -= f.write(self.buff)
|
still_need -= f.write(self.buff)
|
||||||
@@ -233,9 +227,20 @@ class Connection:
|
|||||||
dp.body += self.buff
|
dp.body += self.buff
|
||||||
still_need -= len(self.buff)
|
still_need -= len(self.buff)
|
||||||
self.buff = b'' # empty buff because all tmp data has been write
|
self.buff = b'' # empty buff because all tmp data has been write
|
||||||
|
|
||||||
|
else: # download complete setuation
|
||||||
|
if dp.method == 'file':
|
||||||
|
with open(dp.head['filename'], 'ab') as f:
|
||||||
|
f.write(self.buff[:still_need])
|
||||||
|
else:
|
||||||
|
dp.body = self.buff[:still_need]
|
||||||
|
self.buff = self.buff[still_need:]
|
||||||
|
still_need = 0
|
||||||
|
|
||||||
# bleow code are using to process datapack
|
# bleow code are using to process datapack
|
||||||
send_queue.put(dp)
|
if dp.method == 'file':
|
||||||
|
print('Received file %s' % dp.head['filename'], dp)
|
||||||
|
send_queue.put(dp)
|
||||||
|
|
||||||
|
|
||||||
# below code are using to closed connection
|
# below code are using to closed connection
|
||||||
@@ -258,11 +263,7 @@ class Connection:
|
|||||||
3: appname is not handshake
|
3: appname is not handshake
|
||||||
'''
|
'''
|
||||||
if self.positive:
|
if self.positive:
|
||||||
ndp = Datapack(head={'from': __name__})
|
self.send_id()
|
||||||
ndp.app = 'handshake'
|
|
||||||
ndp.encode()
|
|
||||||
print(ndp.encode_data.decode())
|
|
||||||
self.conn.sendall(ndp.encode_data)
|
|
||||||
|
|
||||||
data = self.conn.recv(BUFFSIZE)
|
data = self.conn.recv(BUFFSIZE)
|
||||||
if not data:
|
if not data:
|
||||||
@@ -280,8 +281,18 @@ class Connection:
|
|||||||
|
|
||||||
self.id = dp.head['id']
|
self.id = dp.head['id']
|
||||||
|
|
||||||
|
if not self.positive:
|
||||||
|
self.send_id()
|
||||||
|
|
||||||
return 0, dp.head.get('flag')
|
return 0, dp.head.get('flag')
|
||||||
|
|
||||||
|
|
||||||
|
def send_id(self):
|
||||||
|
dp = Datapack(head={'from': __name__})
|
||||||
|
dp.app = 'handshake'
|
||||||
|
dp.encode()
|
||||||
|
self.conn.sendall(dp.encode_data)
|
||||||
|
|
||||||
|
|
||||||
def sendall(self, dp):
|
def sendall(self, dp):
|
||||||
self.padding_queue.put(dp)
|
self.padding_queue.put(dp)
|
||||||
|
|||||||
@@ -3,10 +3,11 @@ import tarfile
|
|||||||
import os
|
import os
|
||||||
from mswp import Datapack
|
from mswp import Datapack
|
||||||
from forwarder import receive_queues, send_queue
|
from forwarder import receive_queues, send_queue
|
||||||
|
from config import msw_queue
|
||||||
receive_queue = receive_queues[__name__]
|
receive_queue = receive_queues[__name__]
|
||||||
|
|
||||||
|
|
||||||
remove_file_list = ['__init__.py', 'netlist.txt', 'config.json', 'logger.log']
|
remove_file_list = ['__init__.py', 'addrlist.txt', 'config.json', 'logger.log']
|
||||||
remove_dir_list = ['.git', '.idea', '__pycache__', 'resources']
|
remove_dir_list = ['.git', '.idea', '__pycache__', 'resources']
|
||||||
|
|
||||||
|
|
||||||
@@ -42,6 +43,8 @@ def main():
|
|||||||
print('Starting update local file')
|
print('Starting update local file')
|
||||||
with tarfile.open(dp.head['filename'], 'r:xz') as f:
|
with tarfile.open(dp.head['filename'], 'r:xz') as f:
|
||||||
f.extractall()
|
f.extractall()
|
||||||
|
#os.remove(dp.head['filename'])
|
||||||
|
msw_queue.put(0)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user