2022-03-19 02:34:53 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
|
|
import urllib.request
|
|
|
|
from lxml import etree
|
2022-03-19 21:15:59 +00:00
|
|
|
import tempfile, os, sys, subprocess, shutil
|
2022-03-19 02:34:53 +00:00
|
|
|
|
2022-03-19 21:48:54 +00:00
|
|
|
class Build(object):
|
|
|
|
LANGSTD = [ 'ar', 'de', 'en-GB', 'es', 'fr', 'it', 'ja', 'ko', 'pt', 'pt-BR', 'ru', 'zh-CN', 'zh-TW' ]
|
2022-03-19 02:34:53 +00:00
|
|
|
|
|
|
|
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
|
2022-03-19 21:20:59 +00:00
|
|
|
self.__builddir__ = tempfile.mkdtemp()
|
2022-03-19 02:34:53 +00:00
|
|
|
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.
|
2022-03-19 21:23:11 +00:00
|
|
|
contents = etree.HTML(urllib.request.urlopen(self.__url__).read()).xpath("//td/a")
|
2022-03-19 02:34:53 +00:00
|
|
|
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)
|
|
|
|
|
|
|
|
|
2022-03-19 21:08:20 +00:00
|
|
|
def build(self, outdir):
|
2022-03-19 02:34:53 +00:00
|
|
|
"""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
|
2022-03-19 21:48:54 +00:00
|
|
|
for lang in Build.LANGSTD:
|
2022-03-19 02:34:53 +00:00
|
|
|
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
|
2022-03-19 22:15:31 +00:00
|
|
|
os.makedirs(os.path.join(self.__builddir__, self.__appname__, self.__appname__ + '.AppDir'), exist_ok = True)
|
2022-03-19 02:34:53 +00:00
|
|
|
# And then cd to the appname folder.
|
|
|
|
os.chdir(os.path.join(self.__builddir__, self.__appname__))
|
|
|
|
|
|
|
|
# Unpacking the tarballs
|
|
|
|
for archive in buildtarballs:
|
2022-03-19 21:53:52 +00:00
|
|
|
subprocess.run("tar xzf ../%s" % archive, shell=True)
|
2022-03-19 02:34:53 +00:00
|
|
|
|
|
|
|
# At this point, let's decompress the deb packages
|
2022-03-19 22:15:31 +00:00
|
|
|
os.chdir(os.path.join(self.__builddir__, self.__appname__, self.__appname__ + '.AppDir'))
|
2022-03-19 22:01:14 +00:00
|
|
|
subprocess.run("find .. -iname '*.deb' -exec dpkg -x {} . \;", shell=True)
|
2022-03-19 02:34:53 +00:00
|
|
|
# Changing desktop file
|
2022-03-19 22:01:14 +00:00
|
|
|
subprocess.run("find . -iname startcenter.desktop -exec cp {} . \;", shell=True)
|
2022-03-19 23:01:15 +00:00
|
|
|
#subprocess.run("sed -i -e 's|Name=.*|Name=%s|g' startcenter.desktop" % self.__appname__, shell=True)
|
2022-03-19 21:08:20 +00:00
|
|
|
|
2022-03-19 22:15:31 +00:00
|
|
|
binaryname = subprocess.check_output("awk 'BEGIN { FS = \"=\" } /^Exec/ { print $2; exit }' startcenter.desktop | awk '{ print $1 }'", shell=True).decode('utf-8').strip('\n')
|
2022-03-19 23:08:03 +00:00
|
|
|
subprocess.run("find . -name '*startcenter.png' -path '*hicolor*48x48*' -exec cp {} . \;" % binaryname, shell=True)
|
2022-03-19 22:35:37 +00:00
|
|
|
|
2022-03-19 22:38:26 +00:00
|
|
|
os.makedirs(os.path.join(self.__builddir__, self.__appname__, self.__appname__ + '.AppDir', 'usr', 'bin'), exist_ok = True)
|
2022-03-19 22:15:31 +00:00
|
|
|
os.chdir(os.path.join(self.__builddir__, self.__appname__, self.__appname__ + '.AppDir', 'usr', 'bin'))
|
2022-03-19 22:18:57 +00:00
|
|
|
subprocess.run("find ../../opt -name soffice -path '*programm*' -exec ln -s {} %s \;" % binaryname, shell=True)
|
2022-03-19 22:15:31 +00:00
|
|
|
os.chdir(os.path.join(self.__builddir__, self.__appname__, self.__appname__ + '.AppDir'))
|
2022-03-19 02:34:53 +00:00
|
|
|
|
2022-03-19 21:08:20 +00:00
|
|
|
# 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)
|
2022-03-19 02:34:53 +00:00
|
|
|
|
2022-03-19 21:08:20 +00:00
|
|
|
os.chdir(os.path.join(self.__builddir__, self.__appname__))
|
|
|
|
# Download appimagetool from probonopd repo on github
|
|
|
|
appimagetoolurl = "https://github.com/probonopd/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'
|
|
|
|
# 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)
|
2022-03-19 21:53:52 +00:00
|
|
|
os.chdir('/tmp')
|
2022-03-19 22:40:42 +00:00
|
|
|
|
|
|
|
def __del__(self):
|
2022-03-19 22:15:31 +00:00
|
|
|
del self.__builddir__
|
2022-03-19 21:08:20 +00:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
# Run if it is run as a program.
|
|
|
|
# 1 -> query
|
|
|
|
# 2 -> arch
|
|
|
|
# 3 -> url
|
|
|
|
# 4 -> outdir
|
|
|
|
|
|
|
|
if not len(sys.argv) == 5:
|
|
|
|
print("Please launch with this parameters: build.py query arch url outputdir")
|
|
|
|
sys.exit(255)
|
|
|
|
|
|
|
|
b = Build(sys.argv[1], sys.argv[2], sys.argv[3])
|
|
|
|
b.download()
|
2022-03-19 21:09:11 +00:00
|
|
|
b.build(sys.argv[4])
|
2022-03-19 21:08:20 +00:00
|
|
|
del b
|