Changeset 22141 for lang/python/pit

Show
Ignore:
Timestamp:
10/26/08 07:20:48 (3 months ago)
Author:
yoshiori
Message:

get onliner

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • lang/python/pit/pit_oneliner.py

    r22136 r22141  
    4141    return set_result 
    4242 
    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' : ''} 
     43get = 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' : ''}) ) 
    5452 
    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, 
     53switch = 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, 
    6159              open(_config, 'w'), 
    62               default_flow_style=False) 
    63     return switch_ret 
     60              default_flow_style=False)] and 
     61    switch_ret) 
    6462 
    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 {})) 
    7977 
    8078config = lambda : yaml.load(open(_config))