Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _reinstall(site, admin_password=None, mariadb_root_username=None, mariadb_root_password=None, yes=False, verbose=False):
if not yes:
click.confirm('This will wipe your database. Are you sure you want to reinstall?', abort=True)
try:
frappe.init(site=site)
frappe.connect()
frappe.clear_cache()
installed = frappe.get_installed_apps()
frappe.clear_cache()
except Exception:
installed = []
finally:
if frappe.db:
frappe.db.close()
frappe.destroy()
frappe.init(site=site)
_new_site(frappe.conf.db_name, site, verbose=verbose, force=True, reinstall=True, install_apps=installed,
mariadb_root_username=mariadb_root_username, mariadb_root_password=mariadb_root_password,
def authenticate(register):
"""
For authenticating a client
"""
if register:
reg = click.confirm('Do you already have an account?')
if not reg:
# get the username and password
yes = click.confirm('Well! Why not create one? Press y to confirm.')
# fuck you, user
if not yes: exit(1)
username = click.prompt('Username', type=str)
password = click.prompt('Password', type=str, hide_input=True, confirmation_prompt=True)
# sweet password check
if len(password) < 8:
while len(password) < 8:
click.echo('Password must be atleast of 8 characters.')
password = click.prompt('Password', type=str, hide_input=True, confirmation_prompt=True)
res = post({'user': username, 'pass': password}, SIGNUP)
else:
username = click.prompt('Username', type=str)
password = click.prompt('Password', type=str, hide_input=True)
res = post({'user': username, 'pass': password}, SIGNIN)
else:
# click.echo('Login to your account to pull.')
content_list.append(('file', (filename, clipboard_text)))
utils.secho(colorize, 'New file created from clipboard content', fg='blue')
else:
utils.secho(colorize, 'Clipboard is empty, ignoring', fg='yellow')
if not content_list:
# click.edit() return None if user closes to editor without saving.
content = click.edit()
if content is None:
utils.secho(colorize, 'Empty content. Exiting', fg='red', err=True)
sys.exit(1)
if content == '':
confirm = click.confirm('Content is empty. Create anyway?')
if not confirm:
sys.exit(1)
if not title:
# if title not specified, pick first 50 charecters of file as title.
title = content.split('\n')[0][:50]
content_list.append(('file', (filename, content)))
scm = 'hg' if kwargs.get('hg') else 'git'
utils.secho(colorize, 'Snippet creating...', fg='blue')
api = SnippetApi(config)
response = api.create_snippet(
content_list,
form_data = {"pass": password,
"name": username}
for i in form_feilds:
attrs = i.attrs
if "name" in attrs:
if "value" in attrs and attrs["value"]:
form_data[attrs["name"]] = attrs["value"]
try:
logged_page = codechef_session.post(login_url, form_data)
except BaseException:
display.url_error(login_url, abort=True)
else:
# logout all other sessions as codechef doesn't allow multiple sessions
if("session/limit" in logged_page.url):
click.confirm("Session limit exceeded\n" +
"Do you want to logout of other sessions",
default=True, abort=True)
display.normal("logging you out of all other sessions\n" +
"this may take some time...")
while "session/limit" in logged_page.url:
logout_other_session()
logged_page = codechef_session.post(url, form_data)
# codechef doesn't check cookies and trivially displays
# the latest as current session
# handle this using modifying logout_other_session by
# logging out after checking session cookies
# and matching with form data. trivially the following solution works
logged_page = codechef_session.post(url, form_data)
if len(
def update_volume_group(ctx, from_json, force, wait_for_state, max_wait_seconds, wait_interval_seconds, volume_group_id, defined_tags, display_name, freeform_tags, volume_ids, if_match):
if isinstance(volume_group_id, six.string_types) and len(volume_group_id.strip()) == 0:
raise click.UsageError('Parameter --volume-group-id cannot be whitespace or empty string')
if not force:
if defined_tags or freeform_tags or volume_ids:
if not click.confirm("WARNING: Updates to defined-tags and freeform-tags and volume-ids will replace any existing values. Are you sure you want to continue?"):
ctx.abort()
kwargs = {}
if if_match is not None:
kwargs['if_match'] = if_match
details = {}
if defined_tags is not None:
details['definedTags'] = cli_util.parse_json_parameter("defined_tags", defined_tags)
if display_name is not None:
details['displayName'] = display_name
if freeform_tags is not None:
details['freeformTags'] = cli_util.parse_json_parameter("freeform_tags", freeform_tags)
def terminate_node_calculation(node_name, yes):
if not yes:
click.confirm('Are you sure you want to terminate node {}?'.format(node_name), abort=True)
try:
node_model = Cluster.get(node_name)
if node_model.is_master:
click.echo('Error: cannot terminate master node {}'.format(node_name), err=True)
else:
Cluster.terminate_node(node_name)
click.echo('Node {} was terminated'.format(node_name))
except ConfigNotFoundError as config_not_found_error:
click.echo(str(config_not_found_error), err=True)
except requests.exceptions.RequestException as http_error:
click.echo('Http error: {}'.format(str(http_error)), err=True)
except RuntimeError as runtime_error:
click.echo('Error: {}'.format(str(runtime_error)), err=True)
except ValueError as value_error:
click.echo('Error: {}'.format(str(value_error)), err=True)
n_decks = len(decks)
if n_decks == 0:
click.echo("No notes added")
return
if a.n_decks > 1:
if n_notes == 1:
click.echo(f'Added note to deck: {decks[0]}')
elif n_decks > 1:
click.echo(f'Added {n_notes} notes to {n_decks} different decks')
else:
click.echo(f'Added {n_notes} notes to deck: {decks[0]}')
else:
click.echo(f'Added {n_notes} notes')
if click.confirm('Review added notes?'):
for i, note in enumerate(notes):
note.review(i, n_notes, remove_actions=['Abort'])
def main(inputfile, source, chunksize, yes):
'''
Calculate theta_deg and theta_deg_offs from source position in camera coordinates
e.g. for example for files analysed with the classifier-tools
The following keys have to be present in the h5py hdf5 file.
* az_tracking
* zd_tracking
* source_x_prediction
* source_y_prediction
* unix_time_utc (Only if a source name is given)
'''
with h5py.File(inputfile, 'r') as f:
if any(col in f['events'].keys() for col in cols) and not yes:
click.confirm('Output keys already exist, overwrite? ', abort=True)
if source is None:
df_it = read_h5py_chunked(
inputfile,
key='events',
columns=[
'pointing_position_az',
'pointing_position_zd',
'source_x_prediction',
'source_y_prediction',
'source_position_az',
'source_position_zd',
],
chunksize=chunksize
)
with Parallel(-1, verbose=10) as pool:
def confirm(self, message):
if self.assume_yes:
return True
return click.confirm(message)
def export(profile, output_filename):
check_for_missing_profile(profile)
# Export its contents to a new file.
path = get_config_path(profile)
env_dict = {}
if os.path.exists(path):
with open(path, 'r') as f:
env_dict = json.load(f)
# resolve_path doesn't expand `~` in `path`.
output_path = expanduser(output_filename)
if os.path.exists(output_path):
if click.confirm('Do you wish to overwrite the contents in ' +
click.style('"%s"' % output_path, fg='cyan') + '?',
abort=True):
pass
# Write to file.
with open(output_path, 'w') as f:
json.dump(env_dict, f, indent=4, sort_keys=True)
echo('Configuration successfully exported to: ', nl=False)
echo('"%s"' % output_path, fg='cyan')