<s> import glob <EOL> import json <EOL> import os <EOL> import shutil <EOL> class PappyConfig ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self ) : <EOL> self . pappy_dir = os . path . dirname ( os . path . realpath ( __file__ ) ) <EOL> self . data_dir = os . path . join ( os . path . expanduser ( '<STR_LIT>' ) , '<STR_LIT>' ) <EOL> self . cert_dir = os . path . join ( self . data_dir , '<STR_LIT>' ) <EOL> self . datafile = '<STR_LIT>' <EOL> self . debug_dir = None <EOL> self . debug_to_file = False <EOL> self . debug_verbosity = <NUM_LIT:0> <EOL> self . listeners = [ ( <NUM_LIT> , '<STR_LIT:127.0.0.1>' ) ] <EOL> self . socks_proxy = None <EOL> self . http_proxy = None <EOL> self . ssl_ca_file = '<STR_LIT>' <EOL> self . ssl_pkey_file = '<STR_LIT>' <EOL> self . histsize = <NUM_LIT:1000> <EOL> self . plugin_dirs = [ os . path . join ( self . data_dir , '<STR_LIT>' ) , os . path . join ( self . pappy_dir , '<STR_LIT>' ) ] <EOL> self . config_dict = { } <EOL> self . global_config_dict = { } <EOL> self . archive = '<STR_LIT>' <EOL> self . debug = False <EOL> self . crypt_dir = '<STR_LIT>' <EOL> self . crypt_file = '<STR_LIT>' <EOL> self . crypt_session = False <EOL> self . salt_len = <NUM_LIT:16> <EOL> def get_default_config ( self ) : <EOL> default_config_file = os . path . join ( os . path . dirname ( os . path . realpath ( __file__ ) ) , <EOL> '<STR_LIT>' ) <EOL> with open ( default_config_file ) as f : <EOL> settings = json . load ( f ) <EOL> return settings <EOL> def get_project_files ( self ) : <EOL> file_glob = glob . glob ( '<STR_LIT:*>' ) <EOL> pp = os . getcwd ( ) + os . sep <EOL> project_files = [ pp + f for f in file_glob if os . path . isfile ( pp + f ) ] <EOL> if self . crypt_file in project_files : <EOL> project_files . remove ( self . crypt_file ) <EOL> return project_files <EOL> @ staticmethod <EOL> def _parse_proxy_login ( conf ) : <EOL> proxy = { } <EOL> if '<STR_LIT:host>' in conf and '<STR_LIT:port>' in conf : <EOL> proxy = { } <EOL> proxy [ '<STR_LIT:host>' ] = conf [ '<STR_LIT:host>' ] . encode ( '<STR_LIT:utf-8>' ) <EOL> proxy [ '<STR_LIT:port>' ] = conf [ '<STR_LIT:port>' ] <EOL> if '<STR_LIT:username>' in conf : <EOL> if '<STR_LIT:password>' in conf : <EOL> proxy [ '<STR_LIT:username>' ] = conf [ '<STR_LIT:username>' ] . encode ( '<STR_LIT:utf-8>' ) <EOL> proxy [ '<STR_LIT:password>' ] = conf [ '<STR_LIT:password>' ] . encode ( '<STR_LIT:utf-8>' ) <EOL> else : <EOL> print '<STR_LIT>' <EOL> else : <EOL> print '<STR_LIT>' <EOL> return None <EOL> return proxy <EOL> def load_settings ( self , proj_config ) : <EOL> subs = { } <EOL> subs [ '<STR_LIT>' ] = self . pappy_dir <EOL> subs [ '<STR_LIT>' ] = self . data_dir <EOL> if '<STR_LIT>' in proj_config : <EOL> self . datafile = proj_config [ "<STR_LIT>" ] . format ( ** subs ) <EOL> if '<STR_LIT>' in proj_config : <EOL> if proj_config [ '<STR_LIT>' ] : <EOL> self . debug_to_file = True <EOL> self . debug_dir = proj_config [ "<STR_LIT>" ] . format ( ** subs ) <EOL> if '<STR_LIT>' in proj_config : <EOL> self . cert_dir = proj_config [ "<STR_LIT>" ] . format ( ** subs ) <EOL> if "<STR_LIT>" in proj_config : <EOL> self . listeners = [ ] <EOL> for l in proj_config [ "<STR_LIT>" ] : <EOL> if '<STR_LIT>' in l : <EOL> l [ '<STR_LIT>' ] = l [ '<STR_LIT>' ] . encode ( '<STR_LIT:utf-8>' ) <EOL> if '<STR_LIT>' in l : <EOL> l [ '<STR_LIT>' ] = l [ '<STR_LIT>' ] . encode ( '<STR_LIT:utf-8>' ) <EOL> self . listeners . append ( l ) <EOL> self . socks_proxy = None <EOL> if "<STR_LIT>" in proj_config : <EOL> if proj_config [ '<STR_LIT>' ] is not None : <EOL> self . socks_proxy = PappyConfig . _parse_proxy_login ( proj_config [ '<STR_LIT>' ] ) <EOL> self . http_proxy = None <EOL> if "<STR_LIT>" in proj_config : <EOL> if proj_config [ '<STR_LIT>' ] is not None : <EOL> self . http_proxy = PappyConfig . _parse_proxy_login ( proj_config [ '<STR_LIT>' ] ) <EOL> if "<STR_LIT>" in proj_config : <EOL> self . histsize = proj_config [ '<STR_LIT>' ] <EOL> def load_global_settings ( self , global_config ) : <EOL> from . http import Request <EOL> if "<STR_LIT>" in global_config : <EOL> self . cache_size = global_config [ '<STR_LIT>' ] <EOL> else : <EOL> self . cache_size = <NUM_LIT> <EOL> Request . cache . resize ( self . cache_size ) <EOL> def load_from_file ( self , fname ) : <EOL> if not os . path . isfile ( fname ) : <EOL> print "<STR_LIT>" % fname <EOL> default_config_file = os . path . join ( os . path . dirname ( os . path . realpath ( __file__ ) ) , <EOL> '<STR_LIT>' ) <EOL> shutil . copyfile ( default_config_file , fname ) <EOL> with open ( fname , '<STR_LIT:r>' ) as f : <EOL> self . config_dict = json . load ( f ) <EOL> self . load_settings ( self . config_dict ) <EOL> def global_load_from_file ( self ) : <EOL> fname = os . path . join ( self . data_dir , '<STR_LIT>' ) <EOL> if not os . path . isfile ( fname ) : <EOL> print "<STR_LIT>" % fname <EOL> default_global_config_file = os . path . join ( self . pappy_dir , <EOL> '<STR_LIT>' ) <EOL> shutil . copyfile ( default_global_config_file , fname ) <EOL> with open ( fname , '<STR_LIT:r>' ) as f : <EOL> self . global_config_dict = json . load ( f ) <EOL> self . load_global_settings ( self . global_config_dict ) </s>
