Skip to content
This repository has been archived by the owner on May 29, 2018. It is now read-only.

Commit

Permalink
Use mozdownload for downloading the jenkins.war file (mozilla#685)
Browse files Browse the repository at this point in the history
  • Loading branch information
whimboo committed Nov 9, 2015
1 parent b6ae882 commit 330ed33
Showing 1 changed file with 10 additions and 28 deletions.
38 changes: 10 additions & 28 deletions start.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import os
from subprocess import check_call, CalledProcessError
import sys
import urllib2

HERE = os.path.dirname(os.path.abspath(__file__))

Expand All @@ -18,40 +17,19 @@
JENKINS_WAR = os.path.join(HERE, 'jenkins-%s.war' % JENKINS_VERSION)


def download_jenkins():
"""Downloads Jenkins.war file"""

if os.path.isfile(JENKINS_WAR):
print "Jenkins already downloaded"
else:
print "Downloading Jenkins %s from %s" % (JENKINS_VERSION, JENKINS_URL)
# Download starts
tmp_file = JENKINS_WAR + ".part"

while True:
try:
r = urllib2.urlopen(JENKINS_URL)
CHUNK = 16 * 1024
with open(tmp_file, 'wb') as f:
for chunk in iter(lambda: r.read(CHUNK), ''):
f.write(chunk)
break
except (urllib2.HTTPError, urllib2.URLError):
print "Download failed."
raise
os.rename(tmp_file, JENKINS_WAR)


if __name__ == "__main__":
download_jenkins()

def main():
try:
execfile(JENKINS_ENV, dict(__file__=JENKINS_ENV))
print "Virtual environment activated successfully."
except Exception as ex:
print 'Could not activate virtual environment at "%s": %s.' % (JENKINS_ENV, str(ex))
sys.exit(1)

# Download the Jenkins WAR file
from mozdownload import DirectScraper
scraper = DirectScraper(url=JENKINS_URL, destination=JENKINS_WAR)
scraper.download()

# TODO: Start Jenkins as daemon
print "Starting Jenkins"
os.environ['JENKINS_HOME'] = os.path.join(HERE, 'jenkins-master')
Expand All @@ -61,3 +39,7 @@ def download_jenkins():
check_call(args)
except CalledProcessError as e:
sys.exit(e.returncode)


if __name__ == "__main__":
main()

0 comments on commit 330ed33

Please sign in to comment.