def stack_depends(metadata, distro_name, platform_name): """ @return: list of debian stack dependencies @rtype: [str] """ stackdeps = metadata.get('depends', []) stackdeps = ['ros-%s-%s'%(distro_name, redhatify_name(s)) for s in stackdeps] return stackdeps
def make_source_rpm(distro_name, stack_name, stack_version, os_platform_name, staging_dir): """ @param os_platform_name: Name of OS platform/version, e.g. 'spherical' @type os_platform_name: str @return: list of sourcerpm files @rtype: [str] """ rpm_name = 'ros-%s-%s'%(distro_name, redhatify_name(stack_name)) tmpl_d = os.path.join(os.path.dirname(__file__), 'resources', 'sourcerpm') tarball = os.path.join(staging_dir, "%s-%s.tar.bz2"%(stack_name, stack_version)) if not os.path.exists(tarball): raise Exception("tarball must be copied to staging directory first") # keep track of files we've copied in to modify files = [] # make STACK/debian stack_d = os.path.join(staging_dir, stack_name) debian_d = os.path.join(stack_d, 'debian') if not os.path.exists(debian_d): os.makedirs(debian_d) # Files which go into debian dir for f in ['rules', 'compat', 'postinst']: files.append( (os.path.join(tmpl_d, f), os.path.join(debian_d, f)) ) # Files which go into stack dir for f in ['fixpc.py', 'fixbinpath.py', 'fixrpath.py', 'Makefile', 'setup_rpm.sh', 'purge_build.py', 'update_version.py', 'gen_versioned_rpms.py']: files.append( (os.path.join(tmpl_d, f), os.path.join(stack_d, f)) ) # Files which go into stack dir and are different for ros stack if stack_name == 'ros': for f in ['setup_rpm.sh', 'Makefile']: f_src = f+'-ros' files.append( (os.path.join(tmpl_d, f_src), os.path.join(stack_d, f)) ) # Files which go into stack dir and only exist for ros if stack_name == 'ros': for f in ['setup.sh','setup.bash','setup.zsh','.rosinstall']: files.append( (os.path.join(tmpl_d, f), os.path.join(stack_d, f))) for src, dst in files: with open(src, 'r') as f: src_text = f.read() dst_text = src_text.replace('${ROS_DISTRO_NAME}', distro_name) dst_text = dst_text.replace('${ROS_STACK_NAME}', stack_name) dst_text = dst_text.replace('${ROS_STACK_DEBIAN_NAME}', rpm_name) dst_text = dst_text.replace('${ROS_STACK_VERSION}', stack_version) with open(dst, 'w') as f: f.write(dst_text) # copy permission modes s = os.stat(src) os.chmod(dst, s.st_mode) # CONTROL: read in the control YAML data and convert it to an actual control file control_yaml = os.path.join(staging_dir, '%s-%s.yaml'%(stack_name, stack_version)) with open(control_yaml, 'r') as f: metadata = yaml.load(f.read()) if not type(metadata) == dict: raise Exception("invalid control file: %s\nMetadata is [%s]"%(control_yaml, metadata)) # make distro-specific metadata['package'] = rpm_name with open(os.path.join(debian_d, 'control'), 'w') as f: f.write(control_file(metadata, distro_name, os_platform_name).encode('utf-8')) # CHANGELOG with open(os.path.join(debian_d, 'changelog'), 'w') as f: f.write(changelog_file(metadata, os_platform_name).encode('utf-8')) # We must use a build-version starting with a letter greater than r build_version='s$BUILD_VERSION' with open(os.path.join(debian_d, 'changelog.tmp'), 'w') as f: f.write(changelog_file(metadata, os_platform_name, build_version)) # MD5Sum of original stack tar.bz2: with open(os.path.join(stack_d, '%s-%s.md5'%(stack_name, stack_version)),'w') as mf: with open(os.path.join(staging_dir, '%s-%s.tar.bz2'%(stack_name, stack_version)),'r') as f: m = hashlib.md5() m.update(f.read()) mf.write('%s %s\n'%(m.hexdigest(), '../%s-%s.tar.bz2'%(stack_name, stack_version))) # Note: this creates 3 files. A .dsc, a .tar.gz, and a .changes check_call(['dpkg-buildpackage', '-S', '-uc', '-us'], cwd=stack_d) # SOURCE DEB: .dsc plus tarball of debian dir. Ignore the changes for now f_name = "%s_%s-0~%s"%(rpm_name, stack_version, os_platform_name) files = [os.path.join(staging_dir, f_name+ext) for ext in ('.dsc', '.tar.gz')] for f in files: assert os.path.exists(f), "File: %s does not exist"%f return files