def config(file): """Настройки""" if file: click.echo(CFG_PATH) else: config_data = defaultdict(lambda: "") config_data['redmine.host'] = questionary.text('Укажите URL').ask() auth_method = questionary.select('Выберите метод авторизации', ['Token', 'Login']).ask() if auth_method == 'Token': config_data['redmine.token'] = questionary.password( 'Укажите Token').ask() elif auth_method == 'Login': config_data['redmine.username'] = questionary.text( 'Укажите Логин').ask() config_data['redmine.password'] = questionary.password( 'Укажите Пароль').ask() rd = get_rd(config_data) projects = get_projects(rd) projects_map = {str(v): v for v in projects} selected_project = questionary.select('Укажите ProjectID', list(projects_map.keys())).ask() config_data['project.id'] = projects_map[selected_project].id cf_fields = get_custom_fields(rd) cf_fields_map = {str(v): cf_id for cf_id, v in cf_fields.items()} cf_filter_selected = questionary.checkbox( 'Какие настраиваемые поля использовать?', choices=list(cf_fields_map.keys())).ask() cf_filter_selected_release = questionary.checkbox( 'Какие настраиваемые поля использовать для релиза?', choices=list(cf_fields_map.keys())).ask() config_data['release.filter_custom_fields'] = list( map(str, [cf_fields_map[cf] for cf in cf_filter_selected])) config_data['issue.filter_custom_fields'] = list( map(str, [cf_fields_map[cf] for cf in cf_filter_selected_release])) tracker = get_trackers_project(rd, config_data['project.id']) statuses = get_status_project(rd) status_map = {str(v): v for v in statuses} tracker_map = {str(v): v for v in tracker} selected_tracker = questionary.select('Выберите трекер с релизами', list(tracker_map.keys())).ask() selected_status = questionary.select( 'Выберите статус опубликованого релиза', list(status_map.keys())).ask() config_data['release.tracker_id'] = tracker_map[selected_tracker].id config_data['release.done_status_id'] = status_map[selected_status].id if questionary.confirm('Сохранить').ask(): cfg.update(config_data.items()) cfg.sync() click.secho('Сохраннено', bold=True)
def verify(self): attempts = 3 while True: attempts -= 1 if attempts == 0: print("3 attemps used up!") exit() username = questionary.text( "Enter your username:"******"root", validate=lambda x: len(x) > 0, ).ask() password = questionary.password( "Enter the password:"******"root" and password == "password": print("Username and password validated successfully!") print("-" * os.get_terminal_size().columns) print("Teacher Mode".center(os.get_terminal_size().columns)) print("-" * os.get_terminal_size().columns) break else: print( "Wrong passsword!".center( os.get_terminal_size().columns ).capitalize() )
def password(message, required=False): question = questionary.password(message) if required: return _ask(question, _validate_empty_input) else: return _ask(question)
def ask_pystyle(**kwargs): # create the question object question = questionary.password("Enter your git password", style=custom_style_dope, **kwargs) # prompt the user for an answer return question.ask()
def password(message, required=False): raise_if_non_interactive(message) question = questionary.password(message) if required: return _ask(question, _validate_empty_input) else: return _ask(question)
def showMain(self): questionary.text("What's your first name").ask() questionary.password("What's your secret?").ask() questionary.confirm("Are you amazed?").ask() questionary.select( "What do you want to do?", choices=[ "Order a pizza", "Make a reservation", "Ask for opening hours" ], ).ask() questionary.rawselect( "What do you want to do?", choices=[ "Order a pizza", "Make a reservation", "Ask for opening hours" ], ).ask() questionary.checkbox("Select toppings", choices=["foo", "bar", "bazz"]).ask() questionary.path("Path to the projects version file").ask()
def parse_config_file(path: Path) -> Config: with path.open('r') as f: conf = yaml.full_load(f) conf['_pk'] = os.environ.get('WALLET_PK') if not conf['_pk'] or len(conf['_pk']) != 64 or not all(c in string.hexdigits for c in conf['_pk']): conf['_pk'] = questionary.password( 'In order to make transactions, I need the private key for your wallet:', validate=PrivateKeyValidator, ).ask() account = Account.from_key(conf['_pk']) conf['wallet'] = account.address logger.info(f'Using wallet address {conf["wallet"]}.') conf['config_file'] = str(path) return Config(**conf)
def setup_database(logger): db_type = questionary.select("Which database type are you using?", choices=[{'name': "SQL", 'value': 'mssql+pyodbc_mssql'}, {'name': "MySQL", 'value': 'mysql'}, {'name': "Postgres", 'value': 'postgres'}] ).ask() db_settings = {'database_type': db_type, 'database_user': questionary.text("Database username").ask(), 'database_pwd': questionary.password("Database Password").ask(), 'database_server': questionary.text("Database Server Address").ask(), 'database_port': ask_question(logger, 'Database Port', 'int', default=get_port(db_type)), 'database_schema': questionary.text("Database Schema", default=get_schema(db_type)).ask(), 'database_name': questionary.text("Database Name", default=get_default_db(db_type)).ask()} return db_settings
def set_remote_credentials(): "set remote credentials file to run the test on browserstack or saucelabs" platform = questionary.select("Select the remote platform on which you wish to run the test on", choices=["Browserstack","Saucelabs"]).ask() if platform == "Browserstack": platform = "BS" else: platform = "SL" username = questionary.text("Enter the Username").ask() password = questionary.password("Enter the password").ask() with open("conf/remote_credentials.py",'w') as cred_file: cred_file.write("REMOTE_BROWSER_PLATFORM = '%s'\ \nUSERNAME = '******'\ \nACCESS_KEY = '%s'"%(platform,username,password)) questionary.print("Updated the credentials successfully", style="bold fg:green")
def main(): session = requests.Session() judges = get_login_entries() if any('contests' in judge for judge in judges.values()): print('login.toml contains contest list which is no longer needed') base_url = prompt_choice('Where to upload to', judges.keys()) username = judges[base_url]['username'] password = judges[base_url].get('password') if base_url[-1] == '/': base_url = base_url[:-1] if not password: password = questionary.password(message='Judge password').unsafe_ask() contests = get_active_testing_contest(base_url, username, password) if not contests: exit_error('No running testing contests found for judge ' '(shortname must end in "testing")') contest_name = prompt_choice('Which contest to add to', contests) csrf_token = get_csrf_token(session, base_url) if not login(session, base_url, csrf_token, username, password): exit_error('Invalid login data') contest_id = get_contest_id(session, base_url, contest_name) if contest_id is None: exit_error(f'There is no contest named {contest_name}') if len(sys.argv) == 3: # Upload the validator first, so that the problem can be linked to it # using its domjudge-problem.ini result = upload_validator(session, base_url, sys.argv[2]) if result == 200: print('-> Validator uploaded successfully') elif result == 500: # We get a 500 code with lots of SQL code if the problem already # exists exit_error('Validator upload failed, maybe it was uploaded before') else: exit_error(f'Validator upload failed with status code {result}') result = upload_problem(session, base_url, contest_id, sys.argv[1]) if result is True: print('-> Problem uploaded successfully') elif result == 200: # If the problem already exists, we still get 200 as a response exit_error('-> Problem upload failed, maybe it was uploaded before') else: exit_error(f'Problem upload failed with status code {result}')
def create_client_and_authenticate(ctx): """Create a client and authenticate.""" host = ctx.config['server_url'] port = ctx.config['port'] api_path = ctx.config['api_path'] info(f"Connecting to server at '{host}:{port}{api_path}'") username = q.text("Username:"******"Password:"******"Could not authenticate with server!") debug(e) exit(1) return client
shutil.move('config.py', file) elif cont == 0: exit(0) else: exit(0) with open('config.py', 'a+') as file: file.write('#!/usr/bin/python\n\n') file.write('# Config.py\n') file.write('# Program config, automagically generated by install.py\n') file.write( '# Published under the Apache License 2.0, maintained by James Bolton ([email protected])\n\n' ) username = questionary.text("What's your MySchedule username?").ask() password = questionary.password("What's your MySchedule password").ask() def randomString(stringLength=10): """Generate a random string of fixed length """ letters = string.ascii_lowercase return ''.join(random.choice(letters) for i in range(stringLength)) password = password.encode() salt = randomString(16).encode() passkey = randomString(32).encode() kdf = PBKDF2HMAC(algorithm=hashes.SHA256(), length=32,
return map(filter_games_for_user, users) def filter_zero_games(tabulized_games): return filter(lambda r: sum(r[1:]) > 0, tabulized_games) if __name__ == "__main__": save = questionary.confirm( default=True, message="Save your input to a cache file?").ask() pre_username = load_from_cache('username') pre_password = load_from_cache('password') pre_selected_friends = load_from_cache('selected_friends') username = questionary.text(default=pre_username, message="Your Steam username?").ask() password = questionary.password(default=pre_password, message="Your Steam password?").ask() if save: merge_to_cache({'username': username, 'password': password}) cl = SteamClient() cl.set_credential_location('.') cl.cli_login(username=username, password=password) api = WebAPI(key=fetch_web_api_key(cl)) friends = list( fetch_friends(cl) ) # we need to listify it, to be able to use it twice. TODO: Investigate how to clone generator/iterator? loop = True while loop: pre_selected_friends = load_from_cache('selected_friends') qfriends = list(
def main(): target_path = os.path.abspath( os.path.join(MY_PATH, '..', 'trackersite', 'settings.py')) if os.path.exists(target_path): print( 'Don\'t want to overwrite %s.\nIf you\'re sure, delete it and try again.' % target_path) sys.exit(1) # make a template instance settings.configure(TEMPLATES=[{ 'BACKEND': 'django.template.backends.django.DjangoTemplates' }], TEMPLATE_DEBUG=False) django.setup() template_file = open(os.path.join(MY_PATH, 'settings.py.template')) template = Template(template_file.read()) template_file.close() # set up the options we want options = {} chars = 'abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*(-_=+)' options['secret_key'] = get_random_string(50, chars) # DB provider # TODO: Add Oracle and postgresql_psycopg2 db_choice = questionary.select("Select your database provider", choices=["MySQL", "SQLite"]).ask() if db_choice == "MySQL": options['backend'] = 'mysql' options['DB_NAME'] = questionary.text("Database name", default="tracker").ask() options['DB_USER'] = questionary.text("Database username", default="root").ask() options['DB_PASS'] = questionary.password("Database password").ask() options['DB_HOST'] = questionary.text( "Database hostname [localhost]").ask() options['DB_PORT'] = questionary.text("Database port").ask() print('INFO: Creating your database') subprocess.call( [ 'mysql', # Pass username '-u', options['DB_USER'], # Pass password '-p' + options['DB_PASS'], # Pass -h and hostname, but only if db_host is non-empty string '-h ' + options['DB_HOST'] if options['DB_HOST'] else '', # Same for db_port '-P ' + options['DB_PORT'] if options['DB_PORT'] else '', '-e', 'CREATE DATABASE %s' % options['DB_NAME'] ], stdout=subprocess.DEVNULL) elif db_choice == "SQLite": options['backend'] = 'sqlite3' default_path = os.path.realpath( os.path.join(os.path.dirname(__file__), '..', 'deploy', 'tracker.db')) options['DB_NAME'] = questionary.text("Path to new database file", default=default_path).ask() options['DB_USER'] = '' options['DB_PASS'] = '' options['DB_HOST'] = '' options['DB_PORT'] = '' context = Context(options) target = open(target_path, 'wb') target.write(template.render(context).encode('utf-8')) target.close()
def ask(self): self.answer = questionary.password("Tableau initial admin password?", style=custom_style).ask() return self.answer
def password(message): return _ask(questionary.password(message))
# -*- coding: utf-8 -*- """ Created on Sat Nov 7 13:19:23 2020 @authors: Spencer Ball, Atom Arce, Shyam Menon """ from selenium import webdriver from selenium.webdriver.common.action_chains import ActionChains from selenium.webdriver.common.keys import Keys import questionary # User enters PEY portal credentials portal_ID = questionary.text("Enter PEY portal ID (username)").ask() portal_pass = questionary.password("Enter PEY portal password").ask() # ========== User customizable job search criteria ========== # Discipline selection disciplines = questionary.checkbox( 'Select desired disciplines', choices=[ "Actuarial", "Chemical Engineering", "Civil Engineering", "Engineering Science (Aerospace)", "Engineering Science (Machine Intelligence)", "Engineering Science (Electrical and Computer)", "Math & Stats" ]).ask() # Key words keywords = []
import questionary from examples import custom_style_dope if __name__ == '__main__': questionary.text("What's your first name").ask() questionary.password("What's your secret?").ask() questionary.confirm("Are you amazed?").ask() questionary.select("What do you want to do?", choices=[ 'Order a pizza', 'Make a reservation', 'Ask for opening hours' ]).ask() questionary.rawselect("What do you want to do?", choices=[ 'Order a pizza', 'Make a reservation', 'Ask for opening hours' ]).ask() questionary.checkbox('Select toppings', choices=["foo", "bar", 'bazz'], style=custom_style_dope).ask()
def ask_for_password(self, question): answer = questionary.password(question).ask() return answer