def build(obj, source_dir, force, package_names): """ Build Packages """ # Setup Paths and Vars bld_dir = obj['build_dir'] src_dir = os.path.abspath(source_dir) exp_dir = os.path.join(bld_dir, _BUILD_SRC_DIR) out_dir = os.path.join(bld_dir, _BUILD_PKG_DIR) os.makedirs(out_dir, exist_ok=True) pkgs_succeeded = [] pkgs_skipped = [] pkgs_failed = [] # Export Source via Git cmd = ["git", "checkout-index", "-a", "-f", "--prefix={}/".format(exp_dir)] proc = subprocess.Popen(cmd, cwd=src_dir, stdout=subprocess.PIPE, stderr=subprocess.PIPE) out, err = proc.communicate() if proc.returncode: raise click.ClickException("Git Export Failed") # Find Package Sources src_repo = cu_apt.src_repo(exp_dir) # Find Built Packages deb_repo = cu_apt.deb_repo(out_dir) # Filter Packages pkgs_queued = [] if package_names: for pkg_name in sorted(package_names): found = False for pkg_key in src_repo: pkg = src_repo[pkg_key] if pkg_name == pkg.name: found = True pkgs_queued.append(pkg_key) continue if not found: click.secho("Could Not Find Package '{}'".format(pkg_name), err=True, fg='red') else: pkgs_queued += src_repo.keys() # Find Newer Sources if not force: for src_pkg_key in sorted(pkgs_queued): for deb_pkg_key in deb_repo: if src_repo[src_pkg_key].name == deb_repo[deb_pkg_key].name: pkg_ver = src_repo[src_pkg_key].vers deb_ver = deb_repo[deb_pkg_key].vers if pkg_ver <= deb_ver: click.secho( "Skipping {}:".format(src_pkg_key) + " Version {} already built".format(deb_ver), fg='yellow') pkgs_skipped.append(src_pkg_key) pkgs_queued.remove(src_pkg_key) continue # Build Packages cmd = ["equivs-build", "-f", "control"] for pkg_key in sorted(pkgs_queued): pkg_src_dir = src_repo[pkg_key].path deb_src_dir = os.path.join(pkg_src_dir, _DEB_DIR) click.secho("Building {}...".format(pkg_key), fg='blue') proc = subprocess.Popen(cmd, cwd=deb_src_dir, stdout=subprocess.PIPE, stderr=subprocess.PIPE) stdout, stderr = proc.communicate() if proc.returncode: click.secho("{} Build Failed".format(pkg_key), err=True, fg='red') click.secho(stderr.decode(_ENCODING), err=True, fg='red') pkgs_failed.append(pkg_key) else: click.secho("{} Build Succeeded".format(pkg_key), fg='green') pkgs_succeeded.append(pkg_key) for src_name in os.listdir(deb_src_dir): src_path = os.path.join(deb_src_dir, src_name) if os.path.splitext(src_path)[1] in _DEB_BUILD_EXTS: dst_path = os.path.join(out_dir, src_name) if os.path.exists(dst_path): os.remove(dst_path) shutil.move(src_path, dst_path) # Print Success/Failure click.secho("") if pkgs_succeeded: pkgs_succeeded.sort() click.secho("Succeeded Packages:\n{}".format(pkgs_succeeded), fg='green') if pkgs_skipped: pkgs_skipped.sort() click.secho("Skipped Packages:\n{}".format(pkgs_skipped), fg='yellow') if pkgs_failed: pkgs_failed.sort() click.secho("Failed Packages:\n{}".format(pkgs_failed), err=True, fg='red')
def build(obj, source_dir, force, package_names): """ Build Packages """ # Setup Paths and Vars bld_dir = obj['build_dir'] src_dir = os.path.abspath(source_dir) exp_dir = os.path.join(bld_dir, _BUILD_SRC_DIR) out_dir = os.path.join(bld_dir, _BUILD_PKG_DIR) os.makedirs(out_dir, exist_ok=True) pkgs_succeeded = [] pkgs_skipped = [] pkgs_failed = [] # Export Source via Git cmd = ["git", "checkout-index", "-a", "-f", "--prefix={}/".format(exp_dir)] proc = subprocess.Popen(cmd, cwd=src_dir, stdout=subprocess.PIPE, stderr=subprocess.PIPE) out, err = proc.communicate() if proc.returncode: raise click.ClickException("Git Export Failed") # Find Package Sources src_repo = cu_apt.src_repo(exp_dir) # Find Built Packages deb_repo = cu_apt.deb_repo(out_dir) # Filter Packages pkgs_queued = [] if package_names: for pkg_name in sorted(package_names): found = False for pkg_key in src_repo: pkg = src_repo[pkg_key] if pkg_name == pkg.name: found = True pkgs_queued.append(pkg_key) continue if not found: click.secho("Could Not Find Package '{}'".format(pkg_name), err=True, fg='red') else: pkgs_queued += src_repo.keys() # Find Newer Sources if not force: for src_pkg_key in sorted(pkgs_queued): for deb_pkg_key in deb_repo: if src_repo[src_pkg_key].name == deb_repo[deb_pkg_key].name: pkg_ver = src_repo[src_pkg_key].vers deb_ver = deb_repo[deb_pkg_key].vers if pkg_ver <= deb_ver: click.secho("Skipping {}:".format(src_pkg_key) + " Version {} already built".format(deb_ver), fg='yellow') pkgs_skipped.append(src_pkg_key) pkgs_queued.remove(src_pkg_key) continue # Build Packages cmd = ["equivs-build", "-f", "control"] for pkg_key in sorted(pkgs_queued): pkg_src_dir = src_repo[pkg_key].path deb_src_dir = os.path.join(pkg_src_dir, _DEB_DIR) click.secho("Building {}...".format(pkg_key), fg='blue') proc = subprocess.Popen(cmd, cwd=deb_src_dir, stdout=subprocess.PIPE, stderr=subprocess.PIPE) stdout, stderr = proc.communicate() if proc.returncode: click.secho("{} Build Failed".format(pkg_key), err=True, fg='red') click.secho(stderr.decode(_ENCODING), err=True, fg='red') pkgs_failed.append(pkg_key) else: click.secho("{} Build Succeeded".format(pkg_key), fg='green') pkgs_succeeded.append(pkg_key) for src_name in os.listdir(deb_src_dir): src_path = os.path.join(deb_src_dir, src_name) if os.path.splitext(src_path)[1] in _DEB_BUILD_EXTS: dst_path = os.path.join(out_dir, src_name) if os.path.exists(dst_path): os.remove(dst_path) shutil.move(src_path, dst_path) # Print Success/Failure click.secho("") if pkgs_succeeded: pkgs_succeeded.sort() click.secho("Succeeded Packages:\n{}".format(pkgs_succeeded), fg='green') if pkgs_skipped: pkgs_skipped.sort() click.secho("Skipped Packages:\n{}".format(pkgs_skipped), fg='yellow') if pkgs_failed: pkgs_failed.sort() click.secho("Failed Packages:\n{}".format(pkgs_failed), err=True, fg='red')
def publish(obj, repo_dir, release, major_vers): """ Publish Packages to Repo """ # Setup Paths and Vars bld_dir = obj['build_dir'] out_dir = os.path.join(bld_dir, _BUILD_PKG_DIR) repo_dir = os.path.abspath(repo_dir) pkgs_succeeded = [] pkgs_skipped = [] pkgs_failed = [] def get_repo_info(pkg_name, pkg_arch, release, attribute): cmd = [ "reprepro", "-T", "deb", "-A", "{}".format(pkg_arch), "--list-format", "'${{{}}}'".format(attribute), "list", "{}".format(release), "{}".format(pkg_name) ] proc = subprocess.Popen(cmd, cwd=repo_dir, stdout=subprocess.PIPE, stderr=subprocess.PIPE) out, err = proc.communicate() if err: click.secho(err.decode(_ENCODING), err=True, fg='red') if proc.returncode: raise click.ClickException("reprepro List Failed") return out.decode(_ENCODING).lstrip().rstrip().lstrip("'").rstrip("'") def repo_publish_deb(pkg_path, release): cmd = [ "reprepro", "-s", "includedeb", "{}".format(release), "{}".format(pkg_path) ] proc = subprocess.Popen(cmd, cwd=repo_dir, stdout=subprocess.PIPE, stderr=subprocess.PIPE) out, err = proc.communicate() if err: click.secho(err.decode(_ENCODING), err=True, fg='red') if proc.returncode: raise click.ClickException("reprepro Publish Failed") return out.decode(_ENCODING).lstrip().rstrip() def repo_publish_dsc(pkg_path, release): cmd = [ "reprepro", "-s", "includedsc", "{}".format(release), "{}".format(pkg_path) ] proc = subprocess.Popen(cmd, cwd=repo_dir, stdout=subprocess.PIPE, stderr=subprocess.PIPE) out, err = proc.communicate() if proc.returncode: click.secho(err.decode(_ENCODING), err=True, fg='red') raise click.ClickException("reprepro Publish Failed") return out.decode(_ENCODING).lstrip().rstrip() # Setup Source Repos deb_repo = cu_apt.deb_repo(out_dir) # Publish Packages for pkg_key in sorted(deb_repo): # Get Package Info pkg = deb_repo[pkg_key] click.secho("Publishing {}...".format(pkg.key), fg='blue') # Filter Packages if major_vers: pkg_major_vers = pkg.vers.split('.')[0] if pkg_major_vers != major_vers: click.secho( "Skipping: Wrong Major Version {}".format(pkg_major_vers), fg='yellow') pkgs_skipped.append(pkg.key) continue # Get Repo Version if pkg.arch == "all": repo_vers_amd64 = get_repo_info(pkg.name, "amd64", release, "version") repo_vers_i386 = get_repo_info(pkg.name, "i386", release, "version") if repo_vers_amd64 != repo_vers_i386: click.secho("Architecture Version Mismatch", err=True, fg='red') pkgs_failed.append(pkg.key) continue else: repo_vers = repo_vers_amd64 else: repo_vers = get_repo_info(pkg.name, pkg.arch, release, "version") # Compare Versions if pkg.vers == repo_vers: click.secho("Skipping: Version {} already in repo.".format( pkg.vers), fg='yellow') pkgs_skipped.append(pkg.key) continue # Publish repo_publish_deb(pkg.path, release) print(pkg.path) click.secho("Publishing {} deb Succeeded".format(pkg.key), fg='green') # Publish Source # ToDo pkgs_succeeded.append(pkg.key) # Print Success/Failure click.secho("") if pkgs_succeeded: pkgs_succeeded.sort() click.secho("Succeeded Packages:\n{}".format(pkgs_succeeded), fg='green') if pkgs_skipped: pkgs_skipped.sort() click.secho("Skipped Packages:\n{}".format(pkgs_skipped), fg='yellow') if pkgs_failed: pkgs_failed.sort() click.secho("Failed Packages:\n{}".format(pkgs_failed), err=True, fg='red')
def publish(obj, repo_dir, release, major_vers): """ Publish Packages to Repo """ # Setup Paths and Vars bld_dir = obj['build_dir'] out_dir = os.path.join(bld_dir, _BUILD_PKG_DIR) repo_dir = os.path.abspath(repo_dir) pkgs_succeeded = [] pkgs_skipped = [] pkgs_failed = [] def get_repo_info(pkg_name, pkg_arch, release, attribute): cmd = ["reprepro", "-T", "deb", "-A", "{}".format(pkg_arch), "--list-format", "'${{{}}}'".format(attribute), "list", "{}".format(release), "{}".format(pkg_name)] proc = subprocess.Popen(cmd, cwd=repo_dir, stdout=subprocess.PIPE, stderr=subprocess.PIPE) out, err = proc.communicate() if err: click.secho(err.decode(_ENCODING), err=True, fg='red') if proc.returncode: raise click.ClickException("reprepro List Failed") return out.decode(_ENCODING).lstrip().rstrip().lstrip("'").rstrip("'") def repo_publish_deb(pkg_path, release): cmd = ["reprepro", "-s", "includedeb", "{}".format(release), "{}".format(pkg_path)] proc = subprocess.Popen(cmd, cwd=repo_dir, stdout=subprocess.PIPE, stderr=subprocess.PIPE) out, err = proc.communicate() if err: click.secho(err.decode(_ENCODING), err=True, fg='red') if proc.returncode: raise click.ClickException("reprepro Publish Failed") return out.decode(_ENCODING).lstrip().rstrip() def repo_publish_dsc(pkg_path, release): cmd = ["reprepro", "-s", "includedsc", "{}".format(release), "{}".format(pkg_path)] proc = subprocess.Popen(cmd, cwd=repo_dir, stdout=subprocess.PIPE, stderr=subprocess.PIPE) out, err = proc.communicate() if proc.returncode: click.secho(err.decode(_ENCODING), err=True, fg='red') raise click.ClickException("reprepro Publish Failed") return out.decode(_ENCODING).lstrip().rstrip() # Setup Source Repos deb_repo = cu_apt.deb_repo(out_dir) # Publish Packages for pkg_key in sorted(deb_repo): # Get Package Info pkg = deb_repo[pkg_key] click.secho("Publishing {}...".format(pkg.key), fg='blue') # Filter Packages if major_vers: pkg_major_vers = pkg.vers.split('.')[0] if pkg_major_vers != major_vers: click.secho("Skipping: Wrong Major Version {}".format(pkg_major_vers), fg='yellow') pkgs_skipped.append(pkg.key) continue # Get Repo Version if pkg.arch == "all": repo_vers_amd64 = get_repo_info(pkg.name, "amd64", release, "version") repo_vers_i386 = get_repo_info(pkg.name, "i386", release, "version") if repo_vers_amd64 != repo_vers_i386: click.secho("Architecture Version Mismatch", err=True, fg='red') pkgs_failed.append(pkg.key) continue else: repo_vers = repo_vers_amd64 else: repo_vers = get_repo_info(pkg.name, pkg.arch, release, "version") # Compare Versions if pkg.vers == repo_vers: click.secho("Skipping: Version {} already in repo.".format(pkg.vers), fg='yellow') pkgs_skipped.append(pkg.key) continue # Publish repo_publish_deb(pkg.path, release) print(pkg.path) click.secho("Publishing {} deb Succeeded".format(pkg.key), fg='green') # Publish Source # ToDo pkgs_succeeded.append(pkg.key) # Print Success/Failure click.secho("") if pkgs_succeeded: pkgs_succeeded.sort() click.secho("Succeeded Packages:\n{}".format(pkgs_succeeded), fg='green') if pkgs_skipped: pkgs_skipped.sort() click.secho("Skipped Packages:\n{}".format(pkgs_skipped), fg='yellow') if pkgs_failed: pkgs_failed.sort() click.secho("Failed Packages:\n{}".format(pkgs_failed), err=True, fg='red')