<s> import logging <EOL> import os <EOL> import re <EOL> import yaml <EOL> from . utils import tempdir <EOL> from . crypt import ensure_keys , import_keys , get_default_recipient <EOL> HOMEDIR = os . path . expanduser ( "<STR_LIT>" ) <EOL> DEFAULT_CONFIG_PATH = os . path . join ( os . path . join ( HOMEDIR , '<STR_LIT>' ) ) <EOL> DEFAULT = { <EOL> '<STR_LIT:path>' : os . path . join ( os . path . join ( HOMEDIR , '<STR_LIT>' ) ) , <EOL> '<STR_LIT>' : <NUM_LIT> , <EOL> '<STR_LIT>' : r'<STR_LIT>' , <EOL> '<STR_LIT>' : os . path . join ( os . path . expanduser ( '<STR_LIT>' ) ) , <EOL> '<STR_LIT>' : None , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : [ '<STR_LIT:name>' , '<STR_LIT>' , '<STR_LIT:password>' , '<STR_LIT>' ] , <EOL> '<STR_LIT>' : { '<STR_LIT:name>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' } , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : None , <EOL> '<STR_LIT>' : None , <EOL> '<STR_LIT>' : <NUM_LIT:5> , <EOL> '<STR_LIT>' : <NUM_LIT:0> , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : None , <EOL> '<STR_LIT>' : [ '<STR_LIT:password>' ] , <EOL> '<STR_LIT>' : u'<STR_LIT>' <EOL> } <EOL> def is_repo_url ( path ) : <EOL> if path : <EOL> return re . match ( <EOL> r'<STR_LIT>' , <EOL> path <EOL> ) is not None <EOL> def read ( path , filename = '<STR_LIT>' ) : <EOL> try : <EOL> if os . path . isdir ( path ) : <EOL> path = os . path . join ( path , '<STR_LIT>' ) <EOL> with open ( path ) as config_file : <EOL> content = config_file . read ( ) <EOL> configuration = yaml . load ( content ) <EOL> except IOError : <EOL> logging . debug ( u'<STR_LIT>' . format ( path ) ) <EOL> return { } <EOL> except yaml . scanner . ScannerError as e : <EOL> logging . error ( u'<STR_LIT>' . format ( e ) ) <EOL> return { } <EOL> return configuration <EOL> def create ( path , defaults = { } , filename = '<STR_LIT>' ) : <EOL> config_path = os . path . join ( os . path . expanduser ( path ) , filename ) <EOL> with open ( config_path , '<STR_LIT:w>' ) as config_file : <EOL> config_file . write ( yaml . dump ( defaults , default_flow_style = False ) ) <EOL> def setup_crypt ( configuration ) : <EOL> keys_filepath = ensure_keys ( configuration [ '<STR_LIT:path>' ] ) <EOL> if keys_filepath : <EOL> configuration [ '<STR_LIT>' ] = tempdir ( ) <EOL> import_keys ( keys_filepath , configuration [ '<STR_LIT>' ] ) <EOL> if not configuration [ '<STR_LIT>' ] : <EOL> configuration [ '<STR_LIT>' ] = get_default_recipient ( configuration [ '<STR_LIT>' ] ) <EOL> return configuration </s>
