| Giorgi Lekveishvili | 285ab62 | 2023-11-22 13:50:45 +0400 | [diff] [blame] | 1 | #!/usr/bin/python3 |
| 2 | |
| 3 | # Copyright (C) 2019 The Android Open Source Project |
| 4 | # |
| 5 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | # you may not use this file except in compliance with the License. |
| 7 | # You may obtain a copy of the License at |
| 8 | # |
| 9 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | # |
| 11 | # Unless required by applicable law or agreed to in writing, software |
| 12 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | # See the License for the specific language governing permissions and |
| 15 | # limitations under the License. |
| 16 | |
| 17 | |
| 18 | import argparse |
| 19 | |
| 20 | from initializer.tasks import download_plugins, init, reindex, validate_notedb |
| 21 | from initializer.config.init_config import InitConfig |
| 22 | |
| 23 | |
| 24 | def _run_download_plugins(args): |
| 25 | config = InitConfig().parse(args.config) |
| 26 | download_plugins.get_installer(args.site, config).execute() |
| 27 | |
| 28 | |
| 29 | def _run_init(args): |
| 30 | config = InitConfig().parse(args.config) |
| 31 | init.GerritInit(args.site, config).execute() |
| 32 | |
| 33 | |
| 34 | def _run_reindex(args): |
| 35 | config = InitConfig().parse(args.config) |
| 36 | reindex.get_reindexer(args.site, config).start(args.force) |
| 37 | |
| 38 | |
| 39 | def _run_validate_notedb(args): |
| 40 | validate_notedb.NoteDbValidator(args.site).wait_until_valid() |
| 41 | |
| 42 | |
| 43 | def main(): |
| 44 | parser = argparse.ArgumentParser() |
| 45 | parser.add_argument( |
| 46 | "-s", |
| 47 | "--site", |
| 48 | help="Path to Gerrit site", |
| 49 | dest="site", |
| 50 | action="store", |
| 51 | default="/var/gerrit", |
| 52 | required=True, |
| 53 | ) |
| 54 | parser.add_argument( |
| 55 | "-c", |
| 56 | "--config", |
| 57 | help="Path to configuration file for init process.", |
| 58 | dest="config", |
| 59 | action="store", |
| 60 | required=True, |
| 61 | ) |
| 62 | |
| 63 | subparsers = parser.add_subparsers() |
| 64 | |
| 65 | parser_download_plugins = subparsers.add_parser( |
| 66 | "download-plugins", help="Download plugins" |
| 67 | ) |
| 68 | parser_download_plugins.set_defaults(func=_run_download_plugins) |
| 69 | |
| 70 | parser_init = subparsers.add_parser("init", help="Initialize Gerrit site") |
| 71 | parser_init.set_defaults(func=_run_init) |
| 72 | |
| 73 | parser_reindex = subparsers.add_parser("reindex", help="Reindex Gerrit indexes") |
| 74 | parser_reindex.add_argument( |
| 75 | "-f", |
| 76 | "--force", |
| 77 | help="Reindex even if indices are ready.", |
| 78 | dest="force", |
| 79 | action="store_true", |
| 80 | ) |
| 81 | parser_reindex.set_defaults(func=_run_reindex) |
| 82 | |
| 83 | parser_validate_notedb = subparsers.add_parser( |
| 84 | "validate-notedb", help="Validate NoteDB" |
| 85 | ) |
| 86 | parser_validate_notedb.set_defaults(func=_run_validate_notedb) |
| 87 | |
| 88 | args = parser.parse_args() |
| 89 | args.func(args) |
| 90 | |
| 91 | |
| 92 | if __name__ == "__main__": |
| 93 | main() |