File indexing completed on 2024-04-28 05:37:03

0001 #!/usr/bin/python3
0002 
0003 import argparse
0004 import tempfile
0005 import git
0006 import sys
0007 import stat
0008 import subprocess
0009 import glob
0010 import requests
0011 import shutil
0012 import os
0013 
0014 def merge_path(path,directory):
0015     return os.path.join(path, directory)
0016 
0017 def run_process(args, path):
0018     subprocess.call(args,cwd=path)
0019 
0020 def clone_repo(path,url_repo,name):
0021     git.Git(path).clone(url_repo,"--recurse-submodules",name)
0022 
0023 def move_content(source_file, to):
0024     content = os.listdir(source_file)
0025 
0026     for file_name in content:
0027         shutil.move(os.join.path(source_file, file_name), to)
0028 
0029 
0030 def get_file(url, destination):
0031     print("Downloading {}".format(destination))
0032     r = requests.get(url)
0033     with open(destination, 'wb') as f:
0034         f.write(r.content)
0035 
0036 def release_translation(path):
0037     print("release translation")
0038     print(path)
0039     proArray = glob.glob(merge_path(path,"*.pro"))
0040     run_process(["lrelease",proArray[0]],path)
0041 
0042 def allow_execution(path):
0043     st = os.stat(path)
0044     os.chmod(path, st.st_mode | stat.S_IEXEC)
0045 
0046 
0047 def icon_path(app_name):
0048     print("icon_path")
0049     path_dict={"rolisteam":"resources/logo/rolisteam.svg", "rcse":"resources/logo/rcse.svg","dice":"","rcm":""}
0050     return path_dict[app_name]
0051 
0052 
0053 def build_app(path):
0054     print("build app")
0055     build_directory=merge_path(path, "build")
0056     os.mkdir(build_directory)
0057     release_translation(path)
0058     run_process(["qmake","-r","../","CONFIG+=release","."],build_directory)
0059     run_process(["make","-j8"],build_directory)
0060     return build_directory
0061 
0062 
0063 def build_appimage(path, version, app_name):
0064     print("build appimage")
0065     build_directory = build_app(path)
0066 
0067     linuxdeploy_path=merge_path(path, "linuxdeploy-x86_64.AppImage")
0068     linuxdeployqtplugin_path=merge_path(path, "linuxdeploy-plugin-qt-x86_64.AppImage")
0069     get_file("https://github.com/linuxdeploy/linuxdeploy/releases/download/continuous/linuxdeploy-x86_64.AppImage",linuxdeploy_path)
0070     allow_execution(linuxdeploy_path)
0071     get_file("https://github.com/linuxdeploy/linuxdeploy-plugin-qt/releases/download/continuous/linuxdeploy-plugin-qt-x86_64.AppImage",linuxdeployqtplugin_path)
0072     allow_execution(linuxdeployqtplugin_path)
0073     move_content(merge_path(build_directory,"AppDir/usr/bin/usr/local/bin"), merge_path(build_directory,"AppDir/usr/bin"))
0074     run_process([linuxdeploy_path,"--appdir","../","AppDir","-e","AppDir/usr/bin/{}".format(app_name),"-i","../$ICON_PATH","-d","$DESKTOP_FILE_PATH","--plugin","qt","--output","appimage"],build_directory)
0075     appImageArray = glob.glob(build_directory+"*.AppImage")
0076     shutil.move(appImageArray[0],merge_path(path,"../"))
0077     run_process(["make","install","INSTALL_ROOT=../AppDir/usr/bin/"],buildDirectory)
0078 
0079 def main():
0080     parser = argparse.ArgumentParser(description="Helper script to generate new rolisteam version.")
0081     parser.add_argument("-v","--version", help="Give the version of the software")
0082     parser.add_argument("-p","--package_version",type=int,default=0, help="The package version, default=0")
0083     parser.add_argument("-b","--branch",default="master", help="Git branch to checkout to build")
0084     parser.add_argument("-t","--tarball",action="store_true", help="Generate Tarball")
0085     parser.add_argument("-z","--zip",action="store_true", help="Generate Zip archive")
0086     parser.add_argument("-d","--deb",action="count",default=0, help="Create deb on launchpad: -d to upload to the official launchpad, -dd to upload to the dev launchpad.")
0087     parser.add_argument("-a","--appimage",action="store_true", help="Generate Appimage")
0088     parser.add_argument("-s","--sourceforge",action="store_true", help="Upload result to sourceforge")
0089     #parser.add_argument("-s","--software",default="all", choices=["all","rolisteam","rcse","dice","rcm"], help="List software: all builds everything but rcm.")
0090     parser.add_argument('softwares', metavar='N', nargs='+',choices=["all","rolisteam","rcse","dice","rcm"],
0091                     help='an integer for the accumulator')
0092     args = parser.parse_args()
0093 
0094     #repos=["https://invent.kde.org/rolisteam/rolisteam.git","https://invent.kde.org/rolisteam/rcse.git","https://invent.kde.org/rolisteam/rolisteam-diceparser.git","https://github.com/obiwankennedy/rcm"]
0095     repos=["https://invent.kde.org/rolisteam/rolisteam.git","https://invent.kde.org/rolisteam/rcse.git","https://invent.kde.org/rolisteam/rolisteam-diceparser.git"]
0096     names=["rolisteam","rcse","rolisteam-diceparser","rcm"]
0097 
0098 
0099 
0100     tmpdirname = tempfile.mkdtemp() # dir="./"
0101     print(tmpdirname)
0102     i = 0
0103     for software in args.softwares:
0104         name=software
0105         repo=""
0106         if software == "rolisteam":
0107             repo="https://invent.kde.org/rolisteam/rolisteam.git"
0108         elif software == "rcse":
0109             repo="https://invent.kde.org/rolisteam/rcse.git"
0110         elif software == "dice":
0111             repo="https://invent.kde.org/rolisteam/rolisteam-diceparser.git"
0112         elif software == "rcm":
0113             repo="https://github.com/obiwankennedy/rcm"
0114 
0115         clone_repo("{}".format(tmpdirname),repo, name)
0116         path = os.path.join(tmpdirname,name)
0117 
0118         if args.appimage:
0119             build_appimage(path, args.version,name)
0120 
0121 
0122 
0123 
0124         i+=1
0125 
0126 
0127 if __name__ == '__main__':
0128     main()