Browse Source

Adjust progress output in upgrade function

master
Dmitry Ermakov 1 year ago
parent
commit
2ace505470
  1. 32
      dvrip.py

32
dvrip.py

@ -711,7 +711,7 @@ class DVRIPCam(object):
def upgrade(self, filename="", packetsize=0x8000, vprint=None): def upgrade(self, filename="", packetsize=0x8000, vprint=None):
if not vprint: if not vprint:
vprint = lambda x: print(x) vprint = lambda *args, **kwargs: print(*args, **kwargs)
data = self.set_command( data = self.set_command(
"OPSystemUpgrade", {"Action": "Start", "Type": "System"}, 0x5F0 "OPSystemUpgrade", {"Action": "Start", "Type": "System"}, 0x5F0
@ -719,7 +719,7 @@ class DVRIPCam(object):
if data["Ret"] not in self.OK_CODES: if data["Ret"] not in self.OK_CODES:
return data return data
vprint("Ready to upgrade") self.logger.debug(f"Sending file: {filename}")
blocknum = 0 blocknum = 0
sentbytes = 0 sentbytes = 0
fsize = os.stat(filename).st_size fsize = os.stat(filename).st_size
@ -738,38 +738,32 @@ class DVRIPCam(object):
reply, rcvd = self.recv_json(rcvd) reply, rcvd = self.recv_json(rcvd)
if reply and reply["Ret"] != 100: if reply and reply["Ret"] != 100:
vprint("Upgrade failed") vprint("\nUpgrade failed")
return reply return reply
progress = sentbytes / fsize * 100 progress = sentbytes / fsize * 100
vprint(f"Uploaded {progress:.2f}%") vprint(f"Uploading: {progress:.1f}%", end='\r')
vprint("End of file") vprint()
self.logger.debug("Upload complete")
pkt = struct.pack("BB2xIIxBHI", 255, 0, self.session, blocknum, 1, 0x05F2, 0) pkt = struct.pack("BB2xIIxBHI", 255, 0, self.session, blocknum, 1, 0x05F2, 0)
self.socket_send(pkt) self.socket_send(pkt)
vprint("Waiting for upgrade...") self.logger.debug("Starting upgrade...")
while True:
reply, rcvd = self.recv_json(rcvd)
print(reply)
if not reply:
return
if reply["Name"] == "" and reply["Ret"] == 100:
break
while True: while True:
data, rcvd = self.recv_json(rcvd) data, rcvd = self.recv_json(rcvd)
print(reply) self.logger.debug(reply)
if data is None: if data is None:
vprint("Done") vprint("\nDone")
return return
if data["Ret"] in [512, 514, 513]: if data["Ret"] in [512, 514, 513]:
vprint("Upgrade failed") vprint("\nUpgrade failed")
return data return data
if data["Ret"] == 515: if data["Ret"] == 515:
vprint("Upgrade successful") vprint("\nUpgrade successful")
self.socket.close() self.socket.close()
return data return data
vprint(f"Upgraded {data['Ret']}%") vprint(f"Upgrading: {data['Ret']:>3}%", end='\r')
vprint()
def get_file(self, first_chunk_size): def get_file(self, first_chunk_size):
buf = bytearray() buf = bytearray()

Loading…
Cancel
Save