def show_log(session): """Show the current execution log""" d = session['dialog'] log = session['image'].out[0].stderr log.file.flush() while 1: code = d.textbox(log.name, title="Log", width=70, height=40, extra_button=1, extra_label="Save", ok_label="Close") if code == d.EXTRA: while 1: path = select_file(d, title="Save log as...") if path is None: break if os.path.isdir(path): continue if copy_file(d, log.name, path): break else: return
def show_info(session): """Show registration info""" assert 'current_cloud' in session assert session['current_cloud'] in session['clouds'] cloud = session['clouds']['current_cloud'] assert 'registered' in cloud info = json.dumps(cloud['registered'], ensure_ascii=False, indent=4) d = session['dialog'] while 1: code = d.scrollbox(info, width=WIDTH, title="Registration info", extra_label="Save", extra_button=1, ok_label="Close") if code == d.EXTRA: path = select_file(d, title="Save registration information as...") if path is None: break if os.path.isdir(path): continue if os.path.exists(path): if d.yesno("File: `%s' already exists. Do you want to " "overwrite it?" % path, width=WIDTH, defaultno=1) != d.OK: continue with open(path, 'w') as f: f.write(info + '\n') d.msgbox("File `%s was successfully written." % path, width=SMALL_WIDTH) break else: return
def show_info(session): """Show registration info""" assert 'current_cloud' in session assert session['current_cloud'] in session['clouds'] cloud = session['clouds']['current_cloud'] assert 'registered' in cloud info = json.dumps(cloud['registered'], ensure_ascii=False, indent=4) d = session['dialog'] while 1: code = d.scrollbox(info, width=WIDTH, title="Registration info", extra_label="Save", extra_button=1, ok_label="Close") if code == d.EXTRA: path = select_file(d, title="Save registration information as...") if path is None: break if os.path.isdir(path): continue if os.path.exists(path): if d.yesno("File: `%s' already exists. Do you want to " "overwrite it?" % path, width=WIDTH, defaultno=1 ) != d.OK: continue with open(path, 'w') as f: f.write(info + '\n') d.msgbox("File `%s was successfully written." % path, width=SMALL_WIDTH) break else: return
def show_log(session): """Show the current execution log""" d = session['dialog'] log = session['image'].out[0].stderr log.file.flush() while 1: code = d.textbox(log.name, title="Log", width=70, height=40, extra_button=1, extra_label="Save", ok_label="Close") if code == d.EXTRA: while 1: path = select_file(d, title="Save log as...") if path is None: break if os.path.isdir(path): continue if copy_file(d, log.name, path): break else: return
def dialog_main(media, **kwargs): """Main function for the dialog-based version of the program""" tmpdir = kwargs['tmpdir'] if 'tmpdir' in kwargs else None snapshot = kwargs['snapshot'] if 'snapshot' in kwargs else True logfile = kwargs['logfile'] if 'logfile' in kwargs else None syslog = kwargs['syslog'] if 'syslog' in kwargs else False # In openSUSE dialog is buggy under xterm if os.environ['TERM'] == 'xterm': os.environ['TERM'] = 'linux' d = dialog.Dialog(dialog="dialog") # Add extra button in dialog library if missing if 'extra_button' not in dialog._common_args_syntax: dialog._common_args_syntax["extra_button"] = \ lambda enable: dialog._simple_option("--extra-button", enable) if 'extra_label' not in dialog._common_args_syntax: dialog._common_args_syntax["extra_label"] = \ lambda string: ("--extra-label", string) # Allow yes-no label overwriting if missing if 'yes_label' not in dialog._common_args_syntax: dialog._common_args_syntax["yes_label"] = \ lambda string: ("--yes-label", string) if 'no_label' not in dialog._common_args_syntax: dialog._common_args_syntax["no_label"] = \ lambda string: ("--no-label", string) # Add exit label overwriting if missing if 'exit_label' not in dialog._common_args_syntax: dialog._common_args_syntax["exit_label"] = \ lambda string: ("--exit-label", string) # Monkey-patch pythondialog to include support for form dialog boxes if not hasattr(d, 'form'): d.form = types.MethodType(_dialog_form, d) # Add sort dialog constants if missing if not hasattr(d, 'OK'): d.OK = d.DIALOG_OK if not hasattr(d, 'CANCEL'): d.CANCEL = d.DIALOG_CANCEL if not hasattr(d, 'ESC'): d.ESC = d.DIALOG_ESC if not hasattr(d, 'EXTRA'): d.EXTRA = d.DIALOG_EXTRA if not hasattr(d, 'HELP'): d.HELP = d.DIALOG_HELP d.setBackgroundTitle('snf-image-creator') # Pick input media while True: media = select_file(d, init=media, ftype="br", bundle_host=True, title="Please select an input media.") if media is None: if confirm_exit( d, "You canceled the media selection dialog box."): return 0 continue break tmplog = None if logfile else tempfile.NamedTemporaryFile(prefix='fatal-', delete=False) logs = [] try: stream = logfile if logfile else tmplog logs.append(SimpleOutput(colored=False, stderr=stream, stdout=stream, timestamp=True)) if syslog: logs.append(SyslogOutput()) while 1: try: out = CompositeOutput(logs) out.info("Starting %s v%s ..." % (PROGNAME, version)) ret = create_image(d, media, out, tmpdir, snapshot) break except Reset: for log in logs: log.info("Resetting everything ...") except FatalError as error: for log in logs: log.error(str(error)) msg = 'A fatal error occured. See %s for a full log.' % log.stderr.name d.infobox(msg, width=WIDTH, title="Fatal Error") return 1 else: if tmplog: os.unlink(tmplog.name) finally: if tmplog: tmplog.close() return ret
def dialog_main(media, **kwargs): """Main function for the dialog-based version of the program""" tmpdir = kwargs['tmpdir'] if 'tmpdir' in kwargs else None snapshot = kwargs['snapshot'] if 'snapshot' in kwargs else True logfile = kwargs['logfile'] if 'logfile' in kwargs else None syslog = kwargs['syslog'] if 'syslog' in kwargs else False # In openSUSE dialog is buggy under xterm if os.environ['TERM'] == 'xterm': os.environ['TERM'] = 'linux' d = dialog.Dialog(dialog="dialog") # Add extra button in dialog library if missing if 'extra_button' not in dialog._common_args_syntax: dialog._common_args_syntax["extra_button"] = \ lambda enable: dialog._simple_option("--extra-button", enable) if 'extra_label' not in dialog._common_args_syntax: dialog._common_args_syntax["extra_label"] = \ lambda string: ("--extra-label", string) # Allow yes-no label overwriting if missing if 'yes_label' not in dialog._common_args_syntax: dialog._common_args_syntax["yes_label"] = \ lambda string: ("--yes-label", string) if 'no_label' not in dialog._common_args_syntax: dialog._common_args_syntax["no_label"] = \ lambda string: ("--no-label", string) # Add exit label overwriting if missing if 'exit_label' not in dialog._common_args_syntax: dialog._common_args_syntax["exit_label"] = \ lambda string: ("--exit-label", string) # Monkey-patch pythondialog to include support for form dialog boxes if not hasattr(d, 'form'): d.form = types.MethodType(_dialog_form, d) # Add sort dialog constants if missing if not hasattr(d, 'OK'): d.OK = d.DIALOG_OK if not hasattr(d, 'CANCEL'): d.CANCEL = d.DIALOG_CANCEL if not hasattr(d, 'ESC'): d.ESC = d.DIALOG_ESC if not hasattr(d, 'EXTRA'): d.EXTRA = d.DIALOG_EXTRA if not hasattr(d, 'HELP'): d.HELP = d.DIALOG_HELP d.setBackgroundTitle('snf-image-creator') # Pick input media while True: media = select_file(d, init=media, ftype="br", bundle_host=True, title="Please select an input media.") if media is None: if confirm_exit(d, "You canceled the media selection dialog box."): return 0 continue break tmplog = None if logfile else tempfile.NamedTemporaryFile(prefix='fatal-', delete=False) logs = [] try: stream = logfile if logfile else tmplog logs.append( SimpleOutput(colored=False, stderr=stream, stdout=stream, timestamp=True)) if syslog: logs.append(SyslogOutput()) while 1: try: out = CompositeOutput(logs) out.info("Starting %s v%s ..." % (PROGNAME, version)) ret = create_image(d, media, out, tmpdir, snapshot) break except Reset: for log in logs: log.info("Resetting everything ...") except FatalError as error: for log in logs: log.error(str(error)) msg = 'A fatal error occured. See %s for a full log.' % log.stderr.name d.infobox(msg, width=WIDTH, title="Fatal Error") return 1 else: if tmplog: os.unlink(tmplog.name) finally: if tmplog: tmplog.close() return ret