1
0

Impostazione della classe per fare il build di tutte le versioni di base.

This commit is contained in:
Emiliano Vavassori 2022-03-20 00:53:43 +01:00
parent e51cf40b76
commit e87d4085fb

View File

@ -2,7 +2,7 @@
import urllib.request
from lxml import etree
import tempfile, os, sys, subprocess, shutil
import tempfile, os, sys, glob, subprocess, shutil
class Build(object):
LANGSTD = [ 'ar', 'de', 'en-GB', 'es', 'fr', 'it', 'ja', 'ko', 'pt', 'pt-BR', 'ru', 'zh-CN', 'zh-TW' ]
@ -55,63 +55,96 @@ class Build(object):
# * all languages, no help
# * all languages + offline help
# Let's start with the quickest build: standard languages, no help.
# Preparation tasks
appnamedir = os.path.join(self.__builddir__, self.__appname__)
appimagedir = os.path.join(self.__builddir__, self.__appname__, self.__appname__ + '.AppDir')
os.makedirs(appimagedir, exist_ok = True)
# And then cd to the appname folder.
os.chdir(appnamedir)
# Download appimagetool from github
appimagetoolurl = "https://github.com/AppImage/AppImageKit/releases/download/continuous/appimagetool-{arch}.AppImage".format(arch = self.__arch__)
urllib.request.urlretrieve(appimagetoolurl, 'appimagetool')
os.chmod('appimagetool', 0o755)
# Run to build standard no help
self.__unpackbuild__('standard', False)
# Run to build standard full help
self.__unpackbuild__('standard', True)
# Build full no help
self.__unpackbuild__('full', False)
# Full with help
self.__unpackbuild__('full', True)
def __unpackbuild__(self, languageset = 'full', offlinehelp = False):
# We start by filtering out tarballs from the list
buildtarballs = [ self.__tarballs__[0] ]
# Let's process standard languages and append results to the
# buildtarball
for lang in Build.LANGSTD:
buildtarballs.extend([ x for x in self.__tarballs__ if ('langpack_' + lang) in x ])
# If it was a build with offline help, another extend would have
# solved it:
#buildtarballs.extend([ x for x in self.__tarballs__ if ('helppack_'+ lang) in x ])
# Creating a subfolder
os.makedirs(os.path.join(self.__builddir__, self.__appname__, self.__appname__ + '.AppDir'), exist_ok = True)
# And then cd to the appname folder.
os.chdir(os.path.join(self.__builddir__, self.__appname__))
if languageset == 'standard':
for lang in Build.LANGSTD:
buildtarballs.extend([ x for x in self.__tarballs__ if ('langpack_' + lang) in x ])
if offlinehelp:
buildtarballs.extend([ x for x in self.__tarballs__ if ('helppack_' + lang) in x ])
else:
# In any other cases, we build with all languages
if not offlinehelp:
buildtarballs.extend([ x for x in self.__tarballs__ if 'langpack_' in x ])
else:
# We need also all help. Let's replace buildtarball with the
# whole bunch
buildtarballs = self.__tarballs__
# Unpacking the tarballs
for archive in buildtarballs:
subprocess.run("tar xzf ../%s" % archive, shell=True)
os.chdir(appimagedir)
# At this point, let's decompress the deb packages
os.chdir(os.path.join(self.__builddir__, self.__appname__, self.__appname__ + '.AppDir'))
subprocess.run("find .. -iname '*.deb' -exec dpkg -x {} . \;", shell=True)
# Changing desktop file
subprocess.run("find . -iname startcenter.desktop -exec cp {} . \;", shell=True)
#subprocess.run("sed -i -e 's|Name=.*|Name=%s|g' startcenter.desktop" % self.__appname__, shell=True)
binaryname = subprocess.check_output("awk 'BEGIN { FS = \"=\" } /^Exec/ { print $2; exit }' startcenter.desktop | awk '{ print $1 }'", shell=True).decode('utf-8').strip('\n')
subprocess.run("find . -name '*startcenter.png' -path '*hicolor*48x48*' -exec cp {} . \;", shell=True)
os.makedirs(os.path.join(self.__builddir__, self.__appname__, self.__appname__ + '.AppDir', 'usr', 'bin'), exist_ok = True)
os.chdir(os.path.join(self.__builddir__, self.__appname__, self.__appname__ + '.AppDir', 'usr', 'bin'))
# Find the name of the binary called in the desktop file.
binaryname = subprocess.check_output("awk 'BEGIN { FS = \"=\" } /^Exec/ { print $2; exit }' startcenter.desktop | awk '{ print $1 }'", shell=True).decode('utf-8').strip('\n')
bindir=os.path.join(self.__builddir__, self.__appname__, self.__appname__ + '.AppDir', 'usr', 'bin')
os.makedirs(bindir, exist_ok = True)
os.chdir(bindir)
subprocess.run("find ../../opt -name soffice -path '*programm*' -exec ln -s {} %s \;" % binaryname, shell=True)
os.chdir(os.path.join(self.__builddir__, self.__appname__, self.__appname__ + '.AppDir'))
os.chdir(appimagedir)
# Download AppRun from github
apprunurl = "https://github.com/AppImage/AppImageKit/releases/download/continuous/AppRun-{arch}".format(arch = self.__arch__)
urllib.request.urlretrieve(apprunurl, 'AppRun')
os.chmod('AppRun', 0o755)
os.chdir(os.path.join(self.__builddir__, self.__appname__))
# Download appimagetool from github
appimagetoolurl = "https://github.com/AppImage/AppImageKit/releases/download/continuous/appimagetool-{arch}.AppImage".format(arch = self.__arch__)
urllib.request.urlretrieve(appimagetoolurl, 'appimagetool')
os.chmod('appimagetool', 0o755)
# Setting app version
appversion = self.__version__ + '.standard'
appversion = self.__version__ + '.' + languageset
if offlinehelp:
appversion += '.help'
# Building app
subprocess.run("VERSION={version} ./appimagetool -v ./{appname}.AppDir/".format(version = appversion, appname = self.__appname__), shell=True)
# Copying built image to final directory
subprocess.run("find . -iname '*.AppImage' -exec cp {} %s \;" % outdir, shell = True)
os.chdir('/tmp')
# Cleanup phase, before new run.
os.chdir(appnamedir)
for deb in glob.glob(appnamedir + '/*.deb'):
os.remove(deb)
shutil.rmtree(appimagedir)
os.makedirs(appimagedir)
def __del__(self):
"""Destructor"""
#del self.__builddir__