本文整理汇总了Python中editor.edit方法的典型用法代码示例。如果您正苦于以下问题:Python editor.edit方法的具体用法?Python editor.edit怎么用?Python editor.edit使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类editor
的用法示例。
在下文中一共展示了editor.edit方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: edit
# 需要导入模块: import editor [as 别名]
# 或者: from editor import edit [as 别名]
def edit(path):
"""Given a source path, run the EDITOR for it"""
import editor
try:
editor.edit(path)
except Exception as exc:
raise CommandError('Error executing editor (%s)' % (exc,))
示例2: edit
# 需要导入模块: import editor [as 别名]
# 或者: from editor import edit [as 别名]
def edit(path):
"""Given a source path, run the EDITOR for it"""
import editor
try:
editor.edit(path)
except Exception as exc:
raise CommandError("Error executing editor (%s)" % (exc,))
示例3: cli_edit_state
# 需要导入模块: import editor [as 别名]
# 或者: from editor import edit [as 别名]
def cli_edit_state(fire: object, args: list):
"""Edit the current state
Args:
args (object): Cli args
"""
current_index = fire._current_index
hold = editor.edit(contents=str(fire.states[current_index])).decode()
args[current_index] = hold
示例4: exception_handler
# 需要导入模块: import editor [as 别名]
# 或者: from editor import edit [as 别名]
def exception_handler(exc_type, exc_value, exc_traceback):
if issubclass(exc_type, KeyboardInterrupt):
sys.__excepthook__(exc_type, exc_value, exc_traceback)
return
logger.error("Uncaught exception", exc_info=(exc_type, exc_value, exc_traceback))
if crash_log:
text = editor.edit(filename=os.path.join(log_path(), "log.txt"))
# logger = logging.getLogger(__name__)
# handler = logging.StreamHandler(stream=sys.stdout)
# logger.addHandler(handler)
示例5: save_savegame
# 需要导入模块: import editor [as 别名]
# 或者: from editor import edit [as 别名]
def save_savegame():
print("Going to save:")
restores = [int(key[7:]) for key in request.form.keys() if "restore" in key]
if restores:
save_game = session["backup"]
for i in range(restores[0]):
save_game = save_game["backup"]
save_game = copy.deepcopy(save_game)
print("restoring backup")
message = "Revert to backup \"" + format_backup_message(save_game) + "\""
else:
save_game = json.loads(request.form['savegame'])
message = "before " + request.form.get("message")
print(repr(save_game))
create_backup(message)
session['saved'] = str(session.get('saved', "")) + "edit"
session['user_object'] = save_game['user_object']
session['quests'] = save_game['quests']
session['battle'] = save_game['battle']
session['fleets'] = save_game['fleets']
session['population'] = save_game['population']
session['save_version'] = save_game['save_version']
response = make_response(redirect('/home.html'))
return response
# return ('', 400)
示例6: server_error_page
# 需要导入模块: import editor [as 别名]
# 或者: from editor import edit [as 别名]
def server_error_page(error):
if crash_log:
text = editor.edit(filename=os.path.join(log_path(), "log.txt"))
return 'It went wrong'
示例7: run
# 需要导入模块: import editor [as 别名]
# 或者: from editor import edit [as 别名]
def run(self, args, **kwargs):
schema = self.app.client.managers['ConfigSchema'].get_by_ref_or_id(args.name, **kwargs)
if not schema:
msg = '%s "%s" doesn\'t exist or doesn\'t have a config schema defined.'
raise resource.ResourceNotFoundError(msg % (self.resource.get_display_name(),
args.name))
config = interactive.InteractiveForm(schema.attributes).initiate_dialog()
message = '---\nDo you want to preview the config in an editor before saving?'
description = 'Secrets will be shown in plain text.'
preview_dialog = interactive.Question(message, {'default': 'y',
'description': description})
if preview_dialog.read() == 'y':
try:
contents = yaml.safe_dump(config, indent=4, default_flow_style=False)
modified = editor.edit(contents=contents)
config = yaml.safe_load(modified)
except editor.EditorError as e:
print(six.text_type(e))
message = '---\nDo you want me to save it?'
save_dialog = interactive.Question(message, {'default': 'y'})
if save_dialog.read() == 'n':
raise OperationFailureException('Interrupted')
config_item = Config(pack=args.name, values=config)
result = self.app.client.managers['Config'].update(config_item, **kwargs)
return result
示例8: process_input
# 需要导入模块: import editor [as 别名]
# 或者: from editor import edit [as 别名]
def process_input(self, pressed):
if pressed == key.CTRL_C:
raise KeyboardInterrupt()
if pressed in (key.CR, key.LF, key.ENTER):
data = editor.edit(contents=self.question.default or '')
raise errors.EndOfInput(data.decode('utf-8'))
raise errors.ValidationError('You have pressed unknown key! '
'Press <enter> to open editor or '
'CTRL+C to exit.')