# -*- coding: utf-8 -*-
from setuphelpers import *
import platform
import time
uninstallkey = []
# Defining variables
bin_name_string = 'Apache_OpenOffice_%s_Win_x86_install_%s.exe' # (% version % language)
silent_args = '/S'
app_uninstallkey = ''
app_name = 'OpenOffice'
processes_to_kill = ['soffice','sbase','scalc','sdraw','simpress','smath','sweb','swriter']
def install():
# Initializing variables
package_version = control.version.split('-',1)[0]
bin_name = bin_name_string % (package_version, control.locale)
#processes_to_kill = control.impacted_process.split(',')
# Uninstalling LibreOffice if detected
for uninstall in installed_softwares(name="LibreOffice"):
if uninstall_key_exists(uninstall['key']):
print('Removing: %s' % (uninstall['name']))
run(uninstall_cmd(uninstall['key']))
# Uninstalling OpenOffice if too old
for uninstall in installed_softwares(name=app_name):
if Version(uninstall['version']) < Version(package_version):
if uninstall_key_exists(uninstall['key']):
print('Removing: %s' % (uninstall['name']))
killalltasks(processes_to_kill)
run(uninstall_cmd(uninstall['key']))
# Installing the package
print('Installing: %s' % bin_name)
install_exe_if_needed(bin_name,
silentflags=silent_args,
key=app_uninstallkey,
min_version=package_version)
def uninstall():
# Initializing variables
count = 30 # 30x10=300sec maximum waiting
# Uninstalling the package
for uninstall in installed_softwares(name=app_name):
killalltasks(processes_to_kill)
print('Uninstalling: %s' % uninstall['name'])
run_notfatal(uninstall_cmd(uninstall['key']))
while installed_softwares(name=app_name):
count -= 1
if count == 0:
error('Unable to uninstall: %s' % app_name)
time.sleep(10)
def update_package():
# Initializing variables
proxies = get_proxies()
if not proxies:
proxies = get_proxies_from_wapt_console()
url = 'https://www.openoffice.org/fr/Telecharger'
locale = control.locale
if locale == 'en':
locale = 'en-US'
# Getting latest version from official website
download_html = wgets(url,proxies=proxies).splitlines()
for element in download_html:
if 'Disponible' in element:
version = element.split(r'</a></div>')[0].split(' ')[-1]
latest_bin = bin_name_string % (version, locale)
url_dl = 'https://sourceforge.net/projects/openofficeorg.mirror/files/%s/binaries/%s/%s/download' % (version, locale, latest_bin)
print("Latest %s version is: %s" % (app_name,version))
print("Download url is: %s" % url_dl)
# Downloading latest binaries
if not isfile(latest_bin):
print('Downloading: %s' % latest_bin)
wget(url_dl,latest_bin,proxies=proxies)
# Changing version of the package
control.version = '%s-%s' % (version, control.version.split('-')[-1])
control.save_control_to_wapt()
print('Changing version to: %s in WAPT\\control' % control.version)
# Deleting outdated binaries
remove_outdated_binaries(version)
def build_all_package():
from optparse import OptionParser
from waptpackage import PackageEntry
from common import Wapt
import os
try:
import waptguihelper
except:
waptguihelper = None
import time
global options
os.chdir(os.path.join(os.path.abspath(os.path.curdir),'windows'))
parser = OptionParser()
parser.add_option("--wapt-server-passwd", dest="wapt_server_passwd", default=None, help="Password to upload packages to waptserver. (default: %default)")
parser.add_option("-w","--private-key-passwd", dest="private_key_passwd", default='', help="Path to the password of the private key. (default: %default)")
parser.add_option("--wapt-server-user", dest="wapt_server_user", default=None, help="User to upload packages to waptserver. (default: %default)")
parser.add_option("-c","--config", dest="config", default=makepath(user_local_appdata(),'waptconsole','waptconsole.ini'), help="Config file full path (default: %default)")
parser.add_option("--maturity", dest="maturity", default='PROD', help="Set/change package maturity when building package. (default: None)")
(options,args) = parser.parse_args()
print('Create all Arch and language')
print('Current Dir %s' % os.getcwd())
urlserver = inifile_readstring(options.config,'global','wapt_server')
mycrt = inifile_readstring(options.config,'global','personal_certificate_path')
if options.private_key_passwd:
if isfile(options.private_key_passwd):
passwordkey = { 'keypassword' : open(options.private_key_passwd).read()}
else:
passwordkey = waptguihelper.key_password_dialog('Password for private key',mycrt, '')
if options.wapt_server_passwd :
credentials_url = {}
credentials_url['user'] = options.wapt_server_user
credentials_url['password'] = options.wapt_server_passwd
else:
credentials_url = waptguihelper.login_password_dialog('Credentials for wapt server',urlserver,'admin','')
print(options.config)
myWapt = Wapt(config_filename=options.config)
list_arch = ['all']
list_lang = ['fr','en-US','es','de','it']
for lang in list_lang:
for arch in list_arch:
print ('Build %s - %s' % (lang,arch))
control = PackageEntry().load_control_from_wapt ('.')
for exe in glob.glob('*.exe'):
remove_file(exe)
for w in glob.glob('*.wapt'):
remove_file(w)
control.architecture = arch
control.locale = lang.split('-')[0].lower()
control.save_control_to_wapt('.')
thepackage = PackageEntry(waptfile=os.getcwd())
time.sleep(5)
thepackage.call_setup_hook('update_package',wapt_context=myWapt)
myWapt.build_upload(os.getcwd(),private_key_passwd=passwordkey['keypassword'],wapt_server_user=credentials_url['user'],wapt_server_passwd=credentials_url['password'],set_maturity=options.maturity)
if __name__ == '__main__':
import sys
if len(sys.argv) > 1 :
build_all_package()
else:
update_package()
def get_proxies():
if platform.python_version_tuple()[0] == '3':
from urllib.request import getproxies
else:
from urllib import getproxies
return getproxies()
def get_proxies_from_wapt_console():
proxies = {}
if platform.system() == 'Windows':
waptconsole_ini_path = makepath(user_local_appdata(), 'waptconsole', 'waptconsole.ini')
else:
waptconsole_ini_path = makepath(user_home_directory(), '.config', 'waptconsole', 'waptconsole.ini')
if isfile(waptconsole_ini_path):
proxy_wapt = inifile_readstring(waptconsole_ini_path, 'global', 'http_proxy')
if proxy_wapt:
proxies = {'http': proxy_wapt, 'https': proxy_wapt}
return proxies
def get_version_from_binary(filename):
if filename.endswith('.msi'):
return get_msi_properties(filename)['ProductVersion']
else:
return get_file_properties(filename)['FileVersion']
def remove_outdated_binaries(version, list_extensions=['exe','msi','deb','rpm','dmg','pkg'], list_filename_contain=None):
if type(list_extensions) != list:
list_extensions = [list_extensions]
if list_filename_contain:
if type(list_filename_contain) != list:
list_filename_contain = [list_filename_contain]
list_extensions = ['.' + ext for ext in list_extensions if ext[0] != '.']
for file_ext in list_extensions:
for bin_in_dir in glob.glob('*%s' % file_ext):
if not version in bin_in_dir:
remove_file(bin_in_dir)
if list_filename_contain:
for filename_contain in list_filename_contain:
if not filename_contain in bin_in_dir:
remove_file(bin_in_dir)
def bs_find(url, element, attribute=None, value=None, headers=None, proxies=None, features='html.parser', **kwargs):
""""You may need to use a header for some websites. For example: headers={'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Firefox/78.0'}
"""
import requests
page = requests.get(url, proxies=proxies, headers=headers, **kwargs).text
try:
import bs4 as BeautifulSoup
soup = BeautifulSoup.BeautifulSoup(page, features=features)
except:
import BeautifulSoup
soup = BeautifulSoup.BeautifulSoup(page)
if value:
return soup.find(element,{attribute:value})
else:
return soup.find(element)
def bs_find_all(url, element, attribute=None, value=None, headers=None, proxies=None, features='html.parser', **kwargs):
""""You may need to use a header for some websites. For example: headers={'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Firefox/78.0'}
"""
import requests
page = requests.get(url, proxies=proxies, headers=headers, **kwargs).text
try:
import bs4 as BeautifulSoup
soup = BeautifulSoup.BeautifulSoup(page, features=features)
except:
import BeautifulSoup
soup = BeautifulSoup.BeautifulSoup(page)
if value:
return soup.findAll(element,{attribute:value})
else:
return soup.findAll(element)