scan metadata for targets
Signed-off-by: Igor Gnatenko <ignatenkobrain@fedoraproject.org>
This commit is contained in:
parent
0038452903
commit
7551fcba64
2 changed files with 19 additions and 0 deletions
|
@ -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:
|
||||
|
|
|
@ -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 "<Target {self.kind}|{self.name}>".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[:]
|
||||
|
|
Loading…
Reference in a new issue