]> khamidou — GitHub mirrors - electron.git/commitdiff
Rewrite update-frameworks script in python.
authorCheng Zhao <zcbenz@gmail.com>
Thu, 20 Jun 2013 15:23:22 +0000 (23:23 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Thu, 20 Jun 2013 15:23:22 +0000 (23:23 +0800)
script/lib/util.py
script/update
script/update-frameworks [deleted file]
script/update-frameworks.py [new file with mode: 0755]

index 51ca69dc378e0fa3a391dc199ccc30362f452820..f4f42be926c7431ae7a2463b8280f68d3d9330cd 100644 (file)
@@ -7,6 +7,7 @@ import tarfile
 import tempfile
 import urllib2
 import os
+import zipfile
 
 
 def tempdir(prefix=''):
@@ -37,9 +38,14 @@ def download(text, url, path):
     print
 
 
-def extract_tarball(tarball_path, member, path):
+def extract_tarball(tarball_path, member, destination):
   with tarfile.open(tarball_path) as tarball:
-    tarball.extract(member, path)
+    tarball.extract(member, destination)
+
+
+def extract_zip(zip_path, destination):
+  with zipfile.ZipFile(zip_path) as z:
+    z.extractall(destination)
 
 
 def safe_unlink(path):
index c441f4463ae4d82382bfb5772ddf237f8f6fd973..89ddc0673f6437551e8cee8237b7640005283291 100755 (executable)
@@ -4,7 +4,7 @@ set -e
 
 cd "$(dirname "$0")/.."
 
-./script/update-frameworks
+./script/update-frameworks.py
 ./script/update-node.py --version v0.10.9
 
 gyp -f ninja --depth . atom.gyp \
diff --git a/script/update-frameworks b/script/update-frameworks
deleted file mode 100755 (executable)
index 38656af..0000000
+++ /dev/null
@@ -1,23 +0,0 @@
-#!/bin/bash
-
-cd "$(dirname $0)/.."
-
-. script/lib/polite-curl
-
-[ -d frameworks ] || mkdir frameworks
-cd frameworks
-
-FRAMEWORKS_URL='https://gh-contractor-zcbenz.s3.amazonaws.com/frameworks'
-
-trap 'rm -f *.zip' EXIT
-
-function download_and_unzip() {
-  if ! [ -d $1.framework ]; then
-    echo "Downloading $1..."
-    polite_curl "$FRAMEWORKS_URL/$1.framework.zip" > $1.framework.zip
-    unzip $1.framework.zip
-  fi
-}
-
-download_and_unzip Quincy
-download_and_unzip Sparkle
diff --git a/script/update-frameworks.py b/script/update-frameworks.py
new file mode 100755 (executable)
index 0000000..55f2fc9
--- /dev/null
@@ -0,0 +1,41 @@
+#!/usr/bin/env python
+
+import sys
+import os
+
+from lib.util import *
+
+
+SOURCE_ROOT = os.path.dirname(os.path.dirname(__file__))
+FRAMEWORKS_URL='https://gh-contractor-zcbenz.s3.amazonaws.com/frameworks'
+
+
+def main():
+  os.chdir(SOURCE_ROOT)
+  safe_mkdir('frameworks')
+  download_and_unzip('Quincy')
+  download_and_unzip('Sparkle')
+
+
+def download_and_unzip(framework):
+  zip_path = download_framework(framework)
+  if zip_path:
+    extract_zip(zip_path, 'frameworks')
+
+
+def download_framework(framework):
+  framework_path = os.path.join('frameworks', framework) + '.framework'
+  if os.path.exists(framework_path):
+    return
+
+  filename = framework + '.framework.zip'
+  url = FRAMEWORKS_URL + '/' + filename
+  download_dir = tempdir(prefix='atom-shell-')
+  path = os.path.join(download_dir, filename)
+
+  download('Download ' + framework, url, path)
+  return path
+
+
+if __name__ == '__main__':
+  sys.exit(main())