chiark / gitweb /
Apply some autopep8-python2 suggestions
[fdroidserver.git] / makebuildserver
index 247741645dd826cb6ab479fe05f68c3d82501ab5..6dc317dcac9888680c7806fe34f86be4bfb3ce50 100755 (executable)
@@ -4,8 +4,10 @@ import os
 import sys
 import subprocess
 import time
+import hashlib
 from optparse import OptionParser
 
+
 def vagrant(params, cwd=None, printout=False):
     """Run vagrant.
 
@@ -17,7 +19,7 @@ def vagrant(params, cwd=None, printout=False):
                is the stdout (and stderr) from vagrant
     """
     p = subprocess.Popen(['vagrant'] + params, cwd=cwd,
-            stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
+                         stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
     out = ''
     if printout:
         while True:
@@ -36,15 +38,15 @@ serverdir = 'buildserver'
 
 parser = OptionParser()
 parser.add_option("-v", "--verbose", action="store_true", default=False,
-                      help="Spew out even more information than normal")
+                  help="Spew out even more information than normal")
 parser.add_option("-c", "--clean", action="store_true", default=False,
-                      help="Build from scratch, rather than attempting to update the existing server")
+                  help="Build from scratch, rather than attempting to update the existing server")
 options, args = parser.parse_args()
 
 config = {}
 execfile('makebs.config.py', config)
 
-if not os.path.exists('makebuildserver.py') or not os.path.exists(serverdir):
+if not os.path.exists('makebuildserver') or not os.path.exists(serverdir):
     print 'This must be run from the correct directory!'
     sys.exit(1)
 
@@ -58,44 +60,84 @@ if options.clean:
 cachedir = os.path.join('buildserver', 'cache')
 if not os.path.exists(cachedir):
     os.mkdir(cachedir)
+
 cachefiles = [
-    ('android-sdk_r22.3-linux.tgz',
-     'http://dl.google.com/android/android-sdk_r22.3-linux.tgz',
-     '4077575c98075480e0156c10e48a1521e31c7952768271a206870e6813057f4f'),
+    ('android-sdk_r24.0.1-linux.tgz',
+     'https://dl.google.com/android/android-sdk_r24.0.1-linux.tgz',
+     'bb3754524a8f6700c2898617c9d8836a987a8aa43d0e922885cd7a98ca79b281'),
+    ('gradle-1.4-bin.zip',
+     'https://services.gradle.org/distributions/gradle-1.4-bin.zip',
+     'cd99e85fbcd0ae8b99e81c9992a2f10cceb7b5f009c3720ef3a0078f4f92e94e'),
+    ('gradle-1.6-bin.zip',
+     'https://services.gradle.org/distributions/gradle-1.6-bin.zip',
+     'de3e89d2113923dcc2e0def62d69be0947ceac910abd38b75ec333230183fac4'),
+    ('gradle-1.7-bin.zip',
+     'https://services.gradle.org/distributions/gradle-1.7-bin.zip',
+     '360c97d51621b5a1ecf66748c718594e5f790ae4fbc1499543e0c006033c9d30'),
+    ('gradle-1.8-bin.zip',
+     'https://services.gradle.org/distributions/gradle-1.8-bin.zip',
+     'a342bbfa15fd18e2482287da4959588f45a41b60910970a16e6d97959aea5703'),
     ('gradle-1.9-bin.zip',
-     'http://services.gradle.org/distributions/gradle-1.9-bin.zip',
+     'https://services.gradle.org/distributions/gradle-1.9-bin.zip',
      '097ddc2bcbc9da2bb08cbf6bf8079585e35ad088bafd42e8716bc96405db98e9'),
+    ('gradle-1.10-bin.zip',
+     'https://services.gradle.org/distributions/gradle-1.10-bin.zip',
+     '6e6db4fc595f27ceda059d23693b6f6848583950606112b37dfd0e97a0a0a4fe'),
+    ('gradle-1.11-bin.zip',
+     'https://services.gradle.org/distributions/gradle-1.11-bin.zip',
+     '07e235df824964f0e19e73ea2327ce345c44bcd06d44a0123d29ab287fc34091'),
+    ('gradle-1.12-bin.zip',
+     'https://services.gradle.org/distributions/gradle-1.12-bin.zip',
+     '8734b13a401f4311ee418173ed6ca8662d2b0a535be8ff2a43ecb1c13cd406ea'),
+    ('gradle-2.1-bin.zip',
+     'https://services.gradle.org/distributions/gradle-2.1-bin.zip',
+     '3eee4f9ea2ab0221b89f8e4747a96d4554d00ae46d8d633f11cfda60988bf878'),
+    ('gradle-2.2.1-bin.zip',
+     'https://services.gradle.org/distributions/gradle-2.2.1-bin.zip',
+     '420aa50738299327b611c10b8304b749e8d3a579407ee9e755b15921d95ff418'),
     ('Kivy-1.7.2.tar.gz',
-     'http://pypi.python.org/packages/source/K/Kivy/Kivy-1.7.2.tar.gz',
-     '0485e2ef97b5086df886eb01f8303cb542183d2d71a159466f99ad6c8a1d03f1')
-    ]
+     'https://pypi.python.org/packages/source/K/Kivy/Kivy-1.7.2.tar.gz',
+     '0485e2ef97b5086df886eb01f8303cb542183d2d71a159466f99ad6c8a1d03f1'),
+]
+
 if config['arch64']:
     cachefiles.extend([
-    ('android-ndk-r9b-linux-x86_64.tar.bz2',
-     'http://dl.google.com/android/ndk/android-ndk-r9b-linux-x86_64.tar.bz2',
-     '8956e9efeea95f49425ded8bb697013b66e162b064b0f66b5c75628f76e0f532'),
-    ('android-ndk-r9b-linux-x86_64-legacy-toolchains.tar.bz2',
-     'http://dl.google.com/android/ndk/android-ndk-r9b-linux-x86_64-legacy-toolchains.tar.bz2',
-     'de93a394f7c8f3436db44568648f87738a8d09801a52f459dcad3fc047e045a1')])
+        ('android-ndk-r9b-linux-x86_64.tar.bz2',
+         'https://dl.google.com/android/ndk/android-ndk-r9b-linux-x86_64.tar.bz2',
+         '8956e9efeea95f49425ded8bb697013b66e162b064b0f66b5c75628f76e0f532'),
+        ('android-ndk-r9b-linux-x86_64-legacy-toolchains.tar.bz2',
+         'https://dl.google.com/android/ndk/android-ndk-r9b-linux-x86_64-legacy-toolchains.tar.bz2',
+         'de93a394f7c8f3436db44568648f87738a8d09801a52f459dcad3fc047e045a1')])
 else:
     cachefiles.extend([
-    ('android-ndk-r9b-linux-x86.tar.bz2',
-     'http://dl.google.com/android/ndk/android-ndk-r9b-linux-x86.tar.bz2',
-     '748104b829dd12afb2fdb3044634963abb24cdb0aad3b26030abe2e9e65bfc81'),
-    ('android-ndk-r9b-linux-x86-legacy-toolchains.tar.bz2',
-     'http://dl.google.com/android/ndk/android-ndk-r9b-linux-x86-legacy-toolchains.tar.bz2',
-     '606aadf815ae28cc7b0154996247c70d609f111b14e44bcbcd6cad4c87fefb6f')])
+        ('android-ndk-r9b-linux-x86.tar.bz2',
+         'https://dl.google.com/android/ndk/android-ndk-r9b-linux-x86.tar.bz2',
+         '748104b829dd12afb2fdb3044634963abb24cdb0aad3b26030abe2e9e65bfc81'),
+        ('android-ndk-r9b-linux-x86-legacy-toolchains.tar.bz2',
+         'https://dl.google.com/android/ndk/android-ndk-r9b-linux-x86-legacy-toolchains.tar.bz2',
+         '606aadf815ae28cc7b0154996247c70d609f111b14e44bcbcd6cad4c87fefb6f')])
 wanted = []
+
+
+def sha256_for_file(path):
+    with open(path, 'r') as f:
+        s = hashlib.sha256()
+        while True:
+            data = f.read(4096)
+            if not data:
+                break
+            s.update(data)
+        return s.hexdigest()
+
 for f, src, shasum in cachefiles:
-    if not os.path.exists(os.path.join(cachedir, f)):
+    relpath = os.path.join(cachedir, f)
+    if not os.path.exists(relpath):
         print "Downloading " + f + " to cache"
         if subprocess.call(['wget', src], cwd=cachedir) != 0:
             print "...download of " + f + " failed."
             sys.exit(1)
     if shasum:
-        p = subprocess.Popen(['shasum', '-a', '256', os.path.join(cachedir, f)],
-                stdout=subprocess.PIPE)
-        v = p.communicate()[0].split(' ')[0]
+        v = sha256_for_file(relpath)
         if v != shasum:
             print "Invalid shasum of '" + v + "' detected for " + f
             sys.exit(1)
@@ -108,12 +150,14 @@ for f, src, shasum in cachefiles:
 # Generate an appropriate Vagrantfile for the buildserver, based on our
 # settings...
 vagrantfile = """
-Vagrant::Config.run do |config|
+Vagrant.configure("2") do |config|
 
   config.vm.box = "{0}"
   config.vm.box_url = "{1}"
 
-  config.vm.customize ["modifyvm", :id, "--memory", "{2}"]
+  config.vm.provider "virtualbox" do |v|
+    v.customize ["modifyvm", :id, "--memory", "{2}"]
+  end
 
   config.vm.provision :shell, :path => "fixpaths.sh"
 """.format(config['basebox'], config['baseboxurl'], config['memory'])
@@ -135,6 +179,7 @@ vagrantfile += """
     chef.add_recipe "fdroidbuild-general"
     chef.add_recipe "android-sdk"
     chef.add_recipe "android-ndk"
+    chef.add_recipe "gradle"
     chef.add_recipe "kivy"
   end
 end
@@ -175,7 +220,7 @@ buildserverid = p.communicate()[0].strip()
 print "...ID is " + buildserverid
 subprocess.call(
     ['vagrant', 'ssh', '-c', 'sh -c "echo {0} >/home/vagrant/buildserverid"'
-    .format(buildserverid)],
+        .format(buildserverid)],
     cwd=serverdir)
 
 print "Stopping build server VM"
@@ -197,9 +242,10 @@ while not ready:
                 print "Status: " + line
 
 print "Packaging"
-vagrant(['package', '--output', os.path.join('..', boxfile)], serverdir)
+vagrant(['package', '--output', os.path.join('..', boxfile)], serverdir,
+        printout=options.verbose)
 print "Adding box"
-vagrant(['box', 'add', 'buildserver', boxfile, '-f'])
+vagrant(['box', 'add', 'buildserver', boxfile, '-f'],
+        printout=options.verbose)
 
 os.remove(boxfile)
-