def do_toggle(self): """Toggle generators on/off.""" wf = self.wf args = self.args gen_id = args.get('<genid>') log.debug('toggling=%r', gen_id) # Strength bar toggle if gen_id == 'strength_bar': if wf.settings.get('strength_bar'): log.debug('Turning strength bar off...') wf.settings['strength_bar'] = False mode = 'off' else: log.debug('Turning strength bar on...') wf.settings['strength_bar'] = True mode = 'on' print('Turned strength bar {0}'.format(mode)) # Notifications toggle elif gen_id == 'notifications': if wf.settings.get('suppress_notifications'): log.debug('Turning notifications on...') del wf.settings['suppress_notifications'] mode = 'on' else: log.debug('Turning notifications off...') wf.settings['suppress_notifications'] = True mode = 'off' else: # Generator toggles self.load_user_generators() gen = None for g in get_generators(): if g.id == gen_id: gen = g break if not gen: log.critical('Unknown generator : %s', gen_id) return 1 active_generators = wf.settings.get('generators', [])[:] if gen_id in active_generators: active_generators.remove(gen_id) log.info('Turned generator `%s` off', gen.name) mode = 'off' else: active_generators.append(gen_id) log.info('Turned generator `%s` on', gen.name) mode = 'on' log.debug('Active generators : %s', active_generators) wf.settings['generators'] = active_generators print("Turned generator '{0}' {1}".format(gen.name, mode)) run_trigger('conf') return 0
def do_toggle(self): """Toggle generators on/off.""" wf = self.wf args = self.args gen_id = args.get('<genid>') log.debug('toggling=%r', gen_id) # Strength bar toggle if gen_id == 'strength_bar': if wf.settings.get('strength_bar'): log.debug('Turning strength bar off...') wf.settings['strength_bar'] = False mode = 'off' else: log.debug('Turning strength bar on...') wf.settings['strength_bar'] = True mode = 'on' print('Turned strength bar {0}'.format(mode)) # Notifications toggle elif gen_id == 'notifications': if wf.settings.get('suppress_notifications'): log.debug('Turning notifications on...') del wf.settings['suppress_notifications'] mode = 'on' else: log.debug('Turning notifications off...') wf.settings['suppress_notifications'] = True mode = 'off' else: # Generator toggles self.load_user_generators() gen = None for g in get_generators(): if g.id == gen_id: gen = g break if not gen: log.critical('Unknown generator : %s', gen_id) return 1 active_generators = wf.settings.get('generators', [])[:] if gen_id in active_generators: active_generators.remove(gen_id) log.info('Turned generator `%s` off', gen.name) mode = 'off' else: active_generators.append(gen_id) log.info('Turned generator `%s` on', gen.name) mode = 'on' log.debug('Active generators : %s', active_generators) wf.settings['generators'] = active_generators print("Turned generator '{0}' {1}".format(gen.name, mode)) # call_alfred_search(KEYWORD_CONF + ' ') call_external_trigger('conf') return 0
def do_toggle(self): """Toggle generators on/off.""" wf = self.wf args = self.args gen_id = args.get('<genid>') # Strength bar toggle if gen_id == 'strength_bar': if wf.settings.get('strength_bar'): log.debug('Turning strength bar off...') wf.settings['strength_bar'] = False mode = 'off' else: log.debug('Turning strength bar on...') wf.settings['strength_bar'] = True mode = 'on' print('Turned strength bar {0}'.format(mode)) else: # Generator toggles self.load_user_generators() gen = None for g in get_generators(): if g.id == gen_id: gen = g break if not gen: log.critical('Unknown generator : %s', gen_id) return 1 active_generators = wf.settings.get('generators', []) if gen_id in active_generators: log.debug('Turning generator `%s` off...', gen.name) active_generators.remove(gen_id) mode = 'off' else: log.debug('Turning generator `%s` on...', gen.name) active_generators.append(gen_id) mode = 'on' log.debug('Active generators : %s', active_generators) wf.settings['generators'] = active_generators print("Turned generator '{0}' {1}".format(gen.name, mode)) call_alfred_search(KEYWORD_CONF + ' ') return 0
if (os.path.exists(weights_file)): print("load weight file:", weights_file) model.load_weights(weights_file) print("Get callbacks") # Get callbacks cb = callbacks.get_callbacks(weights_file) print("Compile the model") # Complie the model model.compile(loss="categorical_crossentropy", optimizer=SGD(momentum=0.9), metrics=["acc"]) # Get data generator train_gen, valid_gen = generators.get_generators(width, height) print("Start fitting") # execute fitting on main thread model_output = model.fit_generator(train_gen, steps_per_epoch=constants.STEPS, epochs=20, verbose=1, callbacks=cb, validation_data=valid_gen, validation_steps=constants.VALIDATION_STEPS, workers=0, use_multiprocessing=True, shuffle=True, initial_epoch=0)
def do_conf(self): """Show configuration options.""" args = self.args wf = self.wf query = args.get('<query>') options = [] # Update status if wf.update_available: options.append( { 'title': 'An Update is Available', 'subtitle': '↩ or ⇥ to install update', 'autocomplete': 'workflow:update', 'icon': 'icons/update-available.icns', } ) else: options.append( { 'title': 'No Update Available', 'subtitle': '↩ or ⇥ to check for an update', 'autocomplete': 'workflow:update', 'icon': 'icons/update-none.icns', } ) # Help file options.append( { 'title': 'Open Help', 'subtitle': 'View online help in your browser', 'autocomplete': 'workflow:help', 'icon': ICON_HELP, } ) # Settings options.append( { 'title': 'Default Password Strength : {0}'.format( wf.settings.get('pw_strength')), 'subtitle': '↩ or ⇥ to change', 'arg': 'set pw_strength', 'valid': True, 'icon': ICON_SETTINGS, } ) options.append( { 'title': 'Default Password Length : {0}'.format( wf.settings.get('pw_length')), 'subtitle': '↩ or ⇥ to change', 'arg': 'set pw_length', 'valid': True, 'icon': ICON_SETTINGS, } ) # Strength bar if wf.settings.get('strength_bar'): icon = 'icons/toggle_on.icns' else: icon = 'icons/toggle_off.icns' options.append( { 'title': 'Strength Bar', 'subtitle': 'Show password strength as a bar, not bits', 'arg': 'toggle strength_bar', 'valid': True, 'icon': icon, } ) # Generators self.load_user_generators() generators = get_generators() active_generators = wf.settings.get('generators', []) for gen in generators: if gen.id in active_generators: icon = 'icons/toggle_on.icns' else: icon = 'icons/toggle_off.icns' options.append( { 'title': 'Generator : {0}'.format(gen.name), 'subtitle': gen.description, 'arg': 'toggle {0}'.format(gen.id), 'valid': True, 'icon': icon, } ) if query: options = wf.filter(query, options, key=lambda d: d.get('title'), min_score=30) if not options: wf.add_item('No matching items', 'Try a different query', icon=ICON_WARNING) for opt in options: wf.add_item(**opt) wf.send_feedback() return 0
def do_generate(self): """Generate and display passwords from active generators.""" wf = self.wf args = self.args query = '' mode = 'strength' pw_length = None pw_strength = None if wf.update_available: wf.add_item('An Update is Available', '↩ or ⇥ to install update', autocomplete='workflow:update', icon='icons/update-available.icns') # Determine mode if args.get('--length'): mode = 'length' pw_length = args.get('<length>') or '' pw_length = pw_length.strip() query = pw_length if pw_length: if not pw_length.isdigit(): wf.add_item('`{0}` is not a number'.format(pw_length), 'Usage: pwlen [length]', icon=ICON_WARNING) wf.send_feedback() return 0 pw_length = int(pw_length) pw_length = pw_length or wf.settings.get('pw_length', DEFAULT_PW_LENGTH) log.info('Password length: %d', pw_length) else: # Default strength mode pw_strength = args.get('<strength>') or '' query = pw_strength try: pw_strength = entropy_from_strength(pw_strength) except ValueError: wf.add_item('`{0}` is not a number'.format(pw_strength), 'Usage: pwgen [strength]', icon=ICON_WARNING) wf.send_feedback() return 0 pw_strength = ( pw_strength or entropy_from_strength(wf.settings.get('pw_strength', DEFAULT_PW_STRENGTH))) log.info('Password strength: %d bits', pw_strength) self.load_user_generators() generators = get_generators() # Filter out inactive generators active_generators = wf.settings.get('generators', []) if len(active_generators): generators = [g for g in generators if g.id in active_generators] log.debug('%d active generators', len(generators)) if not len(generators): wf.add_item('No active generators', 'Use `pwconf` to activate some generators', icon=ICON_WARNING) for g in generators: log.debug('[%0.2f/%s] %s : %s', g.entropy, g.id, g.name, g.description) # log.debug('[%s] %s', g.id, g.password()) if mode == 'length': pw, entropy = g.password(length=pw_length) else: pw, entropy = g.password(strength=pw_strength) if wf.settings.get('strength_bar'): strength = pw_strength_meter(entropy) else: strength = 'Strength : %0.1f bits //' % entropy subtitle = ('%s Length : %d // %s' % (strength, len(pw), g.description)) wf.add_item(pw, subtitle, arg=pw, uid=g.id, autocomplete=query, valid=True, copytext=pw, largetext=pw) wf.send_feedback() return 0
def do_conf(self): """Show configuration options.""" args = self.args wf = self.wf query = args.get('<query>') options = [] # Update status if wf.update_available: options.append( { 'title': 'An Update is Available', 'subtitle': '↩ or ⇥ to install update', 'autocomplete': 'workflow:update', 'icon': ICON_UPDATE_AVAILABLE, } ) else: options.append( { 'title': 'No Update Available', 'subtitle': '↩ or ⇥ to check for an update', 'autocomplete': 'workflow:update', 'icon': ICON_UPDATE_NONE, } ) # Help file options.append( { 'title': 'Open Help', 'subtitle': 'View online help in your browser', 'autocomplete': 'workflow:help', 'icon': ICON_HELP, } ) # Settings options.append( { 'title': 'Default Password Strength : {0}'.format( wf.settings.get('pw_strength')), 'subtitle': '↩ or ⇥ to change', 'arg': 'set pw_strength', 'valid': True, 'icon': ICON_SETTINGS, } ) options.append( { 'title': 'Default Password Length : {0}'.format( wf.settings.get('pw_length')), 'subtitle': '↩ or ⇥ to change', 'arg': 'set pw_length', 'valid': True, 'icon': ICON_SETTINGS, } ) # Show notifications if wf.settings.get('suppress_notifications'): icon = ICON_TOGGLE_OFF else: icon = ICON_TOGGLE_ON options.append( { 'title': 'Show notifications', 'subtitle': 'Show a notification when a password is copied', 'arg': 'toggle notifications', 'valid': True, 'icon': icon, } ) # Strength bar if wf.settings.get('strength_bar'): icon = ICON_TOGGLE_ON else: icon = ICON_TOGGLE_OFF options.append( { 'title': 'Strength Bar', 'subtitle': 'Show password strength as a bar, not bits', 'arg': 'toggle strength_bar', 'valid': True, 'icon': icon, } ) # Generators self.load_user_generators() generators = get_generators() active_generators = wf.settings.get('generators', []) for gen in generators: if gen.id in active_generators: icon = ICON_TOGGLE_ON else: icon = ICON_TOGGLE_OFF options.append( { 'title': 'Generator : {0}'.format(gen.name), 'subtitle': gen.description, 'arg': 'toggle {0}'.format(gen.id), 'valid': True, 'icon': icon, } ) if query: options = wf.filter(query, options, key=lambda d: d.get('title'), min_score=30) if not options: wf.add_item('No matching items', 'Try a different query', icon=ICON_WARNING) for opt in options: wf.add_item(**opt) wf.send_feedback() return 0
def do_generate(self): """Generate and display passwords from active generators.""" wf = self.wf args = self.args query = '' mode = 'strength' pw_length = None pw_strength = None if wf.update_available: wf.add_item('An Update is Available', '↩ or ⇥ to install update', autocomplete='workflow:update', icon=ICON_UPDATE_AVAILABLE) # Determine mode if args.get('--length'): mode = 'length' pw_length = args.get('<length>') or '' pw_length = pw_length.strip() query = pw_length if pw_length: if not pw_length.isdigit(): wf.add_item('`{0}` is not a number'.format(pw_length), 'Usage: pwlen [length]', icon=ICON_WARNING) wf.send_feedback() return 0 pw_length = int(pw_length) pw_length = pw_length or wf.settings.get('pw_length', DEFAULT_PW_LENGTH) log.info('Password length: %d', pw_length) else: # Default strength mode pw_strength = args.get('<strength>') or '' query = pw_strength try: pw_strength = entropy_from_strength(pw_strength) except ValueError: wf.add_item('`{0}` is not a number'.format(pw_strength), 'Usage: pwgen [strength]', icon=ICON_WARNING) wf.send_feedback() return 0 pw_strength = ( pw_strength or entropy_from_strength(wf.settings.get('pw_strength', DEFAULT_PW_STRENGTH))) log.info('Password strength: %d bits', pw_strength) self.load_user_generators() generators = get_generators() # Filter out inactive generators active_generators = wf.settings.get('generators', []) if len(active_generators): generators = [g for g in generators if g.id in active_generators] log.debug('%d active generators', len(generators)) if not len(generators): wf.add_item('No active generators', 'Use `pwconf` to activate some generators', icon=ICON_WARNING) for g in generators: log.debug('[%0.2f/%s] %s : %s', g.entropy, g.id, g.name, g.description) # log.debug('[%s] %s', g.id, g.password()) if mode == 'length': pw, entropy = g.password(length=pw_length) else: pw, entropy = g.password(strength=pw_strength) if wf.settings.get('strength_bar'): strength = pw_strength_meter(entropy) else: strength = 'Strength : %0.1f bits //' % entropy subtitle = ('%s Length : %d // %s' % (strength, len(pw), g.description)) icon = pw_strength_icon(entropy) it = wf.add_item(pw, subtitle, arg=pw, uid=g.id, autocomplete=query, valid=True, copytext=pw, largetext=pw, icon=icon) it.setvar('notification', 'Password copied to clipboard') it.setvar('action', 'copy') m = it.add_modifier('cmd', subtitle='Copy to clipboard and ' 'paste to frontmost application', arg=pw) m.setvar('action', 'paste') m = it.add_modifier('alt', subtitle='Copy to clipboard as public data', arg=pw) m.setvar('action', 'public-copy') m = it.add_modifier('ctrl', subtitle='Copy to clipboard as public data ' 'and paste to frontmost application', arg=pw) m.setvar('action', 'public-paste') wf.send_feedback() return 0
def list_generators(): gens = generators.get_generators() print(", ".join(gens.keys()))