PK[}M4ocontrolgraph.py"""Generate build order graph from directory of debian packaging repositories""" __version__ = "0.4.0" import argparse import logging import re import sys from pathlib import Path from subprocess import Popen, run, PIPE, DEVNULL, STDOUT from typing import Dict, List, Tuple import networkx as nx from debian import deb822 L = logging.getLogger("controlgraph") L.addHandler(logging.NullHandler()) class BinaryPackage: def __init__(self, name: str, source: str, build_deps: List[str]) -> None: self.name = name self.source = source self.build_deps = build_deps def __repr__(self) -> str: return "BinaryPackage({})".format(self.__dict__) def parse_controlfile(path: Path) -> Dict[str, BinaryPackage]: source = "" build_deps = [] pkgs = {} with path.open() as f: for src in deb822.Sources.iter_paragraphs(f): if "Source" in src: source = src["Source"] build_deps.extend( [ re.sub(r" \([^\)]*\)", "", s.strip()).strip() for s in src["Build-Depends"].split(",") ] ) elif "Package" in src: pkgs[src["Package"]] = BinaryPackage(src["Package"], source, build_deps) return pkgs def graph(dirs: List[Path]) -> nx.DiGraph: """Prints linear or dot graph build order.""" # Get dict matching binary packages to source packages/build deps pkgs = {} for p in dirs: controlfile = Path(p / "debian/control") if not controlfile.exists(): continue pkgs.update(parse_controlfile(controlfile)) # Get dict matching source package to build deps build_deps = {v.source: v.build_deps for _, v in pkgs.items()} # Get dict matching binary package to source package src_pkgs = {v.name: v.source for _, v in pkgs.items()} # Convert binary build deps to source packages (if available locally) for repo in build_deps: src_deps = [] for dep in build_deps[repo]: if dep in src_pkgs: src_deps.append(src_pkgs[dep]) build_deps[repo] = src_deps # Create graph from build deps graph = nx.DiGraph() for k, v in build_deps.items(): graph.add_node(k) graph.add_nodes_from(v) for dep in v: graph.add_edge(k, dep) return graph def main() -> int: parser = argparse.ArgumentParser(description=__doc__) parser.add_argument( "--version", "-V", action="store_true", help="print program version" ) parser.add_argument( "--verbose", "-v", help="-v for info, -vv for debug", action="count", default=0 ) parser.add_argument( "directories", type=Path, nargs="*", help="directories to graph" ) group_graph_type = parser.add_mutually_exclusive_group() group_graph_type.add_argument( "--linear", "-l", dest="linear", action="store_true", default="true", help="return linear list of build dependencies", ) group_graph_type.add_argument( "--graph", "-g", dest="linear", action="store_false", help="return dot graph of build dependencies", ) args = parser.parse_args() if args.version: print("controlgraph {}".format(__version__)) return 0 # set up logging logging.basicConfig( format="[%(levelname)s] %(message)s", level=10 * (3 - min(args.verbose, 2)) ) if len(args.directories) == 0: args.directories = [p for p in Path.cwd().iterdir() if p.is_dir()] # Get graph and print g = graph(args.directories) if args.linear: # Put all isolated nodes first in list isolates = list(nx.isolates(g)) g.remove_nodes_from(isolates) build_order = list(nx.dfs_postorder_nodes(g)) print(" ".join(isolates + build_order)) else: nx.nx_pydot.write_dot(g, sys.stdout) return 0 if __name__ == "__main__": sys.exit(main()) PK!H\;!(2-controlgraph-0.4.0.dist-info/entry_points.txtN+I/N.,() %d"sr3PKMEz44$controlgraph-0.4.0.dist-info/LICENSEThe MIT License (MIT) Copyright (c) 2018 Dell inc. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. PK!HSmPO"controlgraph-0.4.0.dist-info/WHEEL HM K-*ϳR03rOK-J,/RH,rzd&Y)r$[)T&UrPK!H3%controlgraph-0.4.0.dist-info/METADATAT[O0~8DBT"e4Ь@jT 0;ejP)$ .Ax3!30hgUyFs @iY8%:U/1\LX d*\!( ~7U2Mj'ZFHλ5ub=KԳdWV !ލRk,~ߌka]Yn]׉r8aOo&dM? Fk /}/Qyeܲi Ö0f $qSZcjpa5){&nrB p@#H䶆5ɳ-ijã/6?>֌\XGi0(5m~+2beuC7PK!H -#controlgraph-0.4.0.dist-info/RECORD}=s0($`p(H(J(D~}p׉{+xiT,{Ph n|tv+~jX>P Vܷ I?GD$Jb\Ȋ;{KZ,+x-򎏗M Q#Ԭ"{M%"0 4Kdр$)ΰ FTޛ*MJI4X#mf_&2Zt:H?= >)ReԆvİ 4C;hع3b.vTjfaUݼ5JgI Vi#K3PK[}M4ocontrolgraph.pyPK!H\;!(2-controlgraph-0.4.0.dist-info/entry_points.txtPKMEz44$controlgraph-0.4.0.dist-info/LICENSEPK!HSmPO"controlgraph-0.4.0.dist-info/WHEELPK!H3%controlgraph-0.4.0.dist-info/METADATAPK!H -#controlgraph-0.4.0.dist-info/RECORDPK