def pkg_tarball(self, destdir=None): with fs.mkdtemp() as d: srcroot = join(d, self.pkgname) fs.sh_makedirs(srcroot) # Compilation etc_zarafa = fs.gluejoin(srcroot, self.conf_root) fs.sh_makedirs(etc_zarafa) self.compile_cfg_files(etc_zarafa) # Include source share = fs.gluejoin(srcroot, self.sitepkgs_root) self.include_python_packages(self.repo_basedir, share) self.patch_src(share) # Include dependencies self.include_deps(share) # Generate makefile self.compile_makefile(srcroot) destdir = destdir or d targz_fp = join(destdir, self.targz_name) with archive.tarfile(targz_fp, 'w:gz') as tar: tar.add(d, arcname='') return targz_fp
def do_pkg_rpm(self, destdir=None, targz_fp=None): if not targz_fp: targz_fp = self.pkg_tarball(destdir=destdir) # untar tarball with archive.tarfile(targz_fp, 'r:gz') as tar: tar.extractall(destdir) # create skeleton for rpmbuild rpmbuild_dir = join(destdir, 'rpmbuild') for d in ['RPMS', 'SOURCES', 'SPECS', 'SRPMS', 'BUILD']: d = join(rpmbuild_dir, d) os.makedirs(d) # copy tarball to the right place shutil.copyfile(targz_fp, join(rpmbuild_dir, 'SOURCES', self.targz_name)) # clone spec file specfile = '{0}.spec'.format(self.name) specfile_fp = join(destdir, specfile) shutil.copyfile(join(self.repo_basedir, 'etc', 'packaging', 'skel.spec'), specfile_fp) # extract list of installed files from makefile makefile_fp = join(destdir, self.pkgname, 'Makefile') content = open(makefile_fp, 'rt').read() content = text.safefind('(?s)install:\s*.*', content) files = [] lines = content.split('\n') for line in lines: if '${DESTDIR}' in line: parts = re.split('[ ]', line) path = parts[-1] path = re.sub('^' + re.escape('${DESTDIR}'), '', path) files.append(path) files.sort() # patch spec file context = { '(?m)^(Summary:\s*).*': '\g<1> {0}'.format(self.rpmmeta_summary), '(?m)^(Name:\s*).*': '\g<1> {0}'.format(self.name), '(?m)^(Version:\s*).*': '\g<1> {0}'.format(self.versiontag), '(?m)^(Release:\s*).*': '\g<1> {0}'.format(self.buildnum), '(?m)^(License:\s*).*': '\g<1> {0}'.format(self.license), '(?m)^(Group:\s*).*': '\g<1> {0}'.format(self.rpmmeta_group), '(?m)^(BuildArch:\s*).*': '\g<1> {0}'.format(self.rpmmeta_arch), '(?m)^(Source:\s*).*': '\g<1> {0}'.format(self.targz_name), '(?m)^(BuildRoot:\s*).*': '\g<1> {0}/%{{name}}-buildroot'.format(d), '(?m)^(Requires:\s*).*': '\g<1> {0}'.format(', '.join(self.rpmmeta_requires)), '(?m)^.*[<]desc[>].*': self.rpmmeta_desc, '(?m)^.*[<]files[>].*': '\n'.join(files), } text.patch_file(context, specfile_fp, dest=specfile_fp, literal=False) with warn_only(): run_cmd('rpmbuild -ba {0} --define "_topdir {1}"'.format( specfile_fp, rpmbuild_dir))
def pkg_tarball(self, destdir=None): with fs.mkdtemp() as d: srcroot = join(d, self.pkgname) fs.sh_makedirs(srcroot) # Compilation share_root = fs.gluejoin(srcroot, self.share_root) fs.sh_makedirs(share_root) self.compile_cfg_files(share_root) # Generate makefile self.compile_makefile(srcroot) destdir = destdir or d targz_fp = join(destdir, self.targz_name) with archive.tarfile(targz_fp, 'w:gz') as tar: tar.add(d, arcname='') return targz_fp
def do_pkg_deb(self, destdir=None, targz_fp=None): if not targz_fp: targz_fp = self.pkg_tarball(destdir=destdir) # untar tarball with archive.tarfile(targz_fp, 'r:gz') as tar: tar.extractall(destdir) # clone dh_make dh_make_src = fs.sh_which('dh_make') dh_make = join(destdir, 'dh_make') shutil.copy2(dh_make_src, dh_make) # get rid of dh_make interactive prompt context = { '(?m)^.*my [$]dummy = <STDIN>.*$': '', } text.patch_file(context, dh_make, dest=dh_make, literal=False) pkgloc = join(destdir, self.pkgname) with lcd(pkgloc): # debianize os.environ['DEBFULLNAME'] = self.maintainer_fullname os.environ['DEBEMAIL'] = self.maintainer_email run_cmd('{0} -i -c {1} -e {2} -f {3}'.format( dh_make, self.license, self.maintainer_email, '../{0}'.format(self.targz_name))) # patch control file control_fp = join(pkgloc, 'debian', 'control') context = { '(?m)^(Section:).*$': '\g<1> {0}'.format(self.debmeta_section), '(?m)^(Homepage:).*$': '\g<1> {0}'.format(self.debmeta_homepage), '(?m)^(Depends:.*)$': '\g<1>, {0}'.format(', '.join(self.debmeta_depends)), '(?m)^(Description:).*$': '\g<1> {0}'.format(self.debmeta_desc), '(?m)^ [<]insert long description.*$': ' {0}'.format(self.debmeta_longdesc), } text.patch_file(context, control_fp, dest=control_fp, literal=False) # patch changelog file changelog_fp = join(pkgloc, 'debian', 'changelog') context = { '(?m)^.*[*] Initial release.*$': ' * {0}'.format(self.debmeta_changelog_msg), '(?m)^.*({0} )[(]([0-9._-]+)[)](.*)$'.format(self.name): '\g<1>({0}-{1})\g<3>'.format(self.release, self.buildnum), } text.patch_file(context, changelog_fp, dest=changelog_fp, literal=False) # replace copyright file copyright_fp = join(pkgloc, 'debian', 'copyright') shutil.copyfile( join(self.repo_basedir, 'etc', 'packaging', '{0}.license'.format(self.name)), copyright_fp, ) debian_dir = join(pkgloc, 'debian') fs.rm(debian_dir, 'README.Debian') fs.rm(debian_dir, '*.ex') fs.rm(debian_dir, '*.EX') # build the package with warn_only(): run_cmd('dpkg-buildpackage -rfakeroot -uc -us') # omit pgp signing