Exemplo n.º 1
0
 def __init__(self, path):
     ''' Initialise a yamlfile object '''
     if not os.path.isfile(path):
         raise NotFoundError('No such file: %s' % path)
     if not os.access(path, os.R_OK):
         raise NotFoundError('Cannot open: %s' % path)
     self._path = path
     self._data = dict()
     self._read()
Exemplo n.º 2
0
 def __init__(self, path, fileclass=None):
     ''' Initialise a directory object '''
     if not os.path.isdir(path):
         raise NotFoundError('No such directory: %s' % path)
     if not os.access(path, os.R_OK | os.X_OK):
         raise NotFoundError('Cannot change to or read directory: %s' %
                             path)
     self._path = path
     self._fileclass = fileclass
     self._files = {}
Exemplo n.º 3
0
 def from_file(cls, path):
     ''' Initialise yaml data from a local file '''
     abs_path = os.path.abspath(path)
     if not os.path.isfile(abs_path):
         raise NotFoundError('No such file: %s' % abs_path)
     if not os.access(abs_path, os.R_OK):
         raise NotFoundError('Cannot open: %s' % abs_path)
     y = cls('yaml_fs://{0}'.format(abs_path))
     with open(abs_path) as fp:
         data = yaml.load(fp, Loader=_SafeLoader)
         if data is not None:
             y._data = data
     return y
Exemplo n.º 4
0
 def from_file(cls, path):
     ''' Initialise yaml data from a local file '''
     if not os.path.isfile(path):
         raise NotFoundError('No such file: %s' % path)
     if not os.access(path, os.R_OK):
         raise NotFoundError('Cannot open: %s' % path)
     y = cls('yaml_fs://{0}'.format(path))
     fp = file(path)
     data = yaml.safe_load(fp)
     if data is not None:
         y._data = data
     fp.close()
     return y