bump product version to 4.1.6.2
[LibreOffice.git] / smoketest / lodownloadtest.py
blob63ff439e2020885936b041f1eebd70b755cb3921
1 #!/usr/bin/env python
3 # This file is part of the LibreOffice project.
5 # This Source Code Form is subject to the terms of the Mozilla Public
6 # License, v. 2.0. If a copy of the MPL was not distributed with this
7 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 # The tool is designed to enable test machine fully automatically run smoketest
11 # with both daily and pre release build located in dev-build.libreoffice.org.
13 # The tool is named as losmoketest for its purpose, meanwhile it help you to
14 # check, download and install the latest build. By the fact the installation is
15 # designed not to be different from manually doing these repeated work, the
16 # installed libreoffice build can also be good for manual test.
18 import sys, os, platform
19 import datetime, time
20 import subprocess, shutil
21 import glob, re
22 import urllib, urllib2
23 import logging, getopt
24 try:
25 import ConfigParser as configparser # Python 3.0 change
26 except ImportError:
27 import configparser
29 # FIXME: make this configurable via options or autodetect it
30 build_version = "3.5"
31 tag_version = "3-5"
32 # devel build
33 branding_pack="lodev"
34 basis_pack="lodevbasis"
35 # stable build
36 #branding_pack="libreoffice"
37 #basis_pack="libobasis"
39 # possible program files of libreoffice, put all platform paths are
40 # expected in this list
41 lo_all_paths = [
42 "/opt/lodev" + build_version, \
43 "/opt/libreoffice" + build_version, \
44 "/usr/lib/libreoffice", \
45 "/usr/lib64/libreoffice", \
46 "C:\program file\libreoffice", \
49 build_check_interval = 5 #seconds
51 # Distro list
52 RPM_DISTRO_LIST = ['SuSE', 'fedora', 'redhat', 'centos', 'mandrake', 'mandriva', 'yellowdog', 'turbolinux']
53 DEB_DISTRO_LIST = ['debian', 'ubuntu', 'Ubuntu']
55 # Server urls
56 SERVER_URL = "http://dev-builds.libreoffice.org"
58 # Local dirs
59 root_dir = os.getcwd()
60 DOWNLOAD_DIR = os.path.join(root_dir, "_download")
61 USR_DIR = os.path.join(root_dir, "_libo_smoke_user")
62 LOCAL_BUILD_INFO_FILE = os.path.join(root_dir, "build.cfg")
64 # INSTALL_DIR = os.path.join(root_dir, "_libo_smoke_installation")
65 INSTALL_DIR = "" # Installation dir
67 # SOFFICE_BIN bin
68 if platform.system() == "Linux":
69 SOFFICE_BIN = "soffice"
70 LOSMOKETEST_BIN = "losmoketest"
71 elif platform.system() == "Windows":
72 SOFFICE_BIN = "soffice.exe"
73 LOSMOKETEST_BIN = "losmoketest"
74 else:
75 SOFFICE_BIN = "soffice"
76 LOSMOKETEST_BIN = "losmoketest"
78 # Relative build url
79 ## pre-releases
80 PR_RPM_X86_PATH = "pre-releases/rpm/x86/"
81 PR_RPM_X86_64_PATH = "pre-releases/rpm/x86_64/"
83 PR_DEB_X86_PATH = "pre-releases/deb/x86/"
84 PR_DEB_X86_64_PATH = "pre-releases/deb/x86_64/"
86 PR_MAC_X86_PATH = "pre-releases/mac/x86/"
87 PR_MAC_PPC_PATH = "pre-releases/mac/ppc/"
89 PR_WIN_X86_PATH = "pre-releases/win/x86/"
91 ## daily_master
92 DAILY_MASTER_RPM_X86_PATH = "daily/Linux-x86_10-Release_Configuration/master/current"
93 DAILY_MASTER_RPM_X86_64_PATH = "daily/Linux-x86_64_11-Release_Configuration/master/current"
95 DAILY_MASTER_DEB_X86_PATH = "daily/Linux-x86_10-Release_Configuration/master/current"
96 DAILY_MASTER_DEB_X86_64_PATH = "daily/Linux-x86_64_11-Release_Configuration/master/current"
98 DAILY_MASTER_MAC_X86_PATH = "daily/MacOSX-Intel@3-OSX_10.6.0-gcc_4.0.1/master/current"
99 DAILY_MASTER_MAC_PPC_PATH = "daily/MacOSX-PPC@12-OSX_10.5.0-gcc_4.0.1/master/current" # No build yet
101 DAILY_MASTER_WIN_X86_PATH = "daily/Win-x86@7-MinGW/master/current" # cross compling build
103 ## daily_branch
104 DAILY_BRANCH_RPM_X86_PATH = "daily/Linux-x86_10-Release_Configuration/libreoffice-" + tag_version + "/current"
105 DAILY_BRANCH_RPM_X86_64_PATH = "daily/Linux-x86_64_11-Release_Configuration/libreoffice-" + tag_version + "/current"
107 DAILY_BRANCH_DEB_X86_PATH = "daily/Linux-x86_10-Release_Configuration/libreoffice-" + tag_version + "/current"
108 DAILY_BRANCH_DEB_X86_64_PATH = "daily/Linux-x86_64_11-Release_Configuration/libreoffice-" + tag_version + "/current"
110 DAILY_BRANCH_MAC_X86_PATH = "daily/MacOSX-Intel@3-OSX_10.6.0-gcc_4.0.1/libreoffice-" + tag_version + "/current"
111 DAILY_BRANCH_MAC_PPC_PATH = "daily/MacOSX-PPC@12-OSX_10.5.0-gcc_4.0.1/libreoffice-" + tag_version + "/current"
113 DAILY_BRANCH_WIN_X86_PATH = "daily/Win-x86@7-MinGW/libreoffice-" + tag_version + "/current"
117 def platform_info():
119 s = platform.system()
120 arch_name = platform.machine()
122 if arch_name in ['x86', 'i386', 'i586', 'i686']:
123 arch_name = 'x86'
125 if s == "Linux":
126 if platform.dist()[0] in RPM_DISTRO_LIST:
127 distro_name = platform.dist()[0]
128 pck_name = 'rpm'
129 elif platform.dist()[0] in DEB_DISTRO_LIST:
130 distro_name = platform.dist()[0]
131 pck_name = 'deb'
132 elif s == "Windows":
133 distro_name = platform.dist()[0]
134 pck_name = 'exe'
135 else:
136 distro_name = platform.dist()[0]
137 pck_name = 'dmg'
139 return distro_name, pck_name, arch_name
141 def local_build_info(t):
143 if not os.path.exists(LOCAL_BUILD_INFO_FILE):
144 logger.error("Can't find the file: " + LOCAL_BUILD_INFO_FILE)
145 sys.exit()
147 config = configparser.RawConfigParser()
148 config.read(LOCAL_BUILD_INFO_FILE)
150 try:
151 build_name = config.get(t, 'build_name').strip('\n')
152 build_time = datetime.datetime.strptime(config.get(t, 'build_time').strip('\n'), '%d-%b-%Y %H:%M')
153 except ValueError:
154 build_name = ''
155 build_time = datetime.datetime.min
157 try:
158 testpack_name = config.get(t, 'testpack_name').strip('\n')
159 testpack_build_time = datetime.datetime.strptime(config.get(t, 'testpack_build_time').strip('\n'), '%d-%b-%Y %H:%M')
160 except ValueError:
161 testpack_name = ''
162 testpack_build_time = datetime.datetime.min
164 return build_name, build_time, testpack_name, testpack_build_time
166 def get_url_regexp(t, package, arch):
168 return a url containing download links, i.e:
170 http://dev-builds.libreoffice.org/pre-releases/rpm/x86_64/
171 http://dev-builds.libreoffice.org/daily/Windows_Release_Configuration/libreoffice-3-4/current/
172 http://dev-builds.libreoffice.org/daily/Linux_x86_Release_Configuration/libreoffice-3-4/current/
174 meanwhile return a regexp object that matching corresponding downloadable
175 package and its timestamp '''
177 url = ""
178 reg_lo = re.compile('^$')
179 reg_tst = re.compile('^$')
180 pck = package
181 arc = arch
183 if t == 'pre-releases':
184 if pck == "rpm" and arc == "x86":
185 url = SERVER_URL + "/" + PR_RPM_X86_PATH
186 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}).*')
187 reg_tst = re.compile('\<a\ href=\"(LibO-Test.*.gz)\".*(\d{2}\-[a-zA-Z]{3}\-\d{4}).*(\d{2}:\d{2}).*')
188 elif pck == "rpm" and arc == "x86_64":
189 url = SERVER_URL + "/" + PR_RPM_X86_64_PATH
190 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}).*')
191 reg_tst = re.compile('\<a\ href=\"(LibO-Test.*.gz)\".*(\d{2}\-[a-zA-Z]{3}\-\d{4}).*(\d{2}:\d{2}).*')
192 elif pck == "deb" and arc == "x86":
193 url = SERVER_URL + "/" + PR_DEB_X86_PATH
194 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}).*')
195 elif pck == "deb" and arc == "x86_64":
196 url = SERVER_URL + "/" + PR_DEB_X86_64_PATH
197 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}).*')
198 elif pck == "exe" and arc == "x86":
199 url = SERVER_URL + "/" + PR_WIN_X86_PATH
200 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}).*')
201 elif pck == "dmg" and arc == "x86":
202 url = SERVER_URL + "/" + PR_MAC_X86_PATH
203 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}).*')
204 elif pck == "dmg" and arc == "ppc":
205 url = SERVER_URL + "/" + PR_MAC_PPC_PATH
206 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}).*')
207 else:
208 logger.error("Unable to handle the system or arch!")
209 elif t == 'daily_master':
210 if pck == "rpm" and arc == "x86":
211 url = SERVER_URL + "/" + DAILY_MASTER_RPM_X86_PATH
212 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}).*')
213 elif pck == "rpm" and arc == "x86_64":
214 url = SERVER_URL + "/" + DAILY_MASTER_RPM_X86_64_PATH
215 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}).*')
216 elif pck == "deb" and arc == "x86":
217 url = SERVER_URL + "/" + DAILY_MASTER_DEB_X86_PATH
218 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}).*')
219 elif pck == "deb" and arc == "x86_64":
220 url = SERVER_URL + "/" + DAILY_MASTER_DEB_X86_64_PATH
221 reg_lo = re.compile('^$') # No build yet
222 elif pck == "exe" and arc == "x86":
223 url = SERVER_URL + "/" + DAILY_MASTER_WIN_X86_PATH
224 reg_lo = re.compile('^$') # No build yet
225 elif pck == "dmg" and arc == "x86":
226 url = SERVER_URL + "/" + DAILY_MASTER_MAC_X86_PATH
227 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}).*')
228 elif pck == "dmg" and arc == "ppc":
229 url = SERVER_URL + "/" + DAILY_MASTER_MAC_PPC_PATH
230 reg_lo = re.compile('^$') # No build yet
231 else:
232 logger.error("Unable to handle the system or arch!")
233 elif t == 'daily_branch':
234 if pck == "rpm" and arc == "x86":
235 url = SERVER_URL + "/" + DAILY_BRANCH_RPM_X86_PATH
236 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}).*')
237 elif pck == "rpm" and arc == "x86_64":
238 url = SERVER_URL + "/" + DAILY_BRANCH_RPM_X86_64_PATH
239 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}).*')
240 elif pck == "deb" and arc == "x86":
241 url = SERVER_URL + "/" + DAILY_BRANCH_DEB_X86_PATH
242 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}).*')
243 elif pck == "deb" and arc == "x86_64":
244 url = SERVER_URL + "/" + DAILY_BRANCH_DEB_X86_64_PATH
245 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}).*')
246 elif pck == "exe" and arc == "x86":
247 url = SERVER_URL + "/" + DAILY_BRANCH_WIN_X86_PATH
248 reg_lo = re.compile('\<a\ href=\"(.*LibO_.*install_.*\.exe)\".*(\d{2}\-[a-zA-Z]{3}\-\d{4}).*(\d{2}:\d{2}).*')
249 elif pck == "dmg" and arc == "x86":
250 url = SERVER_URL + "/" + DAILY_BRANCH_MAC_X86_PATH
251 reg_lo = re.compile('^$') # No build yet
252 elif pck == "dmg" and arc == "ppc":
253 url = SERVER_URL + "/" + DAILY_BRANCH_MAC_PPC_PATH
254 reg_lo = re.compile('^$') # No build yet
255 else:
256 logger.error("Unable to handle the system or arch!")
257 else:
258 logger.error("Error build type! The build type has to be:\n pre-releases, daily_master, daily_branch")
260 return url, reg_lo, reg_tst
262 def remote_build_info(url_reg):
263 ''' Get the latest proper build info (build_name, build_time) from
264 url. '''
266 p = platform_info()
267 pck = p[1]
268 arc = p[2]
269 r = url_reg[1]
270 r_t = url_reg[2]
272 f = urllib2.urlopen(url_reg[0])
273 c = ''.join(f.readlines())
274 f.close()
276 build_list = r.findall(c)
277 test_list = r_t.findall(c)
279 build_name = ''
280 build_time = datetime.datetime.min
281 testpack_build_time = datetime.datetime.min
282 testpack_name = ''
285 for b in build_list:
286 if datetime.datetime.strptime(b[1] + ' ' + b[2], '%d-%b-%Y %H:%M') > build_time:
287 build_name = b[0]
288 try:
289 build_time = datetime.datetime.strptime(b[1] + ' ' + b[2], '%d-%b-%Y %H:%M')
290 except:
291 print "remote_build_info: wrong time date&format"
293 for t in test_list:
294 if datetime.datetime.strptime(t[1] + ' ' + t[2], '%d-%b-%Y %H:%M') > testpack_build_time:
295 testpack_name = t[0]
296 try:
297 testpack_build_time = datetime.datetime.strptime(t[1] + ' ' + t[2], '%d-%b-%Y %H:%M')
298 except:
299 print "remote_build_info: wrong time date&format"
301 return build_name, build_time, testpack_name, testpack_build_time
303 # return True when something was downloaded
304 def download(url_reg, build_type):
305 logger.info('Checking new build ...')
307 try:
308 remote_build = remote_build_info(url_reg)
309 local_build = local_build_info(build_type)
311 if remote_build[1] > local_build[1]:
312 logger.info('Found New LO build: ' + remote_build[0])
313 if fetch_build(url_reg[0], remote_build[0]):
314 set_build_config(build_type, 'build_name', remote_build[0])
315 set_build_config(build_type, 'build_time', datetime.datetime.strftime(remote_build[1], '%d-%b-%Y %H:%M'))
316 else:
317 logger.error('Download libreoffice build failed!')
319 if remote_build[3] > local_build[3] and (remote_build[1] - remote_build[3]) < datetime.timedelta(hours=1):
320 logger.info('Found a relevant smoketest package: ' + remote_build[2])
321 if fetch_build(url_reg[0], remote_build[2]):
322 set_build_config(build_type, 'testpack_name', remote_build[2])
323 set_build_config(build_type, 'testpack_build_time', datetime.datetime.strftime(remote_build[3], '%d-%b-%Y %H:%M'))
324 return True
325 else:
326 logger.warning("Failed to find corresponding smoketest package")
328 except urllib2.URLError, HTTPError:
329 logger.error('Error fetch remote build info.')
330 return False
331 except KeyboardInterrupt:
332 sys.exit()
333 except:
334 logger.error('Error fetch remote build info.')
335 return False
337 return False
339 def fetch_build(url, filename):
340 ''' Download a build from address url/filename '''
342 logger.info("Downloading ... " + filename)
344 u = urllib2.urlopen(url + '/' + filename)
346 try:
347 f = open(DOWNLOAD_DIR + '/' + filename, 'wb')
348 f.write(u.read())
349 f.close()
350 except urllib2.HTTPError, e:
351 print "HTTP Error:",e.code , url
352 except urllib2.URLError, e:
353 print "URL Error:",e.reason , url
355 return True
357 def set_build_config(section, option, value):
359 config = configparser.RawConfigParser()
360 config.readfp(open(LOCAL_BUILD_INFO_FILE))
361 config.set(section, option, value)
362 with open(LOCAL_BUILD_INFO_FILE, 'wb') as cfgfile:
363 config.write(cfgfile)
365 def uninstall(build_type):
366 ''' Kill libreoffice processes and uninstall all previously installed
367 libreoffice packages '''
369 if build_type == "pre-releases":
370 branding_pack="libreoffice"
371 basis_pack="libobasis"
373 logger.info("Uninstalling ...")
375 pck = platform_info()[1]
377 if pck == 'rpm':
378 cmd_query = ["rpm", "-qa"]
379 cmd_filter = ["grep", \
380 "-e", branding_pack+build_version, \
381 "-e", basis_pack+build_version, \
384 P_query = subprocess.Popen(cmd_query, stdout = subprocess.PIPE)
385 P_filter = subprocess.Popen(cmd_filter, stdin = P_query.stdout, stdout = subprocess.PIPE)
386 P_query.stdout.close() # protection when P_filter exit before P_query
387 str_filter = P_filter.communicate()[0]
389 if str_filter == "":
390 logger.warning("Nothing to uninstall")
391 return
392 else:
393 cmd = ["sudo", "rpm", "-e"] + str_filter.split()
394 elif pck == 'deb':
395 cmd_query = ["dpkg", "--get-selections", branding_pack+build_version+"*", basis_pack+build_version+"*"]
396 cmd_filter = ["cut", "-f", "1"]
398 P_query = subprocess.Popen(cmd_query, stdout = subprocess.PIPE)
399 P_filter = subprocess.Popen(cmd_filter, stdin = P_query.stdout, stdout = subprocess.PIPE)
400 P_query.stdout.close()
401 str_filter = P_filter.communicate()[0]
403 if str_filter == "":
404 logger.warning("Nothing to uninstall")
405 return
406 else:
407 cmd = ["sudo", "dpkg ", "-P"] + str_filter.split()
408 elif pck == 'exe':
409 pass
410 elif pck == 'dmg':
411 pass
412 else:
413 logger.warning("Non supported package system")
415 subprocess.check_call(cmd)
417 def init_testing():
418 logger.info("Initializing ...")
420 post_testing()
422 if not os.path.exists(DOWNLOAD_DIR):
423 os.mkdir(DOWNLOAD_DIR)
425 if not os.path.exists(USR_DIR):
426 os.mkdir(USR_DIR)
428 if not os.path.exists(LOCAL_BUILD_INFO_FILE):
430 init_build_cfg = '[daily_branch]' + os.linesep\
431 + 'build_name =' + os.linesep\
432 + 'build_time =' + os.linesep\
433 + 'testpack_name =' + os.linesep\
434 + 'testpack_build_time =' + os.linesep\
435 + '[daily_master]' + os.linesep\
436 + 'build_name =' + os.linesep\
437 + 'build_time =' + os.linesep\
438 + 'testpack_name =' + os.linesep\
439 + 'testpack_build_time =' + os.linesep\
440 + '[pre-releases]' + os.linesep\
441 + 'build_name =' + os.linesep\
442 + 'build_time =' + os.linesep \
443 + 'testpack_name =' + os.linesep\
444 + 'testpack_build_time =' + os.linesep
446 with open(LOCAL_BUILD_INFO_FILE, 'w+') as f:
447 f.write(init_build_cfg)
448 f.close()
450 def post_testing():
451 logger.info("Cleaning up ...")
453 # clean up the extracted installer dir
454 for r in os.walk(DOWNLOAD_DIR):
455 if r[0] == DOWNLOAD_DIR:
456 for d in r[1]:
457 shutil.rmtree(os.path.join(r[0], d))
459 def install(filename):
460 ''' filename: local file path of tar.gz, dmg or exe. The script will
461 extract the package and then install it '''
463 logger.info("Installing ... " + filename)
465 def _is_not_filtered(s):
466 ''' True if the package s is not intended to installed. '''
467 filter_pattern_list = ['.*kde.*', '.*gnome.*', '.*desktop.*', '!.*\.rpm$', '!.*\.deb$']
468 for p in filter_pattern_list:
469 r = re.compile(p)
470 if r.match(s):
471 return False
472 return True
474 fn, ext = os.path.splitext(filename)
475 pcklist = []
477 if ext == '.exe':
478 # extract
479 installer_dir = os.path.join(DOWNLOAD_DIR, filename.strip(ext))
480 subprocess.check_call([filename, '/EXTRACTONLY=ON', '/S', '/D='+installer_dir])
481 # install
482 installer = glob.glob(os.path.join(installer_dir, 'libreoffice*msi'))[0]
483 subprocess.check_call(['msiexec', '-i', installer, '-passive', 'ADDLOCAL=all'])
484 elif ext == '.dmg':
485 return
486 elif ext == '.gz':
487 # extract
488 subprocess.check_call(['tar', 'xzf', filename, '-C', DOWNLOAD_DIR])
490 # get a filtered install list
491 for root, dirs, files in os.walk(DOWNLOAD_DIR):
492 if 'RPMS' in root or 'DEBS' in root:
493 pcklist = pcklist + [os.path.join(root_dir, root, f) for f in files]
494 install_pcklist = filter(_is_not_filtered, pcklist)
496 # install
497 if platform_info()[1] == 'rpm':
498 install_cmd = ["sudo", "rpm", "-iv"] + install_pcklist
499 clean_tmp_cmd = ["sudo", "rm", "-f"] + pcklist
500 elif platform_info()[1] == 'deb':
501 install_cmd = ["sudo", "dpkg", "-i"] + install_pcklist
502 else:
503 logger.error('Cannot generate install command')
504 return
506 subprocess.check_call(install_cmd)
507 subprocess.check_call(clean_tmp_cmd)
509 else:
510 logger.info("Unrecognized file extension")
512 def verify_smoketest(headless):
513 logger.info("Testing ...")
515 s = platform.system()
516 p = platform_info()
517 pck = p[1]
518 arc = p[2]
520 lo_testable_paths = filter(lambda p: \
521 os.path.exists(p + os.sep + "program" + os.sep + LOSMOKETEST_BIN) and \
522 os.path.exists(p + os.sep + "program" + os.sep + SOFFICE_BIN), \
523 lo_all_paths)
525 if not lo_testable_paths:
526 logger.error("Not found any Libreoffice or Test packages!")
527 sys.exit(1)
528 else:
529 cmd_smoketests = [ p + os.sep + "program" + os.sep + LOSMOKETEST_BIN for p in lo_testable_paths ]
531 if len(lo_testable_paths) > 1:
532 logger.info("++More than one testable build is found, test them one by one.")
534 # subprocess.call(cmd_smoketest);
535 for c in cmd_smoketests:
536 pattern = re.compile(LOSMOKETEST_BIN + "$")
537 logger.info(" Test Binary: " + pattern.sub(SOFFICE_BIN, c))
538 subprocess.call(c)
540 def usage():
542 print "\n[Usage]\n\n -f Force testing without asking \n\
543 -t Testing type pre-release/daily \n\
544 -l Download and test last builds in a loop \n\
545 -v Run smoketest verification directly \n\
546 -s Use the headless mode when running the tests \n\
547 -i Install the latest build in the DOWNLOAD directory \n\
548 -u Uninstall any existed libreoffice build \n\
549 -d Download the latest build for the given test type \n\
552 def main():
554 interactive = True
555 build_type = "pre-releases"
557 package_type = platform_info()[1]
558 arch_type = platform_info()[2]
560 loop = False
561 interactive = True
562 headless = False
563 build_type = "pre-releases"
565 # Handling options and arguments
566 try:
567 opts, args = getopt.getopt(sys.argv[1:], "dluihfvst:", ["download", "loop", "uninstall", "install", "help", "force", "verify", "headless", "type="])
568 except getopt.GetoptError, err:
569 logger.error(str(err))
570 usage()
571 sys.exit(2)
573 for o, a in opts:
574 if ("-t" in o) or ("--type" in o):
575 build_type = a
576 elif o in ("-s", "--headless"):
577 headless = True
579 url_reg = get_url_regexp(build_type, package_type, arch_type)
581 for o, a in opts:
582 if o in ("-f", "--force"):
583 interactive = False
584 elif o in ("-t", "--type"):
585 pass
586 elif o in ("-s", "--headless"):
587 pass
588 elif o in ("-h", "--help"):
589 usage()
590 sys.exit()
591 elif o in ("-v", "--verify"):
592 init_testing()
593 verify_smoketest(headless)
594 sys.exit()
595 elif o in ("-i", "--install"):
596 init_testing()
597 uninstall(build_type)
598 install(DOWNLOAD_DIR + os.sep + local_build_info(build_type)[0])
599 install(DOWNLOAD_DIR + os.sep + local_build_info(build_type)[2])
600 sys.exit()
601 elif o in ("-u", "--uninstall"):
602 uninstall(build_type)
603 sys.exit()
604 elif o in ("-d", "--download"):
605 init_testing()
606 download(url_reg, build_type)
607 sys.exit()
608 elif o in ("-l", "--loop"):
609 loop = True
610 else:
611 assert False, "Unhandled option: " + o
613 if interactive == True:
614 key = raw_input("The testing will OVERRIDE existed libreoffice, continue(y/N)? ")
615 if not (key == "y" or key == "Y" or key == "yes"):
616 sys.exit()
618 init_testing()
619 first_run = True
620 while loop or first_run:
621 if download(url_reg, build_type):
622 try:
623 # FIXME: uninstall script fails but it need not break the whole game; so try it twice
624 try:
625 uninstall(build_type)
626 except:
627 logger.error("Some errors happened during uninstall. Trying once again.")
628 uninstall(build_type)
630 install(DOWNLOAD_DIR + os.sep + local_build_info(build_type)[0])
631 install(DOWNLOAD_DIR + os.sep + local_build_info(build_type)[2])
632 verify_smoketest(headless)
634 except KeyboardInterrupt:
635 sys.exit()
636 except:
637 continue
638 else:
639 logger.warning("No new build found.")
640 if loop:
641 time.sleep(build_check_interval)
643 first_run = False
646 if __name__ == '__main__':
648 # logging
649 logger = logging.getLogger('')
650 logger.setLevel(logging.DEBUG)
652 fh = logging.FileHandler(os.path.basename(__file__) + '.log')
653 ch = logging.StreamHandler()
655 formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(message)s')
656 ch.setFormatter(formatter)
657 fh.setFormatter(formatter)
659 logger.addHandler(ch)
660 logger.addHandler(fh)
662 main()