Bump for 3.6-28
[LibreOffice.git] / smoketest / lodownloadtest.py
blob91d32fc775103541d033ac05289f2ee224308d03
1 #!/usr/bin/env python
3 # Version: MPL 1.1 / GPLv3+ / LGPLv3+
5 # The contents of this file are subject to the Mozilla Public License Version
6 # 1.1 (the "License"); you may not use this file except in compliance with
7 # the License or as specified alternatively below. You may obtain a copy of
8 # the License at http://www.mozilla.org/MPL/
10 # Software distributed under the License is distributed on an "AS IS" basis,
11 # WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 # for the specific language governing rights and limitations under the
13 # License.
15 # Major Contributor(s):
16 # [ Copyright (C) 2011 Yifan Jiang <yfjiang@suse.com> (initial developer) ]
17 # [ Copyright (C) 2011 Petr Mladek <pmladek@suse.cz> ]
19 # All Rights Reserved.
21 # For minor contributions see the git repository.
23 # Alternatively, the contents of this file may be used under the terms of
24 # either the GNU General Public License Version 3 or later (the "GPLv3+"), or
25 # the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
26 # in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
27 # instead of those above.
29 # The tool is designed to enable test machine fully automatically run smoketest
30 # with both daily and pre release build located in dev-build.libreoffice.org.
32 # The tool is named as losmoketest for its purpose, meanwhile it help you to
33 # check, download and install the latest build. By the fact the installation is
34 # designed not to be different from manually doing these repeated work, the
35 # installed libreoffice build can also be good for manual test.
37 import sys, os, platform
38 import datetime, time
39 import subprocess, shutil
40 import glob, re
41 import urllib, urllib2
42 import logging, getopt
43 try:
44 import ConfigParser as configparser # Python 3.0 change
45 except ImportError:
46 import configparser
48 # FIXME: make this configurable via options or autodetect it
49 build_version = "3.5"
50 tag_version = "3-5"
51 # devel build
52 branding_pack="lodev"
53 basis_pack="lodevbasis"
54 # stable build
55 #branding_pack="libreoffice"
56 #basis_pack="libobasis"
58 # possible program files of libreoffice, put all platform paths are
59 # expected in this list
60 lo_all_paths = [
61 "/opt/lodev" + build_version, \
62 "/opt/libreoffice" + build_version, \
63 "/usr/lib/libreoffice", \
64 "/usr/lib64/libreoffice", \
65 "C:\program file\libreoffice", \
68 build_check_interval = 5 #seconds
70 # Distro list
71 RPM_DISTRO_LIST = ['SuSE', 'fedora', 'redhat', 'centos', 'mandrake', 'mandriva', 'yellowdog', 'turbolinux']
72 DEB_DISTRO_LIST = ['debian', 'ubuntu', 'Ubuntu']
74 # Server urls
75 SERVER_URL = "http://dev-builds.libreoffice.org"
77 # Local dirs
78 root_dir = os.getcwd()
79 DOWNLOAD_DIR = os.path.join(root_dir, "_download")
80 USR_DIR = os.path.join(root_dir, "_libo_smoke_user")
81 LOCAL_BUILD_INFO_FILE = os.path.join(root_dir, "build.cfg")
83 # INSTALL_DIR = os.path.join(root_dir, "_libo_smoke_installation")
84 INSTALL_DIR = "" # Installation dir
86 # SOFFICE_BIN bin
87 if platform.system() == "Linux":
88 SOFFICE_BIN = "soffice"
89 LOSMOKETEST_BIN = "losmoketest"
90 elif platform.system() == "Windows":
91 SOFFICE_BIN = "soffice.exe"
92 LOSMOKETEST_BIN = "losmoketest"
93 else:
94 SOFFICE_BIN = "soffice"
95 LOSMOKETEST_BIN = "losmoketest"
97 # Relative build url
98 ## pre-releases
99 PR_RPM_X86_PATH = "pre-releases/rpm/x86/"
100 PR_RPM_X86_64_PATH = "pre-releases/rpm/x86_64/"
102 PR_DEB_X86_PATH = "pre-releases/deb/x86/"
103 PR_DEB_X86_64_PATH = "pre-releases/deb/x86_64/"
105 PR_MAC_X86_PATH = "pre-releases/mac/x86/"
106 PR_MAC_PPC_PATH = "pre-releases/mac/ppc/"
108 PR_WIN_X86_PATH = "pre-releases/win/x86/"
110 ## daily_master
111 DAILY_MASTER_RPM_X86_PATH = "daily/Linux-x86_10-Release_Configuration/master/current"
112 DAILY_MASTER_RPM_X86_64_PATH = "daily/Linux-x86_64_11-Release_Configuration/master/current"
114 DAILY_MASTER_DEB_X86_PATH = "daily/Linux-x86_10-Release_Configuration/master/current"
115 DAILY_MASTER_DEB_X86_64_PATH = "daily/Linux-x86_64_11-Release_Configuration/master/current"
117 DAILY_MASTER_MAC_X86_PATH = "daily/MacOSX-Intel@3-OSX_10.6.0-gcc_4.0.1/master/current"
118 DAILY_MASTER_MAC_PPC_PATH = "daily/MacOSX-PPC@12-OSX_10.5.0-gcc_4.0.1/master/current" # No build yet
120 DAILY_MASTER_WIN_X86_PATH = "daily/Win-x86@7-MinGW/master/current" # cross compling build
122 ## daily_branch
123 DAILY_BRANCH_RPM_X86_PATH = "daily/Linux-x86_10-Release_Configuration/libreoffice-" + tag_version + "/current"
124 DAILY_BRANCH_RPM_X86_64_PATH = "daily/Linux-x86_64_11-Release_Configuration/libreoffice-" + tag_version + "/current"
126 DAILY_BRANCH_DEB_X86_PATH = "daily/Linux-x86_10-Release_Configuration/libreoffice-" + tag_version + "/current"
127 DAILY_BRANCH_DEB_X86_64_PATH = "daily/Linux-x86_64_11-Release_Configuration/libreoffice-" + tag_version + "/current"
129 DAILY_BRANCH_MAC_X86_PATH = "daily/MacOSX-Intel@3-OSX_10.6.0-gcc_4.0.1/libreoffice-" + tag_version + "/current"
130 DAILY_BRANCH_MAC_PPC_PATH = "daily/MacOSX-PPC@12-OSX_10.5.0-gcc_4.0.1/libreoffice-" + tag_version + "/current"
132 DAILY_BRANCH_WIN_X86_PATH = "daily/Win-x86@7-MinGW/libreoffice-" + tag_version + "/current"
136 def platform_info():
138 s = platform.system()
139 arch_name = platform.machine()
141 if arch_name in ['x86', 'i386', 'i586', 'i686']:
142 arch_name = 'x86'
144 if s == "Linux":
145 if platform.dist()[0] in RPM_DISTRO_LIST:
146 distro_name = platform.dist()[0]
147 pck_name = 'rpm'
148 elif platform.dist()[0] in DEB_DISTRO_LIST:
149 distro_name = platform.dist()[0]
150 pck_name = 'deb'
151 elif s == "Windows":
152 distro_name = platform.dist()[0]
153 pck_name = 'exe'
154 else:
155 distro_name = platform.dist()[0]
156 pck_name = 'dmg'
158 return distro_name, pck_name, arch_name
160 def local_build_info(t):
162 if not os.path.exists(LOCAL_BUILD_INFO_FILE):
163 logger.error("Can't find the file: " + LOCAL_BUILD_INFO_FILE)
164 sys.exit()
166 config = configparser.RawConfigParser()
167 config.read(LOCAL_BUILD_INFO_FILE)
169 try:
170 build_name = config.get(t, 'build_name').strip('\n')
171 build_time = datetime.datetime.strptime(config.get(t, 'build_time').strip('\n'), '%d-%b-%Y %H:%M')
172 except ValueError:
173 build_name = ''
174 build_time = datetime.datetime.min
176 try:
177 testpack_name = config.get(t, 'testpack_name').strip('\n')
178 testpack_build_time = datetime.datetime.strptime(config.get(t, 'testpack_build_time').strip('\n'), '%d-%b-%Y %H:%M')
179 except ValueError:
180 testpack_name = ''
181 testpack_build_time = datetime.datetime.min
183 return build_name, build_time, testpack_name, testpack_build_time
185 def get_url_regexp(t, package, arch):
187 return a url containing download links, i.e:
189 http://dev-builds.libreoffice.org/pre-releases/rpm/x86_64/
190 http://dev-builds.libreoffice.org/daily/Windows_Release_Configuration/libreoffice-3-4/current/
191 http://dev-builds.libreoffice.org/daily/Linux_x86_Release_Configuration/libreoffice-3-4/current/
193 meanwhile return a regexp object that matching corresponding downloadable
194 package and its timestamp '''
196 url = ""
197 reg_lo = re.compile('^$')
198 reg_tst = re.compile('^$')
199 pck = package
200 arc = arch
202 if t == 'pre-releases':
203 if pck == "rpm" and arc == "x86":
204 url = SERVER_URL + "/" + PR_RPM_X86_PATH
205 reg_lo = re.compile('\<a\ href=\"(LibO_\d.*x86_install-rpm.*en-US.*\.gz)\".*(\d{2}\-[a-zA-Z]{3}\-\d{4}).*(\d{2}:\d{2}).*')
206 reg_tst = re.compile('\<a\ href=\"(LibO-Test.*.gz)\".*(\d{2}\-[a-zA-Z]{3}\-\d{4}).*(\d{2}:\d{2}).*')
207 elif pck == "rpm" and arc == "x86_64":
208 url = SERVER_URL + "/" + PR_RPM_X86_64_PATH
209 reg_lo = re.compile('\<a\ href=\"(LibO_\d.*x86-64_install-rpm.*en-US.*\.gz)\".*(\d{2}\-[a-zA-Z]{3}\-\d{4}).*(\d{2}:\d{2}).*')
210 reg_tst = re.compile('\<a\ href=\"(LibO-Test.*.gz)\".*(\d{2}\-[a-zA-Z]{3}\-\d{4}).*(\d{2}:\d{2}).*')
211 elif pck == "deb" and arc == "x86":
212 url = SERVER_URL + "/" + PR_DEB_X86_PATH
213 reg_lo = re.compile('\<a\ href=\"(LibO_\d.*x86_install-deb.*en-US.*\.gz)\".*(\d{2}\-[a-zA-Z]{3}\-\d{4}).*(\d{2}:\d{2}).*')
214 elif pck == "deb" and arc == "x86_64":
215 url = SERVER_URL + "/" + PR_DEB_X86_64_PATH
216 reg_lo = re.compile('\<a\ href=\"(LibO_\d.*x86-64_install-deb.*en-US.*\.gz)\".*(\d{2}\-[a-zA-Z]{3}\-\d{4}).*(\d{2}:\d{2}).*')
217 elif pck == "exe" and arc == "x86":
218 url = SERVER_URL + "/" + PR_WIN_X86_PATH
219 reg_lo = re.compile('\<a\ href=\"(LibO_\d.*Win_x86_install_multi.exe)\".*(\d{2}\-[a-zA-Z]{3}\-\d{4}).*(\d{2}:\d{2}).*')
220 elif pck == "dmg" and arc == "x86":
221 url = SERVER_URL + "/" + PR_MAC_X86_PATH
222 reg_lo = re.compile('\<a\ href=\"(LibO_\d.*MacOS_x86_install_en-US.dmg)\".*(\d{2}\-[a-zA-Z]{3}\-\d{4}).*(\d{2}:\d{2}).*')
223 elif pck == "dmg" and arc == "ppc":
224 url = SERVER_URL + "/" + PR_MAC_PPC_PATH
225 reg_lo = re.compile('\<a\ href=\"(LibO_\d.*MacOS_PPC_install_en-US.dmg)\".*(\d{2}\-[a-zA-Z]{3}\-\d{4}).*(\d{2}:\d{2}).*')
226 else:
227 logger.error("Unable to handle the system or arch!")
228 elif t == 'daily_master':
229 if pck == "rpm" and arc == "x86":
230 url = SERVER_URL + "/" + DAILY_MASTER_RPM_X86_PATH
231 reg_lo = re.compile('\<a\ href=\"(master\~\d.*LibO-Dev_.*x86_install-rpm_en-US.tar.gz)\".*(\d{2}\-[a-zA-Z]{3}\-\d{4}).*(\d{2}:\d{2}).*')
232 elif pck == "rpm" and arc == "x86_64":
233 url = SERVER_URL + "/" + DAILY_MASTER_RPM_X86_64_PATH
234 reg_lo = re.compile('\<a\ href=\"(master\~\d.*LibO-Dev_.*x86-64_install-rpm_en-US.tar.gz)\".*(\d{2}\-[a-zA-Z]{3}\-\d{4}).*(\d{2}:\d{2}).*')
235 elif pck == "deb" and arc == "x86":
236 url = SERVER_URL + "/" + DAILY_MASTER_DEB_X86_PATH
237 reg_lo = re.compile('\<a\ href=\"(master\~\d.*LibO-Dev_.*x86_install-deb_en-US.tar.gz)\".*(\d{2}\-[a-zA-Z]{3}\-\d{4}).*(\d{2}:\d{2}).*')
238 elif pck == "deb" and arc == "x86_64":
239 url = SERVER_URL + "/" + DAILY_MASTER_DEB_X86_64_PATH
240 reg_lo = re.compile('^$') # No build yet
241 elif pck == "exe" and arc == "x86":
242 url = SERVER_URL + "/" + DAILY_MASTER_WIN_X86_PATH
243 reg_lo = re.compile('^$') # No build yet
244 elif pck == "dmg" and arc == "x86":
245 url = SERVER_URL + "/" + DAILY_MASTER_MAC_X86_PATH
246 reg_lo = re.compile('\<a\ href=\"(master\~\d.*LibO-Dev_.*x86_install_en-US.dmg)\".*(\d{2}\-[a-zA-Z]{3}\-\d{4}).*(\d{2}:\d{2}).*')
247 elif pck == "dmg" and arc == "ppc":
248 url = SERVER_URL + "/" + DAILY_MASTER_MAC_PPC_PATH
249 reg_lo = re.compile('^$') # No build yet
250 else:
251 logger.error("Unable to handle the system or arch!")
252 elif t == 'daily_branch':
253 if pck == "rpm" and arc == "x86":
254 url = SERVER_URL + "/" + DAILY_BRANCH_RPM_X86_PATH
255 reg_lo = re.compile('\<a\ href=\"(.*LibO_.*x86_install-rpm_en-US\.tar\.gz)\".*(\d{2}\-[a-zA-Z]{3}\-\d{4}).*(\d{2}:\d{2}).*')
256 elif pck == "rpm" and arc == "x86_64":
257 url = SERVER_URL + "/" + DAILY_BRANCH_RPM_X86_64_PATH
258 reg_lo = re.compile('\<a\ href=\"(.*LibO_.*x86-64_install-rpm_en-US\.tar\.gz)\".*(\d{2}\-[a-zA-Z]{3}\-\d{4}).*(\d{2}:\d{2}).*')
259 elif pck == "deb" and arc == "x86":
260 url = SERVER_URL + "/" + DAILY_BRANCH_DEB_X86_PATH
261 reg_lo = re.compile('\<a\ href=\"(.*LibO_.*x86_install-deb_en-US\.tar\.gz)\".*(\d{2}\-[a-zA-Z]{3}\-\d{4}).*(\d{2}:\d{2}).*')
262 elif pck == "deb" and arc == "x86_64":
263 url = SERVER_URL + "/" + DAILY_BRANCH_DEB_X86_64_PATH
264 reg_lo = re.compile('\<a\ href=\"(.*LibO_.*x86-64_install-deb_en-US\.tar\.gz)\".*(\d{2}\-[a-zA-Z]{3}\-\d{4}).*(\d{2}:\d{2}).*')
265 elif pck == "exe" and arc == "x86":
266 url = SERVER_URL + "/" + DAILY_BRANCH_WIN_X86_PATH
267 reg_lo = re.compile('\<a\ href=\"(.*LibO_.*install_.*\.exe)\".*(\d{2}\-[a-zA-Z]{3}\-\d{4}).*(\d{2}:\d{2}).*')
268 elif pck == "dmg" and arc == "x86":
269 url = SERVER_URL + "/" + DAILY_BRANCH_MAC_X86_PATH
270 reg_lo = re.compile('^$') # No build yet
271 elif pck == "dmg" and arc == "ppc":
272 url = SERVER_URL + "/" + DAILY_BRANCH_MAC_PPC_PATH
273 reg_lo = re.compile('^$') # No build yet
274 else:
275 logger.error("Unable to handle the system or arch!")
276 else:
277 logger.error("Error build type! The build type has to be:\n pre-releases, daily_master, daily_branch")
279 return url, reg_lo, reg_tst
281 def remote_build_info(url_reg):
282 ''' Get the latest proper build info (build_name, build_time) from
283 url. '''
285 p = platform_info()
286 pck = p[1]
287 arc = p[2]
288 r = url_reg[1]
289 r_t = url_reg[2]
291 f = urllib2.urlopen(url_reg[0])
292 c = ''.join(f.readlines())
293 f.close()
295 build_list = r.findall(c)
296 test_list = r_t.findall(c)
298 build_name = ''
299 build_time = datetime.datetime.min
300 testpack_build_time = datetime.datetime.min
301 testpack_name = ''
304 for b in build_list:
305 if datetime.datetime.strptime(b[1] + ' ' + b[2], '%d-%b-%Y %H:%M') > build_time:
306 build_name = b[0]
307 try:
308 build_time = datetime.datetime.strptime(b[1] + ' ' + b[2], '%d-%b-%Y %H:%M')
309 except:
310 print "remote_build_info: wrong time date&format"
312 for t in test_list:
313 if datetime.datetime.strptime(t[1] + ' ' + t[2], '%d-%b-%Y %H:%M') > testpack_build_time:
314 testpack_name = t[0]
315 try:
316 testpack_build_time = datetime.datetime.strptime(t[1] + ' ' + t[2], '%d-%b-%Y %H:%M')
317 except:
318 print "remote_build_info: wrong time date&format"
320 return build_name, build_time, testpack_name, testpack_build_time
322 # return True when something was downloaded
323 def download(url_reg, build_type):
324 logger.info('Checking new build ...')
326 try:
327 remote_build = remote_build_info(url_reg)
328 local_build = local_build_info(build_type)
330 if remote_build[1] > local_build[1]:
331 logger.info('Found New LO build: ' + remote_build[0])
332 if fetch_build(url_reg[0], remote_build[0]):
333 set_build_config(build_type, 'build_name', remote_build[0])
334 set_build_config(build_type, 'build_time', datetime.datetime.strftime(remote_build[1], '%d-%b-%Y %H:%M'))
335 else:
336 logger.error('Download libreoffice build failed!')
338 if remote_build[3] > local_build[3] and (remote_build[1] - remote_build[3]) < datetime.timedelta(hours=1):
339 logger.info('Found a relevant smoketest package: ' + remote_build[2])
340 if fetch_build(url_reg[0], remote_build[2]):
341 set_build_config(build_type, 'testpack_name', remote_build[2])
342 set_build_config(build_type, 'testpack_build_time', datetime.datetime.strftime(remote_build[3], '%d-%b-%Y %H:%M'))
343 return True
344 else:
345 logger.warning("Failed to find corresponding smoketest package")
347 except urllib2.URLError, HTTPError:
348 logger.error('Error fetch remote build info.')
349 return False
350 except KeyboardInterrupt:
351 sys.exit()
352 except:
353 logger.error('Error fetch remote build info.')
354 return False
356 return False
358 def fetch_build(url, filename):
359 ''' Download a build from address url/filename '''
361 logger.info("Downloading ... " + filename)
363 u = urllib2.urlopen(url + '/' + filename)
365 try:
366 f = open(DOWNLOAD_DIR + '/' + filename, 'wb')
367 f.write(u.read())
368 f.close()
369 except urllib2.HTTPError, e:
370 print "HTTP Error:",e.code , url
371 except urllib2.URLError, e:
372 print "URL Error:",e.reason , url
374 return True
376 def set_build_config(section, option, value):
378 config = configparser.RawConfigParser()
379 config.readfp(open(LOCAL_BUILD_INFO_FILE))
380 config.set(section, option, value)
381 with open(LOCAL_BUILD_INFO_FILE, 'wb') as cfgfile:
382 config.write(cfgfile)
384 def uninstall(build_type):
385 ''' Kill libreoffice processes and uninstall all previously installed
386 libreoffice packages '''
388 if build_type == "pre-releases":
389 branding_pack="libreoffice"
390 basis_pack="libobasis"
392 logger.info("Uninstalling ...")
394 pck = platform_info()[1]
396 if pck == 'rpm':
397 cmd_query = ["rpm", "-qa"]
398 cmd_filter = ["grep", \
399 "-e", branding_pack+build_version, \
400 "-e", basis_pack+build_version, \
403 P_query = subprocess.Popen(cmd_query, stdout = subprocess.PIPE)
404 P_filter = subprocess.Popen(cmd_filter, stdin = P_query.stdout, stdout = subprocess.PIPE)
405 P_query.stdout.close() # protection when P_filter exit before P_query
406 str_filter = P_filter.communicate()[0]
408 if str_filter == "":
409 logger.warning("Nothing to uninstall")
410 return
411 else:
412 cmd = ["sudo", "rpm", "-e"] + str_filter.split()
413 elif pck == 'deb':
414 cmd_query = ["dpkg", "--get-selections", branding_pack+build_version+"*", basis_pack+build_version+"*"]
415 cmd_filter = ["cut", "-f", "1"]
417 P_query = subprocess.Popen(cmd_query, stdout = subprocess.PIPE)
418 P_filter = subprocess.Popen(cmd_filter, stdin = P_query.stdout, stdout = subprocess.PIPE)
419 P_query.stdout.close()
420 str_filter = P_filter.communicate()[0]
422 if str_filter == "":
423 logger.warning("Nothing to uninstall")
424 return
425 else:
426 cmd = ["sudo", "dpkg ", "-P"] + str_filter.split()
427 elif pck == 'exe':
428 pass
429 elif pck == 'dmg':
430 pass
431 else:
432 logger.warning("Non supported package system")
434 subprocess.check_call(cmd)
436 def init_testing():
437 logger.info("Initializing ...")
439 post_testing()
441 if not os.path.exists(DOWNLOAD_DIR):
442 os.mkdir(DOWNLOAD_DIR)
444 if not os.path.exists(USR_DIR):
445 os.mkdir(USR_DIR)
447 if not os.path.exists(LOCAL_BUILD_INFO_FILE):
449 init_build_cfg = '[daily_branch]' + os.linesep\
450 + 'build_name =' + os.linesep\
451 + 'build_time =' + os.linesep\
452 + 'testpack_name =' + os.linesep\
453 + 'testpack_build_time =' + os.linesep\
454 + '[daily_master]' + os.linesep\
455 + 'build_name =' + os.linesep\
456 + 'build_time =' + os.linesep\
457 + 'testpack_name =' + os.linesep\
458 + 'testpack_build_time =' + os.linesep\
459 + '[pre-releases]' + os.linesep\
460 + 'build_name =' + os.linesep\
461 + 'build_time =' + os.linesep \
462 + 'testpack_name =' + os.linesep\
463 + 'testpack_build_time =' + os.linesep
465 with open(LOCAL_BUILD_INFO_FILE, 'w+') as f:
466 f.write(init_build_cfg)
467 f.close()
469 def post_testing():
470 logger.info("Cleaning up ...")
472 # clean up the extracted installer dir
473 for r in os.walk(DOWNLOAD_DIR):
474 if r[0] == DOWNLOAD_DIR:
475 for d in r[1]:
476 shutil.rmtree(os.path.join(r[0], d))
478 def install(filename):
479 ''' filename: local file path of tar.gz, dmg or exe. The script will
480 extract the package and then install it '''
482 logger.info("Installing ... " + filename)
484 def _is_not_filtered(s):
485 ''' True if the package s is not intended to installed. '''
486 filter_pattern_list = ['.*kde.*', '.*gnome.*', '.*desktop.*', '!.*\.rpm$', '!.*\.deb$']
487 for p in filter_pattern_list:
488 r = re.compile(p)
489 if r.match(s):
490 return False
491 return True
493 fn, ext = os.path.splitext(filename)
494 pcklist = []
496 if ext == '.exe':
497 # extract
498 installer_dir = os.path.join(DOWNLOAD_DIR, filename.strip(ext))
499 subprocess.check_call([filename, '/EXTRACTONLY=ON', '/S', '/D='+installer_dir])
500 # install
501 installer = glob.glob(os.path.join(installer_dir, 'libreoffice*msi'))[0]
502 subprocess.check_call(['msiexec', '-i', installer, '-passive', 'ADDLOCAL=all'])
503 elif ext == '.dmg':
504 return
505 elif ext == '.gz':
506 # extract
507 subprocess.check_call(['tar', 'xzf', filename, '-C', DOWNLOAD_DIR])
509 # get a filtered install list
510 for root, dirs, files in os.walk(DOWNLOAD_DIR):
511 if 'RPMS' in root or 'DEBS' in root:
512 pcklist = pcklist + [os.path.join(root_dir, root, f) for f in files]
513 install_pcklist = filter(_is_not_filtered, pcklist)
515 # install
516 if platform_info()[1] == 'rpm':
517 install_cmd = ["sudo", "rpm", "-iv"] + install_pcklist
518 clean_tmp_cmd = ["sudo", "rm", "-f"] + pcklist
519 elif platform_info()[1] == 'deb':
520 install_cmd = ["sudo", "dpkg", "-i"] + install_pcklist
521 else:
522 logger.error('Cannot generate install command')
523 return
525 subprocess.check_call(install_cmd)
526 subprocess.check_call(clean_tmp_cmd)
528 else:
529 logger.info("Unrecognized file extension")
531 def verify_smoketest(headless):
532 logger.info("Testing ...")
534 s = platform.system()
535 p = platform_info()
536 pck = p[1]
537 arc = p[2]
539 lo_testable_paths = filter(lambda p: \
540 os.path.exists(p + os.sep + "program" + os.sep + LOSMOKETEST_BIN) and \
541 os.path.exists(p + os.sep + "program" + os.sep + SOFFICE_BIN), \
542 lo_all_paths)
544 if not lo_testable_paths:
545 logger.error("Not found any Libreoffice or Test packages!")
546 sys.exit(1)
547 else:
548 cmd_smoketests = [ p + os.sep + "program" + os.sep + LOSMOKETEST_BIN for p in lo_testable_paths ]
550 if len(lo_testable_paths) > 1:
551 logger.info("++More than one testable build is found, test them one by one.")
553 # subprocess.call(cmd_smoketest);
554 for c in cmd_smoketests:
555 pattern = re.compile(LOSMOKETEST_BIN + "$")
556 logger.info(" Test Binary: " + pattern.sub(SOFFICE_BIN, c))
557 subprocess.call(c)
559 def usage():
561 print "\n[Usage]\n\n -f Force testing without asking \n\
562 -t Testing type pre-release/daily \n\
563 -l Download and test last builds in a loop \n\
564 -v Run smoketest verification directly \n\
565 -s Use the headless mode when running the tests \n\
566 -i Install the latest build in the DOWNLOAD directory \n\
567 -u Uninstall any existed libreoffice build \n\
568 -d Download the latest build for the given test type \n\
571 def main():
573 interactive = True
574 build_type = "pre-releases"
576 package_type = platform_info()[1]
577 arch_type = platform_info()[2]
579 loop = False
580 interactive = True
581 headless = False
582 build_type = "pre-releases"
584 # Handling options and arguments
585 try:
586 opts, args = getopt.getopt(sys.argv[1:], "dluihfvst:", ["download", "loop", "uninstall", "install", "help", "force", "verify", "headless", "type="])
587 except getopt.GetoptError, err:
588 logger.error(str(err))
589 usage()
590 sys.exit(2)
592 for o, a in opts:
593 if ("-t" in o) or ("--type" in o):
594 build_type = a
595 elif o in ("-s", "--headless"):
596 headless = True
598 url_reg = get_url_regexp(build_type, package_type, arch_type)
600 for o, a in opts:
601 if o in ("-f", "--force"):
602 interactive = False
603 elif o in ("-t", "--type"):
604 pass
605 elif o in ("-s", "--headless"):
606 pass
607 elif o in ("-h", "--help"):
608 usage()
609 sys.exit()
610 elif o in ("-v", "--verify"):
611 init_testing()
612 verify_smoketest(headless)
613 sys.exit()
614 elif o in ("-i", "--install"):
615 init_testing()
616 uninstall(build_type)
617 install(DOWNLOAD_DIR + os.sep + local_build_info(build_type)[0])
618 install(DOWNLOAD_DIR + os.sep + local_build_info(build_type)[2])
619 sys.exit()
620 elif o in ("-u", "--uninstall"):
621 uninstall(build_type)
622 sys.exit()
623 elif o in ("-d", "--download"):
624 init_testing()
625 download(url_reg, build_type)
626 sys.exit()
627 elif o in ("-l", "--loop"):
628 loop = True
629 else:
630 assert False, "Unhandled option: " + o
632 if interactive == True:
633 key = raw_input("The testing will OVERRIDE existed libreoffice, continue(y/N)? ")
634 if not (key == "y" or key == "Y" or key == "yes"):
635 sys.exit()
637 init_testing()
638 first_run = True
639 while loop or first_run:
640 if download(url_reg, build_type):
641 try:
642 # FIXME: uninstall script fails but it need not break the whole game; so try it twice
643 try:
644 uninstall(build_type)
645 except:
646 logger.error("Some errors happened during uninstall. Trying once again.")
647 uninstall(build_type)
649 install(DOWNLOAD_DIR + os.sep + local_build_info(build_type)[0])
650 install(DOWNLOAD_DIR + os.sep + local_build_info(build_type)[2])
651 verify_smoketest(headless)
653 except KeyboardInterrupt:
654 sys.exit()
655 except:
656 continue
657 else:
658 logger.warning("No new build found.")
659 if loop:
660 time.sleep(build_check_interval)
662 first_run = False
665 if __name__ == '__main__':
667 # logging
668 logger = logging.getLogger('')
669 logger.setLevel(logging.DEBUG)
671 fh = logging.FileHandler(os.path.basename(__file__) + '.log')
672 ch = logging.StreamHandler()
674 formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(message)s')
675 ch.setFormatter(formatter)
676 fh.setFormatter(formatter)
678 logger.addHandler(ch)
679 logger.addHandler(fh)
681 main()