Corretto script check build. Costruzione di uno script di build.

This commit is contained in:
Emiliano Vavassori 2022-03-19 03:34:53 +01:00
parent 59ff822ca1
commit c7648c520b
2 changed files with 101 additions and 2 deletions

97
build.py Normal file
View File

@ -0,0 +1,97 @@
#!/usr/bin/env python3
import urllib.request
from lxml import etree
import tempfile, os, subprocess
class Build:
LANGSTD = [ 'en-GB', 'it', 'ar', 'zh-CN', 'zh-TW', 'fr', 'de', 'ja', 'ko', 'pt', 'pt-BR', 'es', 'ru' ]
def __init__(self, query, arch, url):
"""Build all versions that can be found in the indicated repo."""
self.__query__ = query
self.__arch__ = arch
self.__url__ = url
# Creating a tempfile
self.__builddir__ = tempfile.mktempdir()
self.__tarballs__ = []
self.__appname__ = ''
self.__version__ = ''
if self.__url__ == '-':
print("Cannot find this version for arch {arch}.".format(arch = self.__arch__))
return False
def download(self):
"""Downloads the contents of the URL as it was a folder."""
# Let's start with defining which files are to be downloaded.
# Let's explore the remote folder.
contents = etree.HTML(urllib.request.openurl(self.__url__).read()).xpath("//td/a")
self.__tarballs__ = [ x.text for x in contents if x.text.endswith('tar.gz') ]
maintarball = self.__tarballs__[0]
main_arr = maintarball.split('_')
self.__appname__ = main_arr[0]
self.__version__ = main_arr[1]
os.chdir(self.__builddir__)
for archive in self.__tarballs__:
# Download the archive
try:
urllib.request.urlretrieve(self.__url__ + archive, archive)
except:
print("Failed to download {archive}.".format(archive = archive))
print("Got %s." % archive)
def build(self, langset = 'full')
"""Building all the versions."""
# We have 4 builds to do:
# * standard languages, no help
# * standard languages + offline help
# * all languages, no help
# * all languages + offline help
# Let's start with the quickest build: standard languages, no help.
# 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 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__ + '.AppImage'), exist_ok = True)
# And then cd to the appname folder.
os.chdir(os.path.join(self.__builddir__, self.__appname__))
# Unpacking the tarballs
for archive in buildtarballs:
subprocess.call("tar xzf ../%s.tar.gz" % archive, shell=True)
# At this point, let's decompress the deb packages
os.chdir(os.path.join(self.__builddir__, self.__appname__, self.__appname__ + '.AppImage'))
subprocess.call("find .. -iname '*.deb' -exec dpkg -x {} . \+", shell=True)
# Changing desktop file
subprocess.call("find . -iname startcenter.desktop -exec cp {} . \+", shell=True)
subprocess.call("sed -i -e 's|Name=.*|Name=%s|g' startcenter.desktop" % self.__appname__, shell=True)
subprocess.call("find . -name startcenter.png -path '*hicolor*48x48*' -exec cp {} \;", shell=True)
binaryname = subprocess.check_output("cat startcenter.desktop | awk 'BEGIN { FS = \"=\" } /^Exec/ { print $2; exit }' | awk '{ print $1 }'", shell=True).strip('\n')
subprocess.call("rm -f usr/bin/%s" % binaryname, shell=True)
subprocess.call("find opt -name soffice -path '*programm*' -exec ln -s {} usr/bin/%si \;" % binaryname, shell=True)
# Arrivato a riga 501

View File

@ -7,7 +7,9 @@ shift 2
count=$(find "${storage}" -iname "*${version}*.AppImage" | wc -l)
if [[ ${count} -eq 0 ]]; then
echo "status: built"
else
echo "status: not built"
exit 1
else
echo "status: built"
# Nothing more to do!
fi