Skip to content

Commit ed84e25

Browse files
committed
Clean up the temp directory
1 parent 88fe34f commit ed84e25

1 file changed

Lines changed: 20 additions & 16 deletions

File tree

‎tools/populate_types.py‎

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import collections
99
import json
1010
import os
11+
import shutil
1112
import sqlite3
1213
import tempfile
1314
import urllib2
@@ -102,22 +103,25 @@ def build_all_types(cursor):
102103

103104
def main():
104105
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)
121125

122126

123127
if __name__ == '__main__':

0 commit comments

Comments
 (0)