MCPcopy Create free account
hub / github.com/AstroPrint/AstroBox / sendLogs

Method sendLogs

src/astroprint/software.py:625–667  ·  view source on GitHub ↗
(self, ticketNo=None, message=None)

Source from the content-addressed store, hash-verified

623 return True
624
625 def sendLogs(self, ticketNo=None, message=None):
626 import zipfile
627
628 from tempfile import gettempdir
629
630 try:
631 boxId = boxrouterManager().boxId
632
633 #Create the zip file
634 zipFilename = '%s/%s-logs.zip' % (gettempdir(), boxId)
635 zipf = zipfile.ZipFile(zipFilename, 'w')
636
637 for root, dirs, files in os.walk(self._settings.getBaseFolder("logs")):
638 for file in files:
639 zipf.write(os.path.join(root, file), file)
640
641 zipf.close()
642
643 except Exception as e:
644 self._logger.error('Error while zipping logs: %s' % e)
645 return False
646
647 zipf = open(zipFilename, 'rb')
648
649 #send the file to the server
650 r = requests.post(
651 '%s/astrobox/software/logs' % roConfig('cloud.apiHost'),
652 data = { 'ticket': ticketNo, 'message': message, 'boxId': boxId},
653 files = {'file': (zipFilename, zipf)},
654 auth = self._checkAuth(),
655 headers = self._requestHeaders
656 )
657
658 zipf.close()
659
660 #remove the file
661 os.remove(zipFilename)
662
663 if r.status_code == 200:
664 return True
665 else:
666 self._logger.error('Error while sending logs: %d' % r.status_code)
667 return False
668
669 def clearLogs(self):
670 activeLogFiles = ['astrobox.log', 'serial.log', 'electron.log', 'touch.log']

Callers

nothing calls this directly

Calls 10

_checkAuthMethod · 0.95
boxrouterManagerFunction · 0.90
roConfigFunction · 0.90
joinMethod · 0.80
removeMethod · 0.80
getBaseFolderMethod · 0.45
writeMethod · 0.45
closeMethod · 0.45
errorMethod · 0.45
postMethod · 0.45

Tested by

no test coverage detected