diff options
Diffstat (limited to 'giscanner')
-rw-r--r-- | giscanner/cachestore.py | 20 | ||||
-rw-r--r-- | giscanner/scannermain.py | 14 |
2 files changed, 18 insertions, 16 deletions
diff --git a/giscanner/cachestore.py b/giscanner/cachestore.py index e3b76058..3512badc 100644 --- a/giscanner/cachestore.py +++ b/giscanner/cachestore.py @@ -169,12 +169,14 @@ class CacheStore(object): return None else: raise - if not self._cache_is_valid(store_filename, filename): - return None - try: - data = pickle.load(fd) - except Exception: - # Broken cache entry, remove it - self._remove_filename(store_filename) - data = None - return data + + with fd: + if not self._cache_is_valid(store_filename, filename): + return None + try: + data = pickle.load(fd) + except Exception: + # Broken cache entry, remove it + self._remove_filename(store_filename) + data = None + return data diff --git a/giscanner/scannermain.py b/giscanner/scannermain.py index f80b2cfe..957ba0b7 100644 --- a/giscanner/scannermain.py +++ b/giscanner/scannermain.py @@ -472,6 +472,10 @@ def write_output(data, options): """Write encoded XML 'data' to the filename specified in 'options'.""" if options.output == "-": output = sys.stdout + try: + output.write(data) + except IOError as e: + _error("while writing output: %s" % (e.strerror, )) elif options.reparse_validate_gir: main_f, main_f_name = tempfile.mkstemp(suffix='.gir') @@ -500,14 +504,10 @@ def write_output(data, options): return 0 else: try: - output = open(options.output, 'wb') + with open(options.output, 'wb') as output: + output.write(data) except IOError as e: - _error("opening output for writing: %s" % (e.strerror, )) - - try: - output.write(data) - except IOError as e: - _error("while writing output: %s" % (e.strerror, )) + _error("opening/writing output: %s" % (e.strerror, )) def get_source_root_dirs(options, filenames): |