| 43 | | def get(name, opts={}): |
| 44 | | setitem('load_data', _load()) |
| 45 | | setitem('get_ret', load_data[name] if load_data.has_key(name) else {} ) |
| 46 | | if opts.has_key('require'): |
| 47 | | setitem('get_for_keys', set(opts['require'].keys()) - set(get_ret.keys())) |
| 48 | | if get_for_keys: |
| 49 | | for key in keys: |
| 50 | | setitem('get_for_ret_' + key,opts['require'][key]) |
| 51 | | setitem('get_ret', set(name,{'config' : get_ret})) |
| 52 | | |
| 53 | | return get_ret or {'username' : '', 'password' : ''} |
| | 43 | get = lambda name, opts={} :( |
| | 44 | [setitem('load_data', _load())] and \ |
| | 45 | [setitem('get_ret', load_data[name] if load_data.has_key(name) else {} )] and \ |
| | 46 | [opts.has_key('require') and \ |
| | 47 | [setitem('get_for_keys', set(opts['require'].keys()) - set(get_ret.keys()))] and \ |
| | 48 | [get_for_keys and \ |
| | 49 | [[setitem('get_for_ret_' + key,opts['require'][key])] for key in get_for_keys] and \ |
| | 50 | [setitem('get_ret', set(name,{'config' : get_ret}))]]] and \ |
| | 51 | (get_ret or {'username' : '', 'password' : ''}) ) |
| 55 | | def switch(name, opts={}): |
| 56 | | setitem('_profile', os.path.join(DIRECTORY, '%s.yaml' % name)) |
| 57 | | setitem('switch_config', config()) |
| 58 | | setitem('switch_ret', switch_config['profile']) |
| 59 | | setitem('switch_config_profie',name) |
| 60 | | yaml.dump(switch_config, |
| | 53 | switch = lambda name, opts={} :( |
| | 54 | [setitem('_profile', os.path.join(DIRECTORY, '%s.yaml' % name))] and |
| | 55 | [setitem('switch_config', config())] and |
| | 56 | [setitem('switch_ret', switch_config['profile'])] and |
| | 57 | [setitem('switch_config_profie',name)] and |
| | 58 | [yaml.dump(switch_config, |
| 65 | | def _load(): |
| 66 | | return ([[os.mkdir(DIRECTORY)] and [os.chmod(DIRECTORY, 0700)] if not os.path.exists(DIRECTORY) else True] |
| 67 | | and |
| 68 | | [[yaml.dump({'profile' : 'default'}, open(_config, 'w'), default_flow_style=False)] |
| 69 | | and [os.chmod(_config, 0600)] if not os.path.exists(_config) else True] |
| 70 | | and |
| 71 | | [switch(config()['profile'])] |
| 72 | | and |
| 73 | | [[yaml.dump({}, |
| 74 | | open(_profile, 'w'), |
| 75 | | default_flow_style=False)] |
| 76 | | and [os.chmod(_profile, 0600)] if not os.path.exists(_profile) else True] |
| 77 | | |
| 78 | | and (yaml.load(open(_profile)) or {})) |
| | 63 | _load = lambda :( |
| | 64 | [[os.mkdir(DIRECTORY)] and [os.chmod(DIRECTORY, 0700)] if not os.path.exists(DIRECTORY) else True] |
| | 65 | and |
| | 66 | [[yaml.dump({'profile' : 'default'}, open(_config, 'w'), default_flow_style=False)] |
| | 67 | and [os.chmod(_config, 0600)] if not os.path.exists(_config) else True] |
| | 68 | and |
| | 69 | [switch(config()['profile'])] |
| | 70 | and |
| | 71 | [[yaml.dump({}, |
| | 72 | open(_profile, 'w'), |
| | 73 | default_flow_style=False)] |
| | 74 | and [os.chmod(_profile, 0600)] if not os.path.exists(_profile) else True] |
| | 75 | |
| | 76 | and (yaml.load(open(_profile)) or {})) |