'Fill database from file, do not maintain old data
Translate the spec portions from node-dict form to spec form
Does not do any locking.'

def _read_from_file(self, stream, format='json'):

    if (format.lower() == 'json'):
        load = sjson.load
    elif (format.lower() == 'yaml'):
        load = syaml.load
    else:
        raise ValueError(('Invalid    database    format:    %s' % format))
    try:
        if isinstance(stream, string_types):
            with open(stream, 'r') as f:
                fdata = load(f)
        else:
            fdata = load(stream)
    except MarkedYAMLError as e:
        raise syaml.SpackYAMLError('error    parsing    YAML    database:', str(e))
    except Exception as e:
        raise CorruptDatabaseError('error    parsing    database:', str(e))
    if (fdata is None):
        return
    def check(cond, msg):
        if (not cond):
            raise CorruptDatabaseError(('Spack    database    is    corrupt:    %s' % msg), self._index_path)
    check(('database' in fdata), "No    'database'    attribute    in    YAML.")
    db = fdata['database']
    check(('installs' in db), "No    'installs'    in    YAML    DB.")
    check(('version' in db), "No    'version'    in    YAML    DB.")
    installs = db['installs']
    version = Version(db['version'])
    if (version > _db_version):
        raise InvalidDatabaseVersionError(_db_version, version)
    elif (version < _db_version):
        self.reindex(spack.store.layout)
        installs = dict(((k, v.to_dict()) for (k, v) in self._data.items()))
    def invalid_record(hash_key, error):
        msg = 'Invalid    record    in    Spack    database:    hash:    %s,    cause:    %s:    %s'
        msg %= (hash_key, type(e).__name__, str(e))
        raise CorruptDatabaseError(msg, self._index_path)
    data = {}
    for (hash_key, rec) in installs.items():
        try:
            spec = self._read_spec_from_dict(hash_key, installs)
            data[hash_key] = InstallRecord.from_dict(spec, rec)
        except Exception as e:
            invalid_record(hash_key, e)
    for hash_key in data:
        try:
            self._assign_dependencies(hash_key, installs, data)
        except Exception as e:
            invalid_record(hash_key, e)
    for (hash_key, rec) in data.items():
        rec.spec._mark_concrete()
    self._data = data
