diff options
-rw-r--r-- | .gitignore | 3 | ||||
-rw-r--r-- | scripts/database/database.db | bin | 2094065 -> 0 bytes | |||
-rw-r--r-- | scripts/database/database.py | 24 |
3 files changed, 24 insertions, 3 deletions
@@ -1,4 +1,5 @@ build stash .* -*.pyc
\ No newline at end of file +*.pyc +*.db
\ No newline at end of file diff --git a/scripts/database/database.db b/scripts/database/database.db Binary files differdeleted file mode 100644 index bf793177..00000000 --- a/scripts/database/database.db +++ /dev/null diff --git a/scripts/database/database.py b/scripts/database/database.py index 66169121..758fdbab 100644 --- a/scripts/database/database.py +++ b/scripts/database/database.py @@ -15,10 +15,17 @@ import os.path import glob import re import json +try: + from urllib.request import urlopen # Python 3 +except ImportError: + from urllib2 import urlopen # Python 2 # Additional modules import pandas as pd +# Server storing a copy of the database +DATABASE_SERVER_URL = "http://www.cedricnugteren.nl/tuning/clblast.db" + # Constants VENDOR_DEFAULT = "default" DEVICETYPE_DEFAULT = "All" @@ -38,6 +45,15 @@ pd.set_option('display.width', 1000) # Database operations # ================================================================================================== +# Downloads the database and save it to disk +def DownloadDatabase(filename): + sys.stdout.write("## Downloading database from '"+DATABASE_SERVER_URL+"'...") + df = urlopen(DATABASE_SERVER_URL) + output = open(file_db,'wb') + output.write(df.read()) + output.close() + print("done") + # Loads the database from disk def LoadDatabase(filename): return pd.read_pickle(filename) @@ -221,9 +237,13 @@ if len(glob.glob(glob_json)) < 1: # The main body of the script # ================================================================================================== -# Loads the database if it exists. If not, a new database is initialized +# Downloads the database if a local copy is not present db_exists = os.path.isfile(file_db) -database = LoadDatabase(file_db) if db_exists else pd.DataFrame() +if not db_exists: + DownloadDatabase(file_db) + +# Loads the database from disk +database = LoadDatabase(file_db) # Loops over all JSON files in the supplied folder for file_json in glob.glob(glob_json): |