Set the directory to cache JSON responses from most API endpoints.
17130
def set_cache_dir(directory):
    
    global cache_dir

    if directory is None:
        cache_dir = None
        return

    if not os.path.exists(directory):
        os.makedirs(directory)
    if not os.path.isdir(directory):
        raise ValueError("not a directory")
    cache_dir = directory
572187
def process_response(self, request, response):
        
        if not hasattr(request, 'location'):
            return response

        storage = storage_class(request=request, response=response)
        try:
            storage.set(location=request.location)
        except ValueError:
            # bad location_id
            pass
        return response
512445
def set_folder(self, folder='assets'):
        
        folder = folder.replace('/', '.')
        self._endpoint = 'files/{folder}'.format(folder=folder)
1315360
def _set_results_dir(self):
        """"""
        if self.running_instance_id:
            self.results_dir = os.path.join(
                self.results_dir,
                self.cloud,
                self.image_id,
                self.running_instance_id
            )
        else:
            self.results_dir = os.path.join(
                self.results_dir,
                self.cloud,
                self.instance_ip
            )

        try:
            os.makedirs(self.results_dir)
        except OSError as error:
            if not os.path.isdir(self.results_dir):
                raise IpaCloudException(
                    'Unable to create ipa results directory: %s' % error
                )

        self.time_stamp = datetime.now().strftime('%Y%m%d%H%M%S')
        self.log_file = ''.join(
            [self.results_dir, os.sep, self.time_stamp, '.log']
        )
        self.logger.debug('Created log file %s' % self.log_file)

        self.results_file = ''.join(
            [self.results_dir, os.sep, self.time_stamp, '.results']
        )
        self.logger.debug('Created results file %s' % self.results_file)

        # Add log file handler
        file_handler = logging.FileHandler(self.log_file)
        file_handler.setLevel(logging.DEBUG)
        file_handler.setFormatter(logging.Formatter('\n%(message)s\n'))
        self.logger.addHandler(file_handler)
597852
public function loadCacheDetails()
    {
        $cacheFile = md5($this->url);
        $this->fileName = $this->saveFolder . $cacheFile;
        $this->fileJson = $this->fileName . ".json";
        if (is_readable($this->fileJson)) {
            $this->cache = json_decode(file_get_contents($this->fileJson), true);
        }
    }
824275
def _should_cache_target_dir(self, vt):
    """"""
    return (
      self.cache_target_dirs and
      vt.cacheable and
      (not vt.is_incremental or self.cache_incremental) and
      self.artifact_cache_writes_enabled()
    )
1330269
def _cache(cpath, arg):
        '''
        
        '''
        if not os.path.isdir(cpath): os.makedirs(cpath)
        for (k,v) in six.iteritems(arg):
            save(os.path.join(cpath, k + '.pp'), v, create_directories=True, overwrite=True)
        return True
1290003
def create_cache_directories(self):
        """"""
        if not os.path.isdir(self.package_cache_dir):
            if not os.path.isdir(self.stacker_cache_dir):
                os.mkdir(self.stacker_cache_dir)
            os.mkdir(self.package_cache_dir)
958498
def set(self, key, response):
        """"""
        key = self._clean_key(key)
        path = os.path.join(self.cache_dir, key)

        with open(path, 'wb') as f:
            status_str = 'status: {0}\n'.format(response.status_code)
            f.write(status_str.encode('utf8'))
            encoding_str = 'encoding: {0}\n'.format(response.encoding)
            f.write(encoding_str.encode('utf8'))
            for h, v in response.headers.items():
                # header: value\n
                f.write(h.encode('utf8'))
                f.write(b': ')
                f.write(v.encode('utf8'))
                f.write(b'\n')
            # one blank line
            f.write(b'\n')
            f.write(response.content)
277248
def store_json(self, filename, dict_to_store):
        """"""
        filename = os.path.join(
            self.data_dir,
            filename + '.data'
        )
        fileops.dump_dict_to_file(
            dict_to_store,
            filename
        )
1025740
@Override
	public void setJsonDirOrFile(String jsonDirOrFile) {
		File file = new File(jsonDirOrFile);
		if (file.isDirectory()) configuration.setProcessConfigDir(file);
		else configuration.setProcessConfigFile(file);
	}
428283
def store_api_url(self):
        """"""
        return "%s://%s%sapi/%s/store/" % (
            self.scheme,
            self.host,
            self.path,
            self.project_id,
        )
1155586
def cache_dir() -> str:
        """"""
        if config.VENDOR is None:
            raise RuntimeError("modelforge is not configured; look at modelforge.configuration. "
                               "Depending on your objective you may or may not want to create a "
                               "modelforgecfg.py file which sets VENDOR and the rest.")
        return os.path.join("~", "." + config.VENDOR)
216972
def work_in(dirname=None):
    
    curdir = os.getcwd()
    try:
        if dirname is not None:
            os.chdir(dirname)

        requests_cache.configure(expire_after=60 * 10 * 10)
        changes.initialise()

        yield

    finally:
        os.chdir(curdir)
685951
def save_repo_cache(i):
    

    r=save_json_to_file({'json_file':work['dir_cache_repo_uoa'], 'dict':cache_repo_uoa})
    if r['return']>0: return r

    r=save_json_to_file({'json_file':work['dir_cache_repo_info'], 'dict':cache_repo_info})
    if r['return']>0: return r

    return {'return':0}
16910
def refresh_urls_and_dirs(self, urls, dirs):
        
        req = {}
        if urls is not None and len(urls) > 0:
            req.update({"urls": urls})
        if dirs is not None and len(dirs) > 0:
            req.update({"dirs": dirs})

        body = json.dumps(req)
        url = '{0}/v2/tune/refresh'.format(self.server)
        return self.__post(url, body)
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
        )