def _remove_script(script_name): path = get_scripts_folder().joinpath(script_name) _check_script_exists(path) try: io.start('Removing script %s' % highlight(script_name)) path.unlink() except OSError as e: raise McmdError('Error removing script: %s' % str(e))
def _read_script(script_name): path = get_scripts_folder().joinpath(script_name) _check_script_exists(path) try: with path.open() as f: for line in f.readlines(): log.info(line.strip()) except OSError as e: raise McmdError('Error reading script: %s' % str(e))
def _input_script_name(): file_name = '' while not file_name: name = io.input_('Supply the name of the script:') if get_scripts_folder().joinpath(name).exists(): overwrite = confirm('%s already exists. Overwrite?' % name) if overwrite: file_name = name else: file_name = name return file_name
def _create_script(args): lines = history.read(args.number, args.show_fails) if len(lines) == 0: log.info('History is empty.') return options = [line[1] for line in lines] commands = io.checkbox('Pick the lines that will form the script:', options) file_name = _input_script_name() try: script_file = open(get_scripts_folder().joinpath(file_name), 'w') for command in commands: script_file.write(command + '\n') except OSError as e: raise McmdError("Error writing to script: %s" % str(e))
def _list_scripts(): for path in get_scripts_folder().iterdir(): if not path.name.startswith('.'): log.info(path.name)