def cleanup(self): files = set() for configuration in self.configurations(): filename = configuration.thumbnail() if filename is None: continue files.add(os.path.basename(filename)) for name in os.listdir(Meta.dataPath('thumbnails')): if name not in files: os.remove(os.path.join(Meta.dataPath('thumbnails'), name))
def _launchUpdate(self): self.setTitle(_('Updating')) self.setSubTitle(_('Update in progress...')) self.wizard().button(self.wizard().CancelButton).setEnabled(False) self.wizard().button(self.wizard().BackButton).setEnabled(False) self._process = QtCore.QProcess(self) self._process.errorOccurred.connect(self._onError) self._process.finished.connect(self._onFinished) self._process.readyReadStandardError.connect(self._onStderr) self._process.readyReadStandardOutput.connect(self._onStdout) manifest = Meta.manifest() filename = os.path.join( Meta.dataPath('images'), manifest['leonardo']['firmware']['current']['name']) args = [ '-patmega32u4', '-cavr109', '-P%s' % self._devname, '-b57600', '-D', '-Uflash:w:%s:i' % filename, ] if platform.system() != 'Windows': args.insert(0, '-C%s' % Meta.avrdudeConf()) self._process.start(Settings().avrdude(), args)
def _gotManifest(self, downloader): downloader.downloadSize.disconnect(self._onSize) downloader.downloadProgress.disconnect(self._onProgress) try: unused, data = downloader.result() except AbortedError: self.logger.info('Aborted manifest') if self._getValue(self._manifest, self._path + ('current', 'version')) != 0: self.accept() else: self.reject() return except DownloadError as exc: self.logger.error('Downloading manifest: %s', exc) if self._getValue(self._manifest, self._path + ('current', 'version')) != 0: self.accept() else: self._msg.setText( _('Cannot download manifest:{error}').format( error='<br /><font color="red">%s</font>' % str(exc))) self._btn.setText(_('Bummer')) self._state = self.STATE_ERROR return data = json.loads(data) self._getValue(self._manifest, self._path)['latest'] = self._getValue( data, self._path + ('latest', )) if self._getValue(self._manifest, self._path + ('current', 'version')) == self._getValue( self._manifest, self._path + ('latest', 'version')): self.logger.info('Up to date') self.accept() return handle, filename = tempfile.mkstemp(dir=Meta.dataPath('images')) os.close(handle) self._state = self.STATE_DL self._msg.setText(_('Downloading image...')) self._downloader = FileDownloader(self, self.mainWindow().manager(), filename, callback=self._gotFile) self._downloader.downloadSize.connect(self._onSize) self._downloader.downloadProgress.connect(self._onProgress) self._downloader.get(Meta.imagesUrl().format( filename=self._getValue(self._manifest, self._path + ('latest', 'name'))))
def initializePage(self): self.setTitle(_('Image copy')) self.setSubTitle(_('Copying image file')) manifest = Meta.manifest() name = manifest['rpi0w-v2']['image']['current']['name'] self._src = os.path.join(Meta.dataPath('images'), name) self._dst = os.path.join( QtCore.QStandardPaths.writableLocation( QtCore.QStandardPaths.DownloadLocation), '%s.img' % os.path.splitext(name)[0]) ssid, password = self.wizard().wifi() self._thread = ImageCopyThread(self._src, self._dst, ssid, password, self.wizard().ssh()) self._thread.progress.connect(self._onProgress) self._thread.finished.connect(self._onFinished) self._thread.error.connect(self._onError) self._thread.start()
def _gotFile(self, downloader): downloader.downloadSize.disconnect(self._onSize) downloader.downloadProgress.disconnect(self._onProgress) try: downloader.result() except AbortedError: self.logger.info('Aborted image') if self._getValue(self._manifest, self._path + ('current', 'version')) != 0: self.accept() else: self.reject() return except DownloadError as exc: self.logger.error('Downloading image: %s', exc) if self._getValue(self._manifest, self._path + ('current', 'version')) != 0: self.accept() else: self._msg.setText( _('Cannot download image: {error}').format( error='<font color="red">%s</font>' % str(exc))) self._btn.setText(_('Bummer')) self._state = self.STATE_ERROR return src = downloader.filename() dst = os.path.join( Meta.dataPath('images'), self._getValue(self._manifest, self._path + ('latest', 'name'))) if os.path.exists(dst): os.remove(dst) os.rename(src, dst) self._getValue(self._manifest, self._path)['current'] = self._getValue( self._manifest, self._path).pop('latest') Meta.updateManifest(self._manifest) self.accept()
#!/usr/bin/env python3 import os import sys import shutil from PyQt5 import QtCore sys.path.insert( 0, os.path.normpath(os.path.join(os.path.dirname(__file__), '..', 'src'))) from dsrlib.ui.main import Application from dsrlib.meta import Meta if __name__ == '__main__': app = Application() settings = QtCore.QSettings() settings.clear() settings.sync() shutil.rmtree(Meta.dataPath())
def save(self): filename = os.path.join(Meta.dataPath(), 'workspace.json') writer = JSONWriter() with codecs.getwriter('utf-8')(open(filename, 'wb')) as fileobj: writer.write(fileobj, self)
def load(self): filename = os.path.join(Meta.dataPath(), 'workspace.json') if os.path.exists(filename): reader = JSONReader() with codecs.getreader('utf-8')(open(filename, 'rb')) as fileobj: reader.read(fileobj, self)