82 # |
82 # |
83 # This should probably use the pkg APIs at some point, but this appears to be |
83 # This should probably use the pkg APIs at some point, but this appears to be |
84 # a stable and less complicated interface to gathering information from the |
84 # a stable and less complicated interface to gathering information from the |
85 # manifests in the package repo. |
85 # manifests in the package repo. |
86 # |
86 # |
87 def get_incorporations(repository, publisher, inc_version='5.12'): |
87 def get_incorporations(repository, publisher, inc_version='5.12', |
88 tmp = subprocess.Popen(["/usr/bin/pkgrepo", "list", "-F", "json", |
88 static_file=None): |
89 "-s", repository, |
89 packages = {} |
90 "-p", publisher], |
|
91 stdout=subprocess.PIPE) |
|
92 incorporations = {} |
90 incorporations = {} |
93 packages = json.load(tmp.stdout) |
91 versions = {} |
94 |
92 |
|
93 # |
|
94 # if a static file was provided, prime the cache with the contents of |
|
95 # that file. |
|
96 # |
|
97 if static_file: |
|
98 with open(static_file, 'r') as fp: |
|
99 for line in fp: |
|
100 line = line.partition('#')[0] |
|
101 line = line.rstrip() |
|
102 |
|
103 try: |
|
104 (incorporation, package, version) = re.split(':|@', line) |
|
105 except ValueError: |
|
106 pass |
|
107 else: |
|
108 if incorporation not in incorporations: |
|
109 incorporations[incorporation] = Incorporation(incorporation, inc_version) |
|
110 # find the incorporation and add the package |
|
111 tmp = incorporations[incorporation] |
|
112 tmp.add_package(package, version) |
|
113 versions[package] = version |
|
114 |
|
115 # |
|
116 # Load the repository for packages to incorporate. |
|
117 # |
|
118 if repository: |
|
119 tmp = subprocess.Popen(["/usr/bin/pkgrepo", "list", "-F", "json", |
|
120 "-s", repository, |
|
121 "-p", publisher], |
|
122 stdout=subprocess.PIPE) |
|
123 packages = json.load(tmp.stdout) |
|
124 |
|
125 # |
95 # Check for multiple versions of packages in the repo, but keep track of |
126 # Check for multiple versions of packages in the repo, but keep track of |
96 # the latest one. |
127 # the latest one. |
97 versions = {} |
128 # |
98 for package in packages: |
129 for package in packages: |
99 pkg_name = package['name'] |
130 pkg_name = package['name'] |
100 pkg_version = package['version'] |
131 pkg_version = package['version'] |
101 |
132 |
102 if pkg_name in versions: |
133 if pkg_name in versions: |
103 warning("%s is in the repo at multiple versions (%s, %s)" % (pkg_name, pkg_version, versions[pkg_name])) |
134 warning("%s is in the repo at multiple versions (%s, %s)" % (pkg_name, pkg_version, versions[pkg_name])) |
104 pkg_version = max(pkg_version, versions[pkg_name]) |
135 pkg_version = max(pkg_version, versions[pkg_name]) |
105 versions[pkg_name] = pkg_version |
136 versions[pkg_name] = pkg_version |
106 |
137 |
|
138 # |
|
139 # Add published packages to the incorporation lists |
|
140 # |
107 for package in packages: |
141 for package in packages: |
108 pkg_name = package['name'] |
142 pkg_name = package['name'] |
109 pkg_version = package['version'] |
143 pkg_version = package['version'] |
110 |
144 |
111 # skip older packages and those that don't want to be incorporated |
145 # skip older packages and those that don't want to be incorporated |
120 if inc_name not in incorporations: |
154 if inc_name not in incorporations: |
121 incorporations[inc_name] = Incorporation(inc_name, inc_version) |
155 incorporations[inc_name] = Incorporation(inc_name, inc_version) |
122 # find the incorporation and add the package |
156 # find the incorporation and add the package |
123 tmp = incorporations[inc_name] |
157 tmp = incorporations[inc_name] |
124 tmp.add_package(pkg_name, pkg_version) |
158 tmp.add_package(pkg_name, pkg_version) |
|
159 |
125 return incorporations |
160 return incorporations |
126 |
161 |
127 def main_func(): |
162 def main_func(): |
128 global Werror |
163 global Werror |
129 |
164 |
130 try: |
165 try: |
131 opts, pargs = getopt.getopt(sys.argv[1:], "c:s:p:v:d:w", |
166 opts, pargs = getopt.getopt(sys.argv[1:], "S:c:s:p:v:d:w", |
132 ["repository=", "publisher=", "version=", |
167 ["repository=", "publisher=", "version=", |
133 "consolidation=", "destdir=", "Werror"]) |
168 "consolidation=", "destdir=", "Werror", |
|
169 "static-content-file="]) |
134 except getopt.GetoptError, e: |
170 except getopt.GetoptError, e: |
135 usage(_("illegal option: %s") % e.opt) |
171 usage(_("illegal option: %s") % e.opt) |
136 |
172 |
|
173 static_file = None |
137 repository = None |
174 repository = None |
138 publisher = None |
175 publisher = None |
139 version = None |
176 version = None |
140 destdir = None |
177 destdir = None |
141 consolidation = None |
178 consolidation = None |
142 |
179 |
143 for opt, arg in opts: |
180 for opt, arg in opts: |
144 if opt in ("-s", "--repository"): |
181 if opt in ("-S", "--static-content-file"): |
|
182 static_file = arg |
|
183 elif opt in ("-s", "--repository"): |
145 repository = arg |
184 repository = arg |
146 elif opt in ("-p", "--publisher"): |
185 elif opt in ("-p", "--publisher"): |
147 publisher = arg |
186 publisher = arg |
148 elif opt in ("-v", "--version"): |
187 elif opt in ("-v", "--version"): |
149 version = arg |
188 version = arg |
152 elif opt in ("-c", "--consolidation"): |
191 elif opt in ("-c", "--consolidation"): |
153 consolidation = arg |
192 consolidation = arg |
154 elif opt in ("-w", "--Werror"): |
193 elif opt in ("-w", "--Werror"): |
155 Werror = True |
194 Werror = True |
156 |
195 |
157 incorporations = get_incorporations(repository, publisher, version) |
196 incorporations = get_incorporations(repository, publisher, version, |
|
197 static_file) |
158 |
198 |
159 for incorporation_name in incorporations.keys(): |
199 for incorporation_name in incorporations.keys(): |
160 filename = '' |
200 filename = '' |
161 if destdir != None: |
201 if destdir != None: |
162 filename = destdir + '/' |
202 filename = destdir + '/' |