forked from AcademySoftwareFoundation/rez
-
Notifications
You must be signed in to change notification settings - Fork 0
/
_rez_query_package_yaml
executable file
·145 lines (122 loc) · 3.7 KB
/
_rez_query_package_yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#!!REZ_PYTHON_BINARY!
#
# An internal utility script for querying package.yaml files
#
import sys
import yaml
import getopt
from rez_metafile import *
try:
opts, pkgstrs = getopt.getopt(sys.argv[1:], '', \
["filepath=", "print-version", "print-name", "print-requires", "print-build-requires", \
"print-desc", "print-help", "print-tools", "print-variant=", "quiet", "no-catch"])
except getopt.GetoptError, e:
sys.stderr.write(str(e)+'\n')
sys.exit(1)
filepath="./package.yaml"
variant_num = None
print_version = ("--print-version", "") in opts
print_name = ("--print-name", "") in opts
print_desc = ("--print-desc", "") in opts
print_requires = ("--print-requires", "") in opts
print_build_requires = ("--print-build-requires", "") in opts
print_help = ("--print-help", "") in opts
print_tools = ("--print-tools", "") in opts
quiet = ("--quiet", "") in opts
no_catch = ("--no-catch", "") in opts
for o, a in opts:
if (o == "--print-variant"):
try:
variant_num = int(a)
if (variant_num < 0):
raise ValueError
except ValueError:
if not quiet:
sys.stderr.write("illegal variant number '" + a + "'\n")
sys.exit(1)
elif (o == "--filepath"):
filepath=a
# load yaml
if no_catch:
metadata = ConfigMetadata(filepath)
else:
try:
metadata = ConfigMetadata(filepath)
except Exception as e:
if not quiet:
sys.stderr.write("Malformed package.yaml: '" + filepath + "'.\n")
print >> sys.stderr, str(e)
sys.exit(1)
if print_version:
if metadata.version:
print str(metadata.version)
else:
if not quiet:
sys.stderr.write("No 'version' in " + filepath + ".\n")
sys.exit(1)
if print_desc:
if metadata.description:
print str(metadata.description)
if print_name:
if metadata.name:
bad_chars = [ '-', '.' ]
for ch in bad_chars:
if (metadata.name.find(ch) != -1):
sys.stderr.write("Package name '" + metadata.name + "' contains illegal character '" + ch + "'.\n")
sys.exit(1)
print str(metadata.name)
else:
if not quiet:
sys.stderr.write("No 'name' in " + filepath + ".\n")
sys.exit(1)
if print_build_requires:
build_requires = metadata.get_build_requires()
if build_requires:
strs = str(' ').join(build_requires)
print strs
if print_requires:
requires = metadata.get_requires()
if requires:
strs = str(' ').join(requires)
print strs
if print_help:
if metadata.help:
print str(metadata.help)
else:
if not quiet:
sys.stderr.write("No 'help' entry specified in " + filepath + ".\n")
sys.exit(1)
if print_tools:
tools = metadata.metadict.get("tools")
if tools:
print str(' ').join(tools)
if (variant_num != None):
variants = metadata.get_variants()
if variants:
if (variant_num >= len(variants)):
if not quiet:
sys.stderr.write("Variant #" + str(variant_num) + " does not exist in package.\n")
sys.exit(1)
else:
strs = str(' ').join(variants[variant_num])
print strs
else:
if not quiet:
sys.stderr.write("Variant #" + str(variant_num) + " does not exist in package.\n")
sys.exit(1)
# Copyright 2008-2012 Dr D Studios Pty Limited (ACN 127 184 954) (Dr. D Studios)
#
# This file is part of Rez.
#
# Rez is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Rez is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with Rez. If not, see <http://www.gnu.org/licenses/>.