def test_editor_editor_run_failed(monkeypatch): def mock_run(*args, **kwargs): raise exception.CommandNotFound('Foo') monkeypatch.setattr(helpers, 'run', mock_run) def mock_env(var): return 'foo_editor' monkeypatch.setattr(helpers.os.environ, 'get', mock_env) with pytest.raises(exception.CommandNotFound) as excinfo: helpers.edit('/tmp/foo') assert excinfo.match(r'.*\(foo_editor\).* Please set \$EDITOR .*')
def ensure_update_notes(upfile_path): update = None ok = False while not ok: update = rdoupdate.actions.check_file(upfile_path) if (not update.notes or update.notes == FILLME or update.notes == rdoupdate.core.FILL_THIS): fmt = ("\n{t.important}Please describe this update " "in the 'notes' field.\n\n" "Press <Enter> to edit update file: {upf}{t.normal}\n") raw_input(fmt.format(t=log.term, upf=upfile_path)) helpers.edit(upfile_path) else: ok = True return update
def new_update(self, update, check_availability=True): update_id, upfile_path = self._get_new_update_id() updir_path, _ = os.path.split(upfile_path) helpers.ensure_dir(updir_path) upfile = file(upfile_path, 'wt') upfile.write(update.update_file()) upfile.close() helpers.edit(upfile_path) cmd.run('/bin/sed', '-i', '-e', '/^#/d', upfile_path, shell=False) parsed_update = None while not parsed_update: try: parsed_update = rdoupdate.actions.check_file(upfile_path) except Exception as ex: print("\n{t.important}Error parsing update file: {t.normal}" "{t.warn}{ex}{t.normal}".format(t=log.term, ex=ex)) again = raw_input("Do you want to edit? [Yn] ") if again and again.lower() != 'y': os.remove(upfile_path) raise exception.UserAbort() helpers.edit(upfile_path) continue if check_availability: log.info("Checking availability of updated builds...") bad_builds = [x for x in parsed_update.builds if not x.is_available(verbose=True)] if bad_builds: builds_str = "\n".join(map(str, bad_builds)) print("\n{t.important}Builds below doesn't seem to be " "available:{t.normal}\n{builds}\n".format( t=log.term, builds=builds_str)) print("Options:") print(" e: Edit update") print(" u: Update anyway") print(" a: Abort") resp = raw_input("What do you want to do? [euA] ").lower() if resp == 'e': parsed_update = None helpers.edit(upfile_path) elif resp == 'u': pass else: raise exception.UserAbort() print("\nUpdate:\n%s\n" % parsed_update) self.submit_update_file(update_id, msg=str(parsed_update))