|
8 | 8 | import collections |
9 | 9 | import json |
10 | 10 | import os |
| 11 | +import shutil |
11 | 12 | import sqlite3 |
12 | 13 | import tempfile |
13 | 14 | import urllib2 |
@@ -102,22 +103,25 @@ def build_all_types(cursor): |
102 | 103 |
|
103 | 104 | def main(): |
104 | 105 | temp_dir = tempfile.mkdtemp() |
105 | | - db_path = os.path.join(temp_dir, 'eve-db.sqlite') |
106 | | - print("Writing sqlite database to %s" % db_path) |
107 | | - download_database(db_path) |
108 | | - |
109 | | - print("Opening database file") |
110 | | - conn = sqlite3.connect(db_path) |
111 | | - conn.row_factory = sqlite3.Row |
112 | | - c = conn.cursor() |
113 | | - |
114 | | - print("Build type information") |
115 | | - all_types = list(build_all_types(c)) |
116 | | - |
117 | | - types_output_file = 'data/types.json' |
118 | | - print("Output types to %s" % types_output_file) |
119 | | - with open(types_output_file, 'w') as f: |
120 | | - f.write(json.dumps(all_types, indent=2)) |
| 106 | + try: |
| 107 | + db_path = os.path.join(temp_dir, 'eve-db.sqlite') |
| 108 | + print("Writing sqlite database to %s" % db_path) |
| 109 | + download_database(db_path) |
| 110 | + |
| 111 | + print("Opening database file") |
| 112 | + conn = sqlite3.connect(db_path) |
| 113 | + conn.row_factory = sqlite3.Row |
| 114 | + c = conn.cursor() |
| 115 | + |
| 116 | + print("Build type information") |
| 117 | + all_types = list(build_all_types(c)) |
| 118 | + |
| 119 | + types_output_file = 'data/types.json' |
| 120 | + print("Output types to %s" % types_output_file) |
| 121 | + with open(types_output_file, 'w') as f: |
| 122 | + f.write(json.dumps(all_types, indent=2)) |
| 123 | + finally: |
| 124 | + shutil.rmtree(temp_dir) |
121 | 125 |
|
122 | 126 |
|
123 | 127 | if __name__ == '__main__': |
|
0 commit comments