vimeo / graph-explorer

A graphite dashboard powered by structured metrics
http://vimeo.github.io/graph-explorer/
Apache License 2.0
1.06k stars 93 forks source link

Ignore OSError when tring to unlink the metrics.json file. #102

Closed abhinav-upadhyay closed 10 years ago

abhinav-upadhyay commented 10 years ago

Came across an OSError when I was trying to run update_metrics.py on a newer version (current master branch) of graph-explorer. If the file is not there, update_metrics.py will always fail there, better to ignore the error in this case.

env PYTHONPATH=.. ./update_metrics.py 
2014-03-27 07:05:06,322 - update_metrics - INFO - fetching/saving metrics from graphite...
2014-03-27 07:05:06,427 - update_metrics - ERROR - sorry, something went wrong: [Errno 2] No such file or directory: 'metrics.json'
Traceback (most recent call last):
  File "./update_metrics.py", line 25, in <module>
    backend.download_metrics_json()
  File "/usr/local/graph-explorer/graph_explorer/backend.py", line 39, in download_metrics_json
    os.unlink(self.config.filename_metrics)
OSError: [Errno 2] No such file or directory: 'metrics.json'
Dieterbe commented 10 years ago

actually it looks like we don't need the unlink: with a rename, it's ok if the dest already exists. it will get overwritten. see

~/w/e/graph-explorer ❯❯❯ echo A > a; echo B > b; python2 -c "import os; os.rename('b', 'a')"
~/w/e/graph-explorer ❯❯❯ cat a
B
~/w/e/graph-explorer ❯❯❯ cat b
cat: b: No such file or directory
Dieterbe commented 10 years ago

actually what i just said is only for linux, it wouldn't work on windows http://docs.python.org/2/library/os.html#os.rename

Dieterbe commented 10 years ago

thanks!