Constructor for the profile object. @param string name: Name of the profile, NOT the path.
(self, name, profiledir=None)
| 17 | |
| 18 | class Profile(object): |
| 19 | def __init__(self, name, profiledir=None): |
| 20 | """Constructor for the profile object. |
| 21 | @param string name: Name of the profile, NOT the path. |
| 22 | """ |
| 23 | self._log = logging.getLogger(self.__class__.__name__) |
| 24 | self.path = _getprofiledir(profiledir) |
| 25 | self.name = os.path.splitext(name)[0] # name without any extension |
| 26 | extension = '.json' |
| 27 | if not name.endswith(extension): |
| 28 | name += extension |
| 29 | path = os.path.join(self.path, name) |
| 30 | self._log.debug('{"event":"open_profile", "path":%s}', path) |
| 31 | if os.path.isfile(path): |
| 32 | with open(path) as fh: |
| 33 | try: |
| 34 | self.values = json.load(fh) |
| 35 | except Exception, e: |
| 36 | self._log.debug('profile load fail for %s on err %s', |
| 37 | os.path.abspath(path), str(e)) |
| 38 | raise e |
| 39 | else: |
| 40 | self._log.debug("no such profile file %s for %s", path, name) |
| 41 | raise IOError("no such profile file %s for %s", path, name) |
| 42 | |
| 43 | |
| 44 | def list_profiles(profiledir=None): |
nothing calls this directly
no test coverage detected