diff options
| author | Joseph Hunkeler <jhunkeler@gmail.com> | 2015-07-07 00:21:30 -0400 | 
|---|---|---|
| committer | Joseph Hunkeler <jhunkeler@gmail.com> | 2015-07-07 00:21:30 -0400 | 
| commit | 2f54fe6ab8698b881cfca72dbe35be110234f40c (patch) | |
| tree | 3cc01f35a64d9714c71eb7941f3ea3adebe9f274 /cbc | |
| parent | 8fe362df5f58d2d51270641ae9f9fb1566352f34 (diff) | |
| download | cbc-2f54fe6ab8698b881cfca72dbe35be110234f40c.tar.gz | |
Add ~/.cbcrc configuration file
Diffstat (limited to 'cbc')
| -rw-r--r-- | cbc/environment.py | 23 | 
1 files changed, 15 insertions, 8 deletions
diff --git a/cbc/environment.py b/cbc/environment.py index a1c6b6e..0bbcd18 100644 --- a/cbc/environment.py +++ b/cbc/environment.py @@ -1,6 +1,6 @@  import os
  from .exceptions import IncompleteEnv
 -from tempfile import TemporaryDirectory
 +from configparser import ConfigParser, ExtendedInterpolation
  import time
 @@ -11,6 +11,8 @@ class Environment(object):          self.cbchome = None
          self.pwd = os.path.abspath(os.curdir)
          self.pkgdir = None
 +        self.rcpath = os.path.expanduser('~/.cbcrc')
 +        self.configrc = None
          if 'CBC_HOME' in kwargs:
              self.cbchome = kwargs['CBC_HOME']
 @@ -19,14 +21,23 @@ class Environment(object):          # passed to the class.
          if 'CBC_HOME' in self.environ:
              self.cbchome = self.environ['CBC_HOME']
 +
 +        if os.path.exists(self.rcpath):
 +            if os.path.isfile(self.rcpath):
 +                self.configrc = ConfigParser(interpolation=ExtendedInterpolation())
 +                self.configrc.read(self.rcpath)
 +        
 +        if 'settings' in self.configrc.sections():
 +            if 'path' in self.configrc['settings']:
 +                self.cbchome = self.configrc['settings']['path']
          if self.cbchome is None:
              raise IncompleteEnv('CBC_HOME is undefined.')
 -        
          self.cbchome = os.path.abspath(self.cbchome)
          if not os.path.exists(self.cbchome):
              os.makedirs(self.cbchome)
 +
      def _script_meta(self):
          self.config['script'] = {}
 @@ -48,9 +59,5 @@ class Environment(object):          self.pkgdir = pkgdir
          self._script_meta()
 -    '''
 -    def local_temp(self):
 -        temp_prefix = os.path.basename(os.path.splitext(__name__)[0])
 -        return TemporaryDirectory(prefix=temp_prefix, dir=self.cbchome)        
 -    '''     
 -        
\ No newline at end of file +
 +          | 
