blob: c7d347d59fdd41f1c8b709ee14bfd462a706f3ac [file]
#!/usr/bin/env python3
# Copyright (C) 2026 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import argparse
import logging
import os
import sys
import plugin
import pod
import restart
import shell_cmd_statusbar
DEFAULT_PATH = "" # Just work from the ANDROID_BUILD_TOP
class StdLoggingHandler(logging.Handler):
def __init__(self):
super().__init__()
def emit(self, record):
if record.levelno < logging.WARNING:
print(record.getMessage())
else:
print(record.getMessage(), file=sys.stderr)
if __name__ == "__main__":
parser = argparse.ArgumentParser(
description="""Commands for working with SystemUI
This includes commands for working with Pods, Plugins, as well as the ability to restart SystemUI.
""",
)
parser.add_argument(
"--log-level",
choices=["INFO", "WARN", "ERROR"],
default="INFO",
help="Amount of output to spew. Defaults to INFO."
)
parser.add_argument(
"-p", "--path",
action="append",
help=f"""Directory in which to work. Can be specified multiple times.
Defaults to `{DEFAULT_PATH}`.
"""
)
subparsers = parser.add_subparsers(help="Commands")
pod.initialize_cmd(subparsers)
plugin.initialize_cmd(subparsers)
restart.initialize_cmd(subparsers)
shell_cmd_statusbar.initialize_cmd(subparsers)
args = parser.parse_args()
if not 'func' in vars(args):
parser.print_help()
sys.exit()
if args.path is None:
args.path = [DEFAULT_PATH]
if args.log_level == "WARN":
log_level = logging.WARN
elif args.log_level == "ERROR":
log_level = logging.ERROR
else:
log_level = logging.INFO
logging.basicConfig(level=log_level, format="%(message)s", handlers=[StdLoggingHandler()])
# make paths absolute relative to cwd
args.path = [os.path.abspath(p) for p in args.path]
args.func(args, logger=logging.getLogger(__name__))