-def confirm_exit(d, msg=''):
- return not d.yesno("%s Do you want to exit?" % msg, width=YESNO_WIDTH)
-
-
-def confirm_reset(d):
- return not d.yesno(
- "Are you sure you want to reset everything?",
- width=YESNO_WIDTH)
-
-def extract_image(session):
- d = session['dialog']
- dir = os.getcwd()
- while 1:
- if dir and dir[-1] != os.sep:
- dir = dir + os.sep
-
- (code, path) = d.fselect(dir, 10, 50, title="Save image as...")
- if code in (d.DIALOG_CANCEL, d.DIALOG_ESC):
- return False
-
- if os.path.isdir(path):
- dir=path
- continue
-
- if os.path.isdir("%s.meta" % path):
- d.msgbox("Can't overwrite directory `%s.meta'" % path,
- width=MSGBOX_WIDTH)
- continue
-
- if os.path.isdir("%s.md5sum" % path):
- d.msgbox("Can't overwrite directory `%s.md5sum'" % path,
- width=MSGBOX_WIDTH)
- continue
-
- basedir = os.path.dirname(path)
- name = os.path.basename(path)
- if not os.path.exists(basedir):
- d.msgbox("Directory `%s' does not exist" % basedir,
- width=MSGBOX_WIDTH)
- continue
-
- dir = basedir
- if len(name) == 0:
- continue
-
- files = ["%s%s" % (path, ext) for ext in ('', '.meta', '.md5sum')]
- overwrite = filter(os.path.exists, files)
-
- if len(overwrite) > 0:
- if d.yesno("The following file(s) exist:\n"
- "%s\nDo you want to overwrite them?" %
- "\n".join(overwrite), width=YESNO_WIDTH):
- continue
-
- out = GaugeOutput(d, "Image Extraction", "Extracting image...")
- try:
- dev = session['device']
- if "checksum" not in session:
- size = dev.meta['SIZE']
- md5 = MD5(out)
- session['checksum'] = md5.compute(session['snapshot'], size)
-
- # Extract image file
- dev.out = out
- dev.dump(path)
-
- # Extract metadata file
- out.output("Extracting metadata file...")
- metastring = '\n'.join(
- ['%s=%s' % (k, v) for (k, v) in session['metadata'].items()])
- metastring += '\n'
- with open('%s.meta' % path, 'w') as f:
- f.write(metastring)
- out.success('done')
-
- # Extract md5sum file
- out.output("Extracting md5sum file...")
- md5str = "%s %s\n" % (session['checksum'], name)
- with open('%s.md5sum' % path, 'w') as f:
- f.write(md5str)
- out.success("done")
-
- finally:
- out.cleanup()
- d.msgbox("Image file `%s' was successfully extracted!" % path,
- width=MSGBOX_WIDTH)
- break
-
- return True
-
-
-def upload_image(session):
- d = session["dialog"]
- size = session['device'].meta['SIZE']
-
- if "account" not in session:
- d.msgbox("You need to provide your ~okeanos login username before you "
- "can upload images to pithos+", width=MSGBOX_WIDTH)
- return False
-
- if "token" not in session:
- d.msgbox("You need to provide your ~okeanos account authentication "
- "token before you can upload images to pithos+",
- width=MSGBOX_WIDTH)
- return False
-
- while 1:
- init=session["upload"] if "upload" in session else ''
- (code, answer) = d.inputbox("Please provide a filename:", init=init,
- width=INPUTBOX_WIDTH)
-
- if code in (d.DIALOG_CANCEL, d.DIALOG_ESC):
- return False
-
- filename = answer.strip()
- if len(filename) == 0:
- d.msgbox("Filename cannot be empty", width=MSGBOX_WIDTH)
- continue
-
- break
-
- out = GaugeOutput(d, "Image Upload", "Uploading...")
- if 'checksum' not in session:
- md5 = MD5(out)
- session['checksum'] = md5.compute(session['snapshot'], size)