Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(742)

Side by Side Diff: services/catalog/public/tools/generate_manifest.py

Issue 2573283002: Use a static catalog manifest for the standalone Mash runner (Closed)
Patch Set: . Created 3 years, 12 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « services/catalog/public/tools/catalog.gni ('k') | services/catalog/reader.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 #!/usr/bin/env python
2 # Copyright 2016 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
5
6 """Generates a static catalog manifest to be loaded at runtime. This includes
7 embedded service manifests for every supported service, as well as information
8 indicating how to start each service."""
9
10 import argparse
11 import json
12 import os.path
13 import sys
14
15 eater_relative = "../../../../../tools/json_comment_eater"
16 eater_relative = os.path.join(os.path.abspath(__file__), eater_relative)
17 sys.path.insert(0, os.path.normpath(eater_relative))
18 try:
19 import json_comment_eater
20 finally:
21 sys.path.pop(0)
22
23
24 def ParseJSONFile(filename):
25 with open(filename) as json_file:
26 try:
27 return json.loads(json_comment_eater.Nom(json_file.read()))
28 except ValueError as e:
29 print "%s is not a valid JSON document" % filename
30 raise e
31
32
33 def ParseManifest(filename):
34 manifest = ParseJSONFile(filename)
35 if "name" not in manifest:
36 raise Exception("Manifest %s missing \"name\" key." % filename)
37 return manifest["name"], manifest
38
39
40 def AddServiceEntryToCatalog(services, name, entry):
41 if name in services:
42 raise Exception("Duplicate service entry for %s" % name)
43 services[name] = entry
44
45
46 def main():
47 parser = argparse.ArgumentParser(
48 description="Generates a Service Manager catalog manifest.")
49 parser.add_argument("--output")
50 parser.add_argument("--packages-dir")
51 parser.add_argument("--pretty", action="store_true")
52 parser.add_argument("--embedded-services", nargs="+",
53 dest="embedded_services", default=[])
54 parser.add_argument("--standalone-services", nargs="+",
55 dest="standalone_services", default=[])
56 parser.add_argument("--include-catalogs", nargs="+", dest="included_catalogs",
57 default=[])
58 parser.add_argument("--override-service-executables", nargs="+",
59 dest="executable_override_specs", default=[])
60 args, _ = parser.parse_known_args()
61
62 if args.output is None or args.packages_dir is None:
63 raise Exception("--output and --packages-dir required")
64
65 services = {}
66 for subcatalog_path in args.included_catalogs:
67 subcatalog = ParseJSONFile(subcatalog_path)
68 for name, entry in subcatalog["services"].iteritems():
69 AddServiceEntryToCatalog(services, name, entry)
70
71 executable_overrides = {}
72 for override_spec in args.executable_override_specs:
73 service_name, exe_path = override_spec.split(":", 1)
74 executable_overrides[service_name] = exe_path
75
76 for name in args.embedded_services:
77 manifest_path = os.path.join(args.packages_dir, name, "manifest.json")
78 service_name, manifest = ParseManifest(manifest_path)
79 entry = { "embedded": True, "manifest": manifest }
80 AddServiceEntryToCatalog(services, service_name, entry)
81
82 for name in args.standalone_services:
83 manifest_path = os.path.join(args.packages_dir, name, "manifest.json")
84 service_name, manifest = ParseManifest(manifest_path)
85 entry = { "embedded": False, "manifest": ParseJSONFile(manifest_path) }
86 if name in executable_overrides:
87 entry["executable"] = executable_overrides[name]
88 AddServiceEntryToCatalog(services, service_name, entry)
89
90 catalog = { "services": services }
91 with open(args.output, 'w') as output_file:
92 json.dump(catalog, output_file, indent=2 if args.pretty else -1)
93
94 return 0
95
96 if __name__ == "__main__":
97 sys.exit(main())
OLDNEW
« no previous file with comments | « services/catalog/public/tools/catalog.gni ('k') | services/catalog/reader.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698