Check for version when downloading external binaries.
authorCheng Zhao <zcbenz@gmail.com>
Sun, 18 May 2014 15:42:47 +0000 (23:42 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Sun, 18 May 2014 15:42:47 +0000 (23:42 +0800)
.gitignore
script/update-external-binaries.py

index c9a7fec..1907e66 100644 (file)
@@ -1,7 +1,7 @@
 .DS_Store
 /build/
 /dist/
-/frameworks/
+/external_binaries/
 /out/
 /vendor/brightray/vendor/download/
 /vendor/python_26/
index c8045c2..5d8014f 100755 (executable)
@@ -7,20 +7,22 @@ import os
 from lib.util import safe_mkdir, extract_zip, tempdir, download
 
 
+VERSION = 'v0.0.3'
 SOURCE_ROOT = os.path.abspath(os.path.dirname(os.path.dirname(__file__)))
 FRAMEWORKS_URL = 'https://github.com/atom/atom-shell-frameworks/releases' \
-                 '/download/v0.0.3'
+                 '/download/' + VERSION
 
 
 def main():
   os.chdir(SOURCE_ROOT)
-  try:
-    os.makedirs('external_binaries')
-  except OSError as e:
-    if e.errno != errno.EEXIST:
-      raise
-    else:
-      return
+  version_file = os.path.join(SOURCE_ROOT, 'external_binaries', '.version')
+
+  safe_mkdir('external_binaries')
+  if (is_updated(version_file, VERSION)):
+    return
+
+  with open(version_file, 'w') as f:
+    f.write(VERSION)
 
   if sys.platform == 'darwin':
     download_and_unzip('Mantle')
@@ -30,6 +32,17 @@ def main():
     download_and_unzip('directxsdk')
 
 
+def is_updated(version_file, version):
+  existing_version = ''
+  try:
+    with open(version_file, 'r') as f:
+      existing_version = f.readline().strip()
+  except IOError as e:
+    if e.errno != errno.ENOENT:
+      raise
+  return existing_version == version
+
+
 def download_and_unzip(framework):
   zip_path = download_framework(framework)
   if zip_path: