@@ -37,6 +37,12 @@ def int_tuple(s):
3737 except ValueError :
3838 raise ConfigError ("Required format is (integer, integer): %s" % s )
3939
40+ def get_config_directory ():
41+ xdg_config_home = os .getenv ("XDG_CONFIG_HOME" )
42+ if xdg_config_home == "" :
43+ xdg_config_home = os .path .join (os .getenv ("HOME" ), ".config" )
44+ return os .path .join (xdg_config_home , "wpm" )
45+
4046DEFAULTS = {
4147 "curses" : {
4248 "escdelay" : (str , 15 , "Curses ESCDELAY" ),
@@ -87,19 +93,21 @@ def __getattr__(self, name):
8793 try :
8894 return convert (value )
8995 except ConfigError as e :
90- raise ConfigError ("Error in . wpmrc section %r option %r: %s" %
96+ raise ConfigError ("Error in wpmrc section %r option %r: %s" %
9197 (self .section , name , e ))
9298
9399
94100class Config (object ):
95- """Contains the user configuration, backed by the . wpmrc file."""
101+ """Contains the user configuration, backed by the wpmrc file."""
96102 # pylint: disable=too-many-public-methods
97103
98104 config = None
99105
100106 def __init__ (self ):
101107 Config .config = configparser .ConfigParser ()
102- self .filename = os .path .expanduser ("~/.wpmrc" )
108+ config_directory = get_config_directory ()
109+ self .filename = os .path .join (config_directory , "wpmrc" )
110+ os .makedirs (config_directory , exist_ok = True )
103111
104112 if os .path .isfile (self .filename ):
105113 self .load ()
@@ -113,19 +121,19 @@ def verify(self):
113121 """Verifies wpmrc values."""
114122 level = self .wpm .confidence_level
115123 if not (0 < level < 1 ):
116- raise ConfigError ("The . wpmrc confidence level must be within [0, 1>" )
124+ raise ConfigError ("The wpmrc confidence level must be within [0, 1>" )
117125
118126 def load (self ):
119- """Loads ~/. wpmrc config settings."""
127+ """Loads wpmrc config settings."""
120128 Config .config .read (self .filename )
121129
122130 def save (self ):
123- """Saves settings to ~/. wpmrc"""
131+ """Saves settings to wpmrc"""
124132 with open (self .filename , "wt" ) as file_obj :
125133 Config .config .write (file_obj )
126134
127135 def add_defaults (self ):
128- """Adds missing sections and options to your ~/. wpmrc file."""
136+ """Adds missing sections and options to your wpmrc file."""
129137 for section , values in sorted (DEFAULTS .items ()):
130138 if not Config .config .has_section (section ):
131139 Config .config .add_section (section )
0 commit comments