def test_ask_yes_no() -> None: """ Test that you can answer with several types of common answers """ with mock.patch("builtins.input") as m: m.side_effect = ["y", "yes", "Yes", "n", "no", "No"] expected_res = [True, True, True, False, False, False] for res in expected_res: actual = cli_ui.ask_yes_no("coffee?") assert actual == res
def do_reset_hard(self, processor): 'Reset failed and done tasks for one processor.' if cli_ui.ask_yes_no( "Are you sure you want to delete all computed data?", default=False): processor = cli_ui.ask_choice("Pick a processor to reset", choices=self._sis.processors) self._sis.reset([processor], reset_hard=True) print("done.")
def test_ask_colored_message() -> None: with mock.patch("builtins.input") as m: m.side_effect = ["y"] res = cli_ui.ask_yes_no("Deploy to", cli_ui.bold, "prod", cli_ui.reset, "?", default=False) assert res
def add_passwords(): website = cli_ui.ask_string("Please enter the website\'s name") username = cli_ui.ask_string("Please enter your username") choice1 = cli_ui.ask_yes_no( "Would you like to generate a new password?", default=False) if choice1 == True: length = int(input("How many characters do you want in your password? ")) type1 = cli_ui.ask_yes_no("Do you want Upper Case Characters in your password?") type2 = cli_ui.ask_yes_no("Do you want Lower Case Characters in your password?") type3 = cli_ui.ask_yes_no("Do you want Special Characters in your password?") type4 = cli_ui.ask_yes_no("Do you want Numbers in your password?") password = helper.password_generator_main(type1, type2, type3, type4, length) choice = cli_ui.ask_yes_no( "Would you like to add this password", default=False) if choice == True: user_info.add_password(website, username, password) print("The password has been added.") else: helper.clear_screen() return True else: password1 = cli_ui.ask_string("Please enter your password") user_info.add_password(website, username, password1) print("The password has been added.") helper.clear_screen() return True
def load_or_ask(self): if self.exists(): try: self.load() self.print() ask = cli.ask_yes_no("Would you like to provide new settings?") if not ask: return except ValueError: print("There was an error loading the settings.") os.remove(self.settings_path) self.ask()
def print_countdown_when_ready(seconds=3): '''Waits until the user is ready and prints a countdown afterwards. Parameters ---------- seconds : int Length of the countdown (the default is 3). ''' user_is_ready = False while not user_is_ready: user_is_ready = cli_ui.ask_yes_no('Bereit?', default=True) for i in range(seconds)[::-1]: time.sleep(1) print(i + 1) print_circle(cli_ui.yellow)
def bump(options: BumpOptions) -> None: working_path = options.working_path new_version = options.new_version interactive = options.interactive only_patch = options.only_patch dry_run = options.dry_run config = parse_config(options.working_path) # fmt: off ui.info_1( "Bumping from", ui.bold, config.current_version, ui.reset, "to", ui.bold, new_version, ) # fmt: on git_bumper = GitBumper(working_path) git_bumper.set_config(config) git_state_error = None try: git_bumper.check_dirty() # Avoid data loss if not only_patch: git_bumper.check_branch_state(new_version) except tbump.git.GitError as e: if dry_run: git_state_error = e else: raise file_bumper = FileBumper(working_path) file_bumper.set_config(config) hooks_runner = HooksRunner(working_path, config.current_version) if not only_patch: for hook in config.hooks: hooks_runner.add_hook(hook) executor = Executor(new_version, file_bumper) if not only_patch: executor.add_git_and_hook_actions(new_version, git_bumper, hooks_runner) if interactive: executor.print_self(dry_run=True) if not dry_run: proceed = ui.ask_yes_no("Looking good?", default=False) if not proceed: raise Cancelled() if dry_run: if git_state_error: ui.error("Git repository state is invalid") git_state_error.print_error() sys.exit(1) else: return executor.print_self(dry_run=False) executor.run() if config.github_url: tag_name = git_bumper.get_tag_name(new_version) suggest_creating_github_release(config.github_url, tag_name)
def edit(): today = date.today() response = user_info.edit_account_choice() choices = ['Password', 'Username', 'Username and Password'] a = cli_ui.ask_choice("What would you like to edit?", choices=choices) if a == 'Password': new_password = cli_ui.ask_string("Enter new Password") user_info.edit(f'password = "******", Date_Modified = "{today}"', response[0], response[1]) helper.clear_screen() print("Records have been updated.") return True elif a == 'Username': new_username = cli_ui.ask_string("Enter new Username") user_info.edit(f'username = "******", Date_Modified = "{today}"', response[0], response[1) helper.clear_screen() print("Records have been updated.") return True elif a == 'Username and Password': new_password = cli_ui.ask_string("Enter new Password") new_username = cli_ui.ask_string("Enter new Username") user_info.edit( f'username = "******", password = "******", Date_Modified = "{today}"', response[0], response[1]) helper.clear_screen() print("Records have been updated.") return True def delete(): user_info.delete() helper.clear_screen() print("Account records have been deleted.") return True choices = ['Login', 'Sign Up', 'Exit'] flag = False while not flag: c = cli_ui.ask_choice("Would you like to", choices=choices) if c == "Login": flag = login() elif c == "Sign Up": flag = sign_up() elif c == "Exit": sys.exit(0) logged_in_choices = ['View Stored Passwords', 'Log Out', 'Add New Passwords', 'Edit Passwords', 'Delete Passwords', 'Password Generator'] achoices = ['Filter by Website', 'Filter by Username', 'View All'] while flag: c = cli_ui.ask_choice("Would you like to", choices=logged_in_choices) if c == 'View Stored Passwords': a = cli_ui.ask_choice("Would you like to", choices=achoices) if a == 'Filter by Website': info = filter_website() helper.clear_screen() print(info) elif a == 'Filter by Username': info = filter_username() helper.clear_screen() print(info) elif a == 'View All': info = user_info.get_all_password() helper.clear_screen() print(info) elif c == 'Log Out': helper.clear_screen() print("Logged Out.") sys.exit(0) elif c == 'Add New Passwords': helper.clear_screen() flag = add_passwords() elif c == 'Edit Passwords': helper.clear_screen() flag = edit() elif c == 'Delete Passwords': helper.clear_screen() flag = delete() elif c == 'Password Generator': helper.clear_screen() length = int(input("How many characters do you want in your password? ")) type1 = cli_ui.ask_yes_no("Do you want Upper Case Characters in your password?") type2 = cli_ui.ask_yes_no("Do you want Lower Case Characters in your password?") type3 = cli_ui.ask_yes_no("Do you want Special Characters in your password?") type4 = cli_ui.ask_yes_no("Do you want Numbers in your password?") password = helper.password_generator_main(type1, type2, type3, type4, length) if password: choice = cli_ui.ask_yes_no( "Would you like to add this password", default=False) if choice == True: website = cli_ui.ask_string("Please enter the website\'s name") username = cli_ui.ask_string("Please enter your username") user_info.add_password(website, username, password) helper.clear_screen() print("The password has been added.") elif choice == False: helper.clear_screen() flag = True
def test_ask_yes_no_wrong_input() -> None: """ Test that we keep asking when answer does not make sense """ with mock.patch("builtins.input") as m: m.side_effect = ["coffee!", "n"] assert cli_ui.ask_yes_no("tea?") is False assert m.call_count == 2
def test_ask_yes_no_default() -> None: """ Test that just pressing enter returns the default value """ with mock.patch("builtins.input") as m: m.side_effect = ["", ""] assert cli_ui.ask_yes_no("coffee?", default=True) is True assert cli_ui.ask_yes_no("coffee?", default=False) is False
async def upload(self, session, meta): from unidecode import unidecode await self.edit_torrent(meta) cat_id = await self.get_cat_id(meta) subs = self.get_subtitles(meta) pronfo = await self.edit_desc(meta) if meta.get('is_disc', '') == 'BDMV': mi_file = None # bd_file = f"{meta['base_dir']}/tmp/{meta['uuid']}/BD_SUMMARY_00.txt", 'r', encoding='utf-8' else: mi_file = os.path.abspath( f"{meta['base_dir']}/tmp/{meta['uuid']}/MEDIAINFO.txt") with open(mi_file, 'r') as f: mi_file = f.read() f.close() # bd_file = None with open( f"{meta['base_dir']}/tmp/{meta['uuid']}/[THR]DESCRIPTION.txt", 'r') as f: desc = f.read() f.close() torrent_path = os.path.abspath( f"{meta['base_dir']}/tmp/{meta['uuid']}/[THR]{meta['clean_name']}.torrent" ) with open(torrent_path, 'rb') as f: tfile = f.read() f.close() thr_name = unidecode(meta['name'].replace('DD+', 'DDP')) #Upload Form url = 'https://www.torrenthr.org/takeupload.php' files = {'tfile': (f"{thr_name}.torrent", tfile)} payload = { 'name': thr_name, 'descr': desc, 'type': cat_id, 'url': f"https://www.imdb.com/title/tt{meta.get('imdb_id').replace('tt', '')}/", 'tube': meta.get('youtube', '') } headers = { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:97.0) Gecko/20100101 Firefox/97.0' } #If pronfo fails, put mediainfo into THR parser if pronfo == False and meta.get('is_disc', '') != 'BDMV': files['nfo'] = ("MEDIAINFO.txt", mi_file) if subs != []: payload['subs[]'] = tuple(subs) if meta['debug'] == False: thr_upload_prompt = True else: thr_upload_prompt = cli_ui.ask_yes_no("send to takeupload.php?", default=False) if thr_upload_prompt == True: response = session.post(url=url, files=files, data=payload, headers=headers) try: if meta['debug']: pprint(response.text) if response.url.endswith('uploaded=1'): cprint(f'Successfully Uploaded at: {response.url}', 'grey', 'on_green') #Check if actually uploaded except: if meta['debug']: pprint(response.text) cprint("It may have uploaded, go check") # cprint(f"Request Data:", 'cyan') # pprint(data) return else: cprint(f"Request Data:", 'cyan') pprint(files) pprint(payload)
colorId = settings.lecture_color['id'] if e['is_exercise']: colorId = settings.exercise_color['id'] event = { 'summary': f"[{course_abbr}] {course_name} ({e['type']})", 'location': room, 'description': f'<a href="{course_url}">Stránka předmětu</a>', 'colorId': colorId, 'source': { 'title': "FIT VUTBR - " + course_name, 'url': course_url, }, 'start': { 'dateTime': course_date_from.isoformat(), 'timeZone': 'Europe/Prague', }, 'end': { 'dateTime': course_date_to.isoformat(), 'timeZone': 'Europe/Prague', }, 'recurrence': ['RRULE:FREQ=WEEKLY;COUNT=13'], } api_event = api.calendar_service().events().insert( calendarId=settings.calendar['id'], body=event).execute() print(f"Created event {api_event['htmlLink']}") repeat = cli.ask_yes_no("Continue with more courses?", default=True)
def password_generator_main(type1, type2, type3, type4, length): condition = True while condition: if type1 == True: if type2 == True: if type3 == True: if type4 == True: sample_space = string.ascii_letters + string.punctuation + string.digits password = ''.join((random.choice(sample_space) for i in range(length))) clear_screen() printdashes() print("Your password is: ", password) printdashes() c = cli_ui.ask_yes_no("Do you like this password? ") if c == True: clipboard.copy(password) clear_screen() print( "The password has been copied to your clipboard." ) condition = False return password elif c == False: condition = True else: sample_space = string.ascii_letters + string.punctuation password = ''.join((random.choice(sample_space) for i in range(length))) clear_screen() printdashes() print("Your password is: ", password) printdashes() c = cli_ui.ask_yes_no("Do you like this password? ") if c == True: clipboard.copy(password) clear_screen() print( "The password has been copied to your clipboard." ) condition = False return password elif c == False: condition = True else: if type4 == True: sample_space = string.ascii_letters + string.digits password = ''.join((random.choice(sample_space) for i in range(length))) clear_screen() printdashes() print("Your password is: ", password) printdashes() c = cli_ui.ask_yes_no("Do you like this password? ") if c == True: clipboard.copy(password) clear_screen() print( "The password has been copied to your clipboard." ) condition = False return password else: condition = True else: sample_space = string.ascii_letters password = ''.join((random.choice(sample_space) for i in range(length))) clear_screen() printdashes() print("Your password is: ", password) printdashes() c = cli_ui.ask_yes_no("Do you like this password? ") if c == True: clipboard.copy(password) clear_screen() print( "The password has been copied to your clipboard." ) condition = False return password else: condition = True else: if type3 == True: if type4 == True: sample_space = string.ascii_uppercase + string.punctuation + string.digits password = ''.join((random.choice(sample_space) for i in range(length))) clear_screen() printdashes() print("Your password is: ", password) printdashes() c = cli_ui.ask_yes_no("Do you like this password? ") if c == True: clipboard.copy(password) clear_screen() print( "The password has been copied to your clipboard." ) condition = False return password else: condition = True else: sample_space = string.ascii_uppercase + string.punctuation password = ''.join((random.choice(sample_space) for i in range(length))) clear_screen() printdashes() print("Your password is: ", password) printdashes() c = cli_ui.ask_yes_no("Do you like this password? ") if c == True: clipboard.copy(password) clear_screen() print( "The password has been copied to your clipboard." ) condition = False return password else: condition = True else: if type4 == True: sample_space = string.ascii_uppercase + string.digits password = ''.join((random.choice(sample_space) for i in range(length))) clear_screen() printdashes() print("Your password is: ", password) printdashes() c = cli_ui.ask_yes_no("Do you like this password? ") if c == True: clipboard.copy(password) clear_screen() print( "The password has been copied to your clipboard." ) condition = False return password else: condition = True else: sample_space = string.ascii_uppercase password = ''.join((random.choice(sample_space) for i in range(length))) clear_screen() printdashes() print("Your password is: ", password) printdashes() c = cli_ui.ask_yes_no("Do you like this password? ") if c == True: clipboard.copy(password) clear_screen() print( "The password has been copied to your clipboard." ) condition = False return password else: condition = True else: if type2 == True: if type3 == True: if type4 == True: sample_space = string.ascii_lowercase + string.punctuation + string.digits password = ''.join((random.choice(sample_space) for i in range(length))) clear_screen() printdashes() print("Your password is: ", password) printdashes() c = cli_ui.ask_yes_no("Do you like this password? ") if c == True: clipboard.copy(password) clear_screen() print( "The password has been copied to your clipboard." ) condition = False return password else: condition = True else: sample_space = string.ascii_lowercase + string.punctuation password = ''.join((random.choice(sample_space) for i in range(length))) clear_screen() printdashes() print("Your password is: ", password) printdashes() c = cli_ui.ask_yes_no("Do you like this password? ") if c == True: clipboard.copy(password) clear_screen() print( "The password has been copied to your clipboard." ) condition = False return password else: condition = True else: if type4 == True: sample_space = string.ascii_lowercase + string.digits password = ''.join((random.choice(sample_space) for i in range(length))) clear_screen() printdashes() print("Your password is: ", password) printdashes() c = cli_ui.ask_yes_no("Do you like this password? ") if c == True: clipboard.copy(password) clear_screen() print( "The password has been copied to your clipboard." ) condition = False return password else: condition = True else: sample_space = string.ascii_lowercase password = ''.join((random.choice(sample_space) for i in range(length))) clear_screen() printdashes() print("Your password is: ", password) printdashes() c = cli_ui.ask_yes_no("Do you like this password? ") if c == True: clipboard.copy(password) clear_screen() print( "The password has been copied to your clipboard." ) condition = False return password else: condition = True else: if type3 == True: if type4 == True: sample_space = string.punctuation + string.digits password = ''.join((random.choice(sample_space) for i in range(length))) clear_screen() printdashes() print("Your password is: ", password) printdashes() c = cli_ui.ask_yes_no("Do you like this password? ") if c == True: clipboard.copy(password) clear_screen() print( "The password has been copied to your clipboard." ) condition = False return password else: condition = True else: sample_space = string.punctuation password = ''.join((random.choice(sample_space) for i in range(length))) clear_screen() printdashes() print("Your password is: ", password) printdashes() c = cli_ui.ask_yes_no("Do you like this password? ") if c == True: clipboard.copy(password) clear_screen() print( "The password has been copied to your clipboard." ) condition = False return password else: condition = True else: if type4 == True: sample_space = string.digits password = ''.join((random.choice(sample_space) for i in range(length))) clear_screen() printdashes() print("Your password is: ", password) printdashes() c = cli_ui.ask_yes_no("Do you like this password? ") if c == True: clipboard.copy(password) clear_screen() print( "The password has been copied to your clipboard." ) condition = False return password else: condition = True else: print("You didn't choose any type of character.") c = cli_ui.ask_yes_no("Do you want to retry?") if c == True: condition = True else: clear_screen() condition = False return False