forked from david-caro/python-foreman
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes issue david-caro#67
- Loading branch information
Showing
1 changed file
with
17 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -737,24 +737,6 @@ def _get_remote_defs(self): | |
|
||
if res.ok: | ||
data = json.loads(res.text) | ||
defs_path = os.path.join(self.cache_dir, 'definitions') | ||
|
||
if not os.path.exists(defs_path): | ||
try: | ||
os.makedirs(defs_path) | ||
except: | ||
logger.debug('Unable to create cache dir %s', defs_path) | ||
return | ||
cache_fn = '%s/%s-v%s.json' % ( | ||
defs_path, self.version, | ||
self.api_version, | ||
) | ||
try: | ||
with open(cache_fn, 'w') as cache_fd: | ||
cache_fd.write(json.dumps(data, indent=4, default=str)) | ||
logger.debug('Wrote cache file %s', cache_fn) | ||
except: | ||
logger.debug('Unable to write cache file %s', cache_fn) | ||
else: | ||
if res.status_code == 404: | ||
logger.warn( | ||
|
@@ -769,6 +751,23 @@ def _get_remote_defs(self): | |
"There was an error trying to get api definition from %s/%s" | ||
% (self.url, 'apidoc/v%s.json' % self.api_version) | ||
) | ||
defs_path = os.path.join(self.cache_dir, 'definitions') | ||
|
||
if not os.path.exists(defs_path): | ||
try: | ||
os.makedirs(defs_path) | ||
except: | ||
logger.debug('Unable to create cache dir %s', defs_path) | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
jcmcken
Author
Owner
|
||
cache_fn = '%s/%s-v%s.json' % ( | ||
defs_path, self.version, | ||
self.api_version, | ||
) | ||
try: | ||
with open(cache_fn, 'w') as cache_fd: | ||
cache_fd.write(json.dumps(data, indent=4, default=str)) | ||
logger.debug('Wrote cache file %s', cache_fn) | ||
except: | ||
logger.debug('Unable to write cache file %s', cache_fn) | ||
return data | ||
|
||
def _get_defs(self, use_cache, strict_cache): | ||
|
you can do the return data here and short-circuit the file creation (if makedirs failed, for sure it will fail too)