jellyfin-build/build_client.py
2020-01-25 14:45:53 -05:00

95 lines
3.1 KiB
Python

#!/usr/bin/env python3
import os, sys, yaml, json, subprocess, datetime
import manifest
cwd = os.getcwd()
def run_os_command(command, environment=None, shell=False):
if shell:
cmd = command
else:
cmd = command.split()
try:
command_output = subprocess.run(
cmd,
env=environment,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
shell=shell
)
except Exception as e:
print(e)
print(command_output)
return command_output.stdout.decode('utf8'), command_output.stderr.decode('utf8'), command_output.returncode
def build_client(project, package, web_target):
# Extract our name and type
project_name = project['name']
project_type = project['type']
# Set out the directories
type_dir = "{}/projects/{}".format(cwd, project_type)
project_dir = "{}/projects/{}/{}".format(cwd, project_type, project_name)
# Check if a build configuration exists and load it
manifest_file = '{}/build.yaml'.format(project_dir)
if not os.path.exists(manifest_file):
print("ERROR: Project {} does not contain a valid 'build.yaml' file.".format(project['name']))
return False
build_cfg = manifest.load_manifest(manifest_file)
project_version = build_cfg['version']
project_packages = build_cfg['packages']
packages_list = list()
if package == 'all':
packages_list = project_packages
else:
if package in project_packages:
packages_list.append(package)
else:
print('ERROR: Package type {} is not valid. Valid packages are:'.format(package))
print('\n > '.join(project_packages))
return False
# move into the project directory
revdir = os.getcwd()
# Build each package type
for package in packages_list:
os.chdir(project_dir)
# We wrap `build` so we expect it to be sane and like what we send it
build_script = './build'
if not os.path.isfile('./build') and os.path.isfile('./build.sh'):
build_script = './build.sh'
subprocess.call('{} -r {} -b {}'.format(build_script, package, web_target), shell=True)
# Move back to the previous directory
os.chdir(revdir)
# Collect artifacts
src_dir = "{}/bin".format(type_dir)
target_dir = "./bin/{}".format(project_name)
# Make the type dir if it doesn't exist
if not os.path.isdir(target_dir):
os.makedirs(target_dir)
# Clean out the old target dir
stdout, stderr, retcode = run_os_command("rm -rf {}/{}".format(target_dir, package))
if retcode:
print('Could not remove old archive: {}'.format(stderr))
return False
# Move the artifacts
stdout, stderr, retcode = run_os_command("mv {}/* {}/".format(src_dir, target_dir), shell=True)
if retcode:
print('Could not move archive: {}'.format(stderr))
return False
# Remove build junk
run_os_command("rm -rf {}".format(src_dir))
return True