jellyfin-build/build_ffmpeg.py

90 lines
2.7 KiB
Python
Raw Normal View History

2019-03-07 04:47:55 +00:00
#!/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_ffmpeg(project, package):
# 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)
# Get release and architecture
release, architecture = package.split('-')
# We wrap `build` so we expect it to be sane and like what we send it
subprocess.call('./build {} {}'.format(release, architecture), 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)
# 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