2022-03-20 23:57:45 +01:00
#!/usr/bin/env python
# encoding: utf-8
2023-01-07 02:03:31 +01:00
""" Helps with command line commands. """
2022-03-20 23:57:45 +01:00
2023-01-07 02:03:31 +01:00
import json
2022-03-20 23:57:45 +01:00
import click
2022-03-31 01:50:15 +02:00
import yaml
2023-01-07 02:03:31 +01:00
import loaih
import loaih . build
2022-03-20 23:57:45 +01:00
2022-04-30 16:58:00 +02:00
@click.group ( )
def cli ( ) :
2023-01-07 02:03:31 +01:00
""" Helps with command line commands. """
2022-04-30 16:58:00 +02:00
@cli.command ( )
2023-01-07 02:03:31 +01:00
@click.option ( ' -j ' , ' --json ' , ' jsonout ' , default = False , is_flag = True ,
help = " Output format in json. " )
2022-04-30 16:58:00 +02:00
@click.argument ( ' query ' )
def getversion ( query , jsonout ) :
2023-01-07 02:03:31 +01:00
""" Get the numeral version from a named version. """
batch = [ ]
2022-04-30 16:58:00 +02:00
queries = [ ]
if ' , ' in query :
queries . extend ( query . split ( ' , ' ) )
else :
queries . append ( query )
2023-01-07 02:03:31 +01:00
for singlequery in queries :
batch . extend ( loaih . Base . collectedbuilds ( singlequery ) )
2022-04-30 16:58:00 +02:00
2023-01-07 02:03:31 +01:00
if len ( batch ) > 0 :
2022-04-30 16:58:00 +02:00
if jsonout :
2023-01-07 02:03:31 +01:00
click . echo ( json . dumps ( [ x . todict ( ) for x in batch ] ) )
2022-04-30 16:58:00 +02:00
else :
2023-01-07 02:03:31 +01:00
for value in batch :
click . echo ( value )
2022-04-30 16:58:00 +02:00
@cli.command ( )
2023-01-07 02:03:31 +01:00
@click.option ( ' -a ' , ' --arch ' , ' arch ' , default = ' all ' ,
type = click . Choice ( [ ' x86 ' , ' x86_64 ' , ' all ' ] , case_sensitive = False ) ,
help = " Build the AppImage for a specific architecture. If there is no specific options, the process will build for both architectures (if available). Default: all " )
@click.option ( ' -c/-C ' , ' --check/--no-check ' , ' check ' , default = True ,
help = " Check in the final storage if the queried version is existent. Default: check " )
@click.option ( ' -d ' , ' --download-path ' , ' download_path ' ,
default = ' /var/tmp/downloads ' , type = str ,
help = " Path to the download folder. Default: /var/tmp/downloads " )
@click.option ( ' -l ' , ' --language ' , ' language ' , default = ' basic ' , type = str ,
help = " Languages to be included. Options: basic, standard, full, a language string (e.g. ' it ' ) or a list of languages comma separated (e.g.: ' en-US,en-GB,it ' ). Default: basic " )
@click.option ( ' -o/-O ' , ' --offline-help/--no-offline-help ' , ' offline ' , default = False ,
help = " Include or not the offline help for the chosen languages. Default: no offline help " )
@click.option ( ' -p/-P ' , ' --portable/--no-portable ' , ' portable ' , default = False ,
help = " Create a portable version of the AppImage or not. Default: no portable " )
@click.option ( ' -r ' , ' --repo-path ' , ' repo_path ' , default = ' /mnt/appimage ' ,
type = str , help = " Path to the final storage of the AppImage. Default: /mnt/appimage " )
@click.option ( ' -s/-S ' , ' --sign/--no-sign ' , ' sign ' , default = True ,
help = " Wether to sign the build. Default: sign " )
@click.option ( ' -u/-U ' , ' --updatable/--no-updatable ' , ' updatable ' , default = True ,
help = " Create an updatable version of the AppImage or not. Default: updatable " )
2022-03-20 23:57:45 +01:00
@click.argument ( ' query ' )
2022-03-31 00:24:21 +02:00
def build ( arch , language , offline , portable , updatable , download_path , repo_path , check , sign , query ) :
2023-01-07 02:03:31 +01:00
""" Builds an Appimage with the provided options. """
2022-03-20 23:57:45 +01:00
# Parsing options
2022-03-30 01:47:00 +02:00
arches = [ ]
2022-03-20 23:57:45 +01:00
if arch . lower ( ) == ' all ' :
# We need to build it twice.
2023-01-07 02:03:31 +01:00
arches = [ ' x86 ' , ' x86_64 ' ]
2022-03-20 23:57:45 +01:00
else :
2022-03-31 01:19:51 +02:00
arches = [ arch . lower ( ) ]
2022-03-20 23:57:45 +01:00
2022-03-31 01:50:15 +02:00
if query . endswith ( ' .yml ' ) or query . endswith ( ' .yaml ' ) :
# This is a buildfile. So we have to load the file and pass the build options ourselves.
config = { }
2023-01-07 02:03:31 +01:00
with open ( query , ' r ' , encoding = ' utf-8 ' ) as file :
2022-03-31 01:50:15 +02:00
config = yaml . safe_load ( file )
2022-03-20 23:57:45 +01:00
2022-03-31 01:50:15 +02:00
# With the config file, we ignore all the command line options and set
# generic default.
2023-01-07 02:03:31 +01:00
for cbuild in config [ ' builds ' ] :
2022-03-31 01:50:15 +02:00
# Loop a run for each build.
2023-01-07 02:03:31 +01:00
collection = loaih . build . Collection ( cbuild [ ' query ' ] , arches )
2022-04-30 23:31:06 +02:00
for obj in collection :
# Configuration phase
2023-01-07 02:06:05 +01:00
obj . language = cbuild [ ' language ' ]
obj . offline_help = cbuild [ ' offline_help ' ]
obj . portable = cbuild [ ' portable ' ]
2022-04-30 23:31:06 +02:00
obj . updatable = True
2023-01-07 02:03:31 +01:00
obj . storage_path = " /srv/http/appimage.sys42.eu "
if ' repo ' in config [ ' data ' ] and config [ ' data ' ] [ ' repo ' ] :
obj . storage_path = config [ ' data ' ] [ ' repo ' ]
obj . download_path = " /var/tmp/downloads "
if ' download ' in config [ ' data ' ] and config [ ' data ' ] [ ' download ' ] :
obj . download_path = config [ ' data ' ] [ ' download ' ]
2023-01-05 01:07:12 +01:00
if ' http ' in obj . storage_path :
obj . remoterepo = True
2023-01-07 02:03:31 +01:00
obj . remote_host = " ciccio.libreitalia.org "
if ' remote_host ' in config [ ' data ' ] and config [ ' data ' ] [ ' remote_host ' ] :
obj . remote_host = config [ ' data ' ] [ ' remote_host ' ]
obj . remote_path = " /var/lib/nethserver/vhost/appimages "
if ' remote_path ' in config [ ' data ' ] and config [ ' data ' ] [ ' remote_path ' ] :
obj . remote_path = config [ ' data ' ] [ ' remote_path ' ]
2022-04-30 23:31:06 +02:00
if ' sign ' in config [ ' data ' ] and config [ ' data ' ] [ ' sign ' ] :
obj . sign = True
# Build phase
obj . calculate ( )
if not ' force ' in config [ ' data ' ] or not config [ ' data ' ] [ ' force ' ] :
obj . check ( )
obj . download ( )
obj . build ( )
obj . checksums ( )
2023-01-05 01:59:55 +01:00
if obj . remoterepo and obj . appnamedir :
2023-01-05 01:07:12 +01:00
obj . generalize_and_link ( obj . appnamedir )
2022-04-30 23:31:06 +02:00
obj . publish ( )
2023-01-05 01:07:12 +01:00
if not obj . remoterepo :
obj . generalize_and_link ( )
2022-04-30 23:31:06 +02:00
del obj
2022-03-31 01:50:15 +02:00
2022-04-30 23:31:06 +02:00
else :
collection = loaih . build . Collection ( query , arches )
for obj in collection :
2022-03-31 02:12:46 +02:00
# Configuration phase
2022-04-30 23:31:06 +02:00
obj . language = language
obj . offline_help = offline
obj . portable = portable
obj . updatable = updatable
obj . storage_path = repo_path
obj . download_path = download_path
if sign :
2022-03-31 01:50:15 +02:00
obj . sign = True
2022-04-30 23:31:06 +02:00
# Running phase
2022-03-31 02:12:46 +02:00
obj . calculate ( )
2022-04-30 23:31:06 +02:00
if check :
2022-03-31 02:12:46 +02:00
obj . check ( )
2022-03-31 01:50:15 +02:00
2022-03-31 02:12:46 +02:00
obj . download ( )
2022-03-31 01:50:15 +02:00
obj . build ( )
obj . checksums ( )
obj . publish ( )
2022-04-08 00:56:28 +02:00
obj . generalize_and_link ( )
2022-03-31 01:50:15 +02:00
del obj