MCPcopy
hub / github.com/RUB-NDS/PRET / do_get

Method do_get

printer.py:446–465  ·  view source on GitHub ↗

Receive file: get

(self, arg, lpath="", r=True)

Source from the content-addressed store, hash-verified

444
445 # ------------------------[ get <file> ]------------------------------
446 def do_get(self, arg, lpath="", r=True):
447 "Receive file: get <file>"
448 if not arg:
449 arg = eval(input("Remote file: "))
450 if not lpath:
451 lpath = self.basename(arg)
452 path = self.rpath(arg) if r else arg
453 str_recv = self.get(path)
454 if str_recv != c.NONEXISTENT:
455 rsize, data = str_recv
456 lsize = len(data)
457 # fix carriage return chars added by some devices
458 if lsize != rsize and len(conv().nstrip(data)) == rsize:
459 lsize, data = rsize, conv().nstrip(data)
460 # write to local file
461 file().write(lpath, data.encode())
462 if lsize == rsize:
463 print((str(lsize) + " bytes received."))
464 else:
465 self.size_mismatch(rsize, lsize)
466
467 def size_mismatch(self, size1, size2):
468 size1, size2 = str(size1), str(size2)

Callers 2

do_editMethod · 0.95
mirrorMethod · 0.95

Calls 8

basenameMethod · 0.95
rpathMethod · 0.95
size_mismatchMethod · 0.95
convClass · 0.90
fileClass · 0.90
nstripMethod · 0.80
getMethod · 0.45
writeMethod · 0.45

Tested by

no test coverage detected