Skip to content
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
executable file 122 lines (107 sloc) 4.12 KB
#!/usr/bin/env python
import argparse
import ConfigParser
import logging
import os
import re
import subprocess
import sys
import tempfile
logger = logging.getLogger()
def get_passenger(repo, tag, root):"Git cloning passenger %s to %s", tag, root)
clone_cmd = ['git', 'clone', '--branch', tag, repo, root]
logger.debug("Executing %s", ' '.join(clone_cmd))
process = subprocess.Popen(clone_cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
out, err = process.communicate()
exit_code = process.returncode
if exit_code != 0:
logger.error("Clone error: %s", out + err)
return False
subm_cmd = ['git', 'submodule', 'update', '--init', '--recursive']
logger.debug("Executing %s", ' '.join(subm_cmd))
process = subprocess.Popen(subm_cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=root)
out, err = process.communicate()
exit_code = process.returncode
if exit_code != 0:
logger.error("Submodule error: %s", out + err)
return False
return True
def build_packages(passenger, cache, output, work, dists, debug):
rpms = []
srpms = []
dist = ' '.join(dists)
build_path = os.path.join(passenger, 'packaging/rpm', 'build')
cmd = [
build_path, '-p', passenger,
'-c', cache, '-o', output, '-w', work,
'-a', 'x86_64', '-d', dist, '-t', 'rpm:all'
]"Building packages for %s", dist)
logger.debug("Executing: %s", ' '.join(cmd))
process = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
while True:
stdout = process.stdout.readline()
if stdout == '' and process.poll() is not None:
print stdout
if stdout and debug:
print stdout
rc = process.poll()
if rc != 0:
logger.error("Failed to build packages, rc=%s work=%s output=%s", rc, work, output)
return False, False
for d in dists:
rpm_dir = os.path.join(output, d)
if not os.path.isdir(rpm_dir):
logger.error("RPM Directory %s not found", rpm_dir)
return False, False
for f in os.listdir(rpm_dir):
path = os.path.join(rpm_dir, f)
if path.endswith('src.rpm'):"Found SRPM: %s", path)
elif path.endswith('.rpm'):"Found RPM: %s", path)
return rpms, srpms
def main():
usage_examples = """
Usage examples:
Build passenger and nginx RPMs
%(prog)s --work /work --output /output --dist el7
parser = argparse.ArgumentParser(formatter_class=argparse.RawDescriptionHelpFormatter, epilog=usage_examples)
parser.add_argument('-d', '--debug', action='store_true', default=False)
parser.add_argument('-w', '--work', required=True)
parser.add_argument('-o', '--output', required=True)
parser.add_argument('-D', '--dist', nargs='+', required=True)
args = parser.parse_args()
if args.debug:
log_level = logging.DEBUG
log_level = logging.INFO
ch = logging.StreamHandler()
formatter = logging.Formatter('[%(asctime)s] %(levelname)s: %(message)s')
config_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'passenger-nginx.ini')
config = ConfigParser.ConfigParser()
logger.debug("Loading config file %s", config_path)
repo = config.get('main', 'repo')
tag = config.get('main', 'tag')
passenger_root = tempfile.mkdtemp(prefix='/tmp/')
cache_dir = tempfile.mkdtemp(prefix='/tmp/')
output_dir = args.output
work_dir =
logger.debug("passenger=%s cache=%s output=%s work=%s", passenger_root, cache_dir, output_dir, work_dir)
success = get_passenger(repo, tag, passenger_root)
if not success:
rpms, srpms = build_packages(passenger_root, cache_dir, output_dir, work_dir, args.dist, args.debug)
if not rpms or not srpms:
if __name__ == '__main__':
You can’t perform that action at this time.