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
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
39 import subprocess
, shutil
41 import urllib
, urllib2
42 import logging
, getopt
44 import ConfigParser
as configparser
# Python 3.0 change
48 # FIXME: make this configurable via options or autodetect it
53 basis_pack
="lodevbasis"
55 #branding_pack="libreoffice"
56 #basis_pack="libobasis"
58 # possible program files of libreoffice, put all platform paths are
59 # expected in this list
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
71 RPM_DISTRO_LIST
= ['SuSE', 'fedora', 'redhat', 'centos', 'mandrake', 'mandriva', 'yellowdog', 'turbolinux']
72 DEB_DISTRO_LIST
= ['debian', 'ubuntu', 'Ubuntu']
75 SERVER_URL
= "http://dev-builds.libreoffice.org"
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
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"
94 SOFFICE_BIN
= "soffice"
95 LOSMOKETEST_BIN
= "losmoketest"
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/"
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
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"
138 s
= platform
.system()
139 arch_name
= platform
.machine()
141 if arch_name
in ['x86', 'i386', 'i586', 'i686']:
145 if platform
.dist()[0] in RPM_DISTRO_LIST
:
146 distro_name
= platform
.dist()[0]
148 elif platform
.dist()[0] in DEB_DISTRO_LIST
:
149 distro_name
= platform
.dist()[0]
152 distro_name
= platform
.dist()[0]
155 distro_name
= platform
.dist()[0]
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
)
166 config
= configparser
.RawConfigParser()
167 config
.read(LOCAL_BUILD_INFO_FILE
)
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')
174 build_time
= datetime
.datetime
.min
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')
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 '''
197 reg_lo
= re
.compile('^$')
198 reg_tst
= re
.compile('^$')
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}).*')
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
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
275 logger
.error("Unable to handle the system or arch!")
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
291 f
= urllib2
.urlopen(url_reg
[0])
292 c
= ''.join(f
.readlines())
295 build_list
= r
.findall(c
)
296 test_list
= r_t
.findall(c
)
299 build_time
= datetime
.datetime
.min
300 testpack_build_time
= datetime
.datetime
.min
305 if datetime
.datetime
.strptime(b
[1] + ' ' + b
[2], '%d-%b-%Y %H:%M') > build_time
:
308 build_time
= datetime
.datetime
.strptime(b
[1] + ' ' + b
[2], '%d-%b-%Y %H:%M')
310 print "remote_build_info: wrong time date&format"
313 if datetime
.datetime
.strptime(t
[1] + ' ' + t
[2], '%d-%b-%Y %H:%M') > testpack_build_time
:
316 testpack_build_time
= datetime
.datetime
.strptime(t
[1] + ' ' + t
[2], '%d-%b-%Y %H:%M')
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 ...')
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'))
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'))
345 logger
.warning("Failed to find corresponding smoketest package")
347 except urllib2
.URLError
, HTTPError
:
348 logger
.error('Error fetch remote build info.')
350 except KeyboardInterrupt:
353 logger
.error('Error fetch remote build info.')
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
)
366 f
= open(DOWNLOAD_DIR
+ '/' + filename
, 'wb')
369 except urllib2
.HTTPError
, e
:
370 print "HTTP Error:",e
.code
, url
371 except urllib2
.URLError
, e
:
372 print "URL Error:",e
.reason
, url
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]
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]
409 logger
.warning("Nothing to uninstall")
412 cmd
= ["sudo", "rpm", "-e"] + str_filter
.split()
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]
423 logger
.warning("Nothing to uninstall")
426 cmd
= ["sudo", "dpkg ", "-P"] + str_filter
.split()
432 logger
.warning("Non supported package system")
434 subprocess
.check_call(cmd
)
437 logger
.info("Initializing ...")
441 if not os
.path
.exists(DOWNLOAD_DIR
):
442 os
.mkdir(DOWNLOAD_DIR
)
444 if not os
.path
.exists(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
)
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
:
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
:
493 fn
, ext
= os
.path
.splitext(filename
)
498 installer_dir
= os
.path
.join(DOWNLOAD_DIR
, filename
.strip(ext
))
499 subprocess
.check_call([filename
, '/EXTRACTONLY=ON', '/S', '/D='+installer_dir
])
501 installer
= glob
.glob(os
.path
.join(installer_dir
, 'libreoffice*msi'))[0]
502 subprocess
.check_call(['msiexec', '-i', installer
, '-passive', 'ADDLOCAL=all'])
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
)
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
522 logger
.error('Cannot generate install command')
525 subprocess
.check_call(install_cmd
)
526 subprocess
.check_call(clean_tmp_cmd
)
529 logger
.info("Unrecognized file extension")
531 def verify_smoketest(headless
):
532 logger
.info("Testing ...")
534 s
= platform
.system()
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
), \
544 if not lo_testable_paths
:
545 logger
.error("Not found any Libreoffice or Test packages!")
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
))
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\
574 build_type
= "pre-releases"
576 package_type
= platform_info()[1]
577 arch_type
= platform_info()[2]
582 build_type
= "pre-releases"
584 # Handling options and arguments
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
))
593 if ("-t" in o
) or ("--type" in o
):
595 elif o
in ("-s", "--headless"):
598 url_reg
= get_url_regexp(build_type
, package_type
, arch_type
)
601 if o
in ("-f", "--force"):
603 elif o
in ("-t", "--type"):
605 elif o
in ("-s", "--headless"):
607 elif o
in ("-h", "--help"):
610 elif o
in ("-v", "--verify"):
612 verify_smoketest(headless
)
614 elif o
in ("-i", "--install"):
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])
620 elif o
in ("-u", "--uninstall"):
621 uninstall(build_type
)
623 elif o
in ("-d", "--download"):
625 download(url_reg
, build_type
)
627 elif o
in ("-l", "--loop"):
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"):
639 while loop
or first_run
:
640 if download(url_reg
, build_type
):
642 # FIXME: uninstall script fails but it need not break the whole game; so try it twice
644 uninstall(build_type
)
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:
658 logger
.warning("No new build found.")
660 time
.sleep(build_check_interval
)
665 if __name__
== '__main__':
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
)