def run(self): """ Execute a set of operations to perform the Task. """ msg = """Remove most traces of pakit. You are warned! Will delete ... - all links from the link directory to pakit's programs. - all programs pakit built, including the source trees. - all downloaded recipes. - all logs and configs EXCEPT the pakit.yml file. OK? y/n """ if user_input(msg).strip().lower()[0] != 'y': USER.info('Aborted.') return USER.info('Removing all links made by pakit.') config = pakit.conf.CONFIG unlink_man_pages(config.path_to('link')) walk_and_unlink_all(config.path_to('link'), config.path_to('prefix')) uris_file = os.path.join(config.path_to('recipes'), 'uris.yml') ruri_db = pakit.conf.RecipeURIDB(uris_file) to_remove = [config.path_to('prefix'), config.path_to('source'), uris_file] to_remove += [ruri_db[uri]['path'] for uri in ruri_db if ruri_db[uri]['is_vcs']] to_remove += glob.glob(config.get('pakit.log.file') + '*') for path in to_remove: try: USER.info('Deleting: %s', path) if os.path.isdir(path): shutil.rmtree(path) else: os.remove(path) except OSError: logging.error('Could not delete path: %s', path)
def test_user_input(mock_input): mock_input.return_value = "Bye" assert user_input("Hello") == "Bye"
def test_user_input(mock_input): mock_input.return_value = 'Bye' assert user_input('Hello') == 'Bye'