From 7551fcba64e27c9cec4fb6475b25cb382953fc7b Mon Sep 17 00:00:00 2001 From: Igor Gnatenko Date: Fri, 10 Feb 2017 19:52:07 +0100 Subject: [PATCH] scan metadata for targets Signed-off-by: Igor Gnatenko --- cargodeps.py | 3 +++ rust2rpm/metadata.py | 16 ++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/cargodeps.py b/cargodeps.py index b623c75..308b528 100644 --- a/cargodeps.py +++ b/cargodeps.py @@ -6,6 +6,7 @@ from rust2rpm import Metadata def main(): parser = argparse.ArgumentParser() group = parser.add_mutually_exclusive_group(required=True) + group.add_argument("-t", "--target-kinds", action="store_true", help="Print target kinds") group.add_argument("-P", "--provides", action="store_true", help="Print Provides") group.add_argument("-R", "--requires", action="store_true", help="Print Requires") group.add_argument("-C", "--conflicts", action="store_true", help="Print Conflicts") @@ -25,6 +26,8 @@ def main(): for f in files: f = f.rstrip() md = Metadata.from_file(f) + if args.target_kinds: + print("\n".join(set(tgt.kind for tgt in md.targets))) if args.provides: print_deps(md.provides) if args.requires: diff --git a/rust2rpm/metadata.py b/rust2rpm/metadata.py index 1254f54..29cfc01 100644 --- a/rust2rpm/metadata.py +++ b/rust2rpm/metadata.py @@ -11,6 +11,14 @@ REQ_TO_CON = {">": "<=", ">=": "<", "<=": ">"} +class Target(object): + def __init__(self, kind, name): + self.kind = kind + self.name = name + + def __repr__(self): + return "".format(self=self) + class Dependency(object): def __init__(self, name, spec, feature=None, inverted=False): self.name = name @@ -32,6 +40,7 @@ class Metadata(object): self.license = None self.license_file = None self._version = None + self._targets = [] self._provides = [] self._requires = [] self._conflicts = [] @@ -50,6 +59,9 @@ class Metadata(object): self.license_file = md["license_file"] self._version = semver.SpecItem("={}".format(md["version"])) + # Targets + self._targets = [Target(tgt["kind"][0], tgt["name"]) for tgt in md["targets"]] + # Provides self._provides = [Dependency(self.name, self._version)] for feature in md["features"]: @@ -131,6 +143,10 @@ class Metadata(object): def version(self): return str(self._version.spec) if self._version is not None else None + @property + def targets(self): + return self._targets[:] + @property def provides(self): return self._provides[:]