Set the entire fact cache data only if the fact_cache_type is 'jsonfile'
975027
def set_fact_cache(self, host, data):
        '''
        
        '''
        if self.config.fact_cache_type != 'jsonfile':
            raise Exception('Unsupported fact cache type.  Only "jsonfile" is supported for reading and writing facts from ansible-runner')
        fact_cache = os.path.join(self.config.fact_cache, host)
        if not os.path.exists(os.path.dirname(fact_cache)):
            os.makedirs(os.path.dirname(fact_cache), mode=0o700)
        with open(fact_cache, 'w') as f:
            return f.write(json.dumps(data))
524732
def savecache(apicache, json_file):
    
    if apicache is None or apicache is {}:
        return ""
    apicachestr = json.dumps(apicache, indent=2)
    with open(json_file, 'w') as cache_file:
        cache_file.write(apicachestr)
    return apicachestr
500031
def _set_data_filelist(self,
                           start_path,
                           attr_name,
                           conn,
                           file_exts=[],
                           dir_filter=set()):
        '''  '''

        def filter_path(filter_terms, dir_path):
            """ sees if any of the terms are present in the path if so returns
                True

            args:
                filter_terms(list): terms to check
                dir_path: the path of the directory
            """
            if filter_terms.intersection(set(dir_path.split(os.path.sep))):
                return True
            else:
                return False

        data_obj = {}
        files_dict = {}
        latest_mod = 0
        dir_filter = set(dir_filter)
        for root, dirnames, filenames in os.walk(start_path):
            if not dir_filter or filter_path(dir_filter, root):
                if file_exts:
                    filenames = [x for x in filenames
                                 if x.split('.')[-1].lower() in file_exts]
                files_dict[root] = filenames
                for def_file in filenames:
                    file_mod = os.path.getmtime(os.path.join(root,def_file))
                    if file_mod > latest_mod:
                        latest_mod = file_mod
        data_obj['latest_mod'] = latest_mod
        data_obj['files'] = files_dict
        json_mod = 0
        cache_path = os.path.join(CFG.CACHE_DATA_PATH, attr_name)
        if cache_path:
            for root, dirnames, filenames in os.walk(cache_path):
                for json_file in filenames:
                    file_mod = os.path.getmtime(os.path.join(root,json_file))
                    if file_mod > json_mod:
                        json_mod = file_mod
        data_obj['last_json_mod'] = json_mod
        data_obj['conn'] = conn
        data_obj['cache_path'] = cache_path
        self.datafile_obj[attr_name] = data_obj
1271744
def data_json(self, extra_context=None, publish=False):
        
        if not self.project.CREATE_JSON:
            # nothing to see here, but the right mimetype
            return jsonify()

        if not self.data:
            # this sets site.data by spreadsheet or gdoc
            self.get_context(publish)

        return jsonify(self.data)
926576
def _only_if_file_not_exist(func_, *args, **kwargs):
    
    obj_dict = args[1]
    conn = args[-1]
    try:
        RBF.get(obj_dict[PRIMARY_FIELD]).pluck(PRIMARY_FIELD).run(conn)
        err_str = "Duplicate primary key `Name`: {}".format(obj_dict[PRIMARY_FIELD])
        err_dict = {'errors': 1,
                    'first_error':  err_str}
        return err_dict
    except r.errors.ReqlNonExistenceError:
        return func_(*args, **kwargs)
802400
def write_to_cache(self, data, filename=''):
        '''  '''
        if not filename:
            filename = self.cache_path_cache
        json_data = json.dumps(data)
        with open(filename, 'w') as cache:
            cache.write(json_data)
        return True
1252448
function(key) {
    var filepath = this._makeFilepath(key);
    if (!fs.existsSync(filepath)) {
      return;
    }

    var cache = JSON.parse(fs.readFileSync(filepath), 'UTF8');

    if (!this._cacheIsValid(cache)) {
      return this.delSync(key);
    }

    return cache.data;
  }
1025740
@Override
	public void setJsonDirOrFile(String jsonDirOrFile) {
		File file = new File(jsonDirOrFile);
		if (file.isDirectory()) configuration.setProcessConfigDir(file);
		else configuration.setProcessConfigFile(file);
	}
879741
def _set_ignored_version(version):
    
    data = {'version': version}
    with open(filepath, 'w') as data_file:
        json.dump(data, data_file)
358465
def update_cache(func):
    
    @wraps(func)
    def wrapper(self, *args, **kwargs):
        """The wrapper function."""
        lazy = kwargs.get('lazy', False)
        kwargs.pop('lazy', None)

        if not lazy:
            self.get_json()

        ret = func(self, *args, **kwargs)

        # If returning a string assume it is an update message
        if isinstance(ret, str) and not lazy:
            self.set_json(ret)
        else:
            return ret

    return wrapper
1041471
def store_json(self, filename, dict_to_store):
        """"""
        epoch = int(time.time() * (10 ** 6))
        s3_key = Key(self.bucket)
        s3_key.key = os.path.join(
            '/data',
            "%s_%s.json" % (filename, epoch)
        )
        s3_key.set_contents_from_string(
            json.dumps(dict_to_store),
            headers={'Content-Type': 'application/json; charset=UTF-8'},
            replace=True
        )
1361905
def set_file_encoding(self, path, encoding):
        
        try:
            map = json.loads(self._settings.value('cachedFileEncodings'))
        except TypeError:
            map = {}
        map[path] = encoding
        self._settings.setValue('cachedFileEncodings', json.dumps(map))
36540
def set_info_cache(self, jid, node, info):
        
        fut = asyncio.Future()
        fut.set_result(info)
        self.set_info_future(jid, node, fut)
684280
def save_data(self):
        """"""
        filename = os.path.join(
            self._get_prefix(),
            self.model.site
        )
        self.store.store_json(
            filename,
            self.model.get_dict()
        )
785809
function readJsonCached(cache, filepath, reload){
    if( reload || !cache[filepath] ) {
      cache[filepath] = grunt.file.readJSON(filepath);
    }
    return cache[filepath];
  }
264133
public function setFromStorage($json)
    {
        list($cache, $complete) = json_decode($json, true);

        if (json_last_error() === JSON_ERROR_NONE && is_array($cache) && is_array($complete)) {
            $this->cache = $cache;
            $this->complete = $complete;
        }
    }
766050
function createJsonFileDiscoverProvider(hostsFile) {
    var fs = require('fs');

    return function jsonFileProvider(callback) {
        fs.readFile(hostsFile, function onFileRead(err, data) {
            if (err) {
                callback(err);
                return;
            }

            var hosts;
            try {
                hosts = JSON.parse(data.toString());
            } catch (e) {
                callback(e);
                return;
            }
            callback(null, hosts);
            return;
        });
    };
}