2024-05-18 22:35:10 +00:00
|
|
|
import argparse
|
|
|
|
|
2024-07-05 09:06:05 +00:00
|
|
|
from symconf import util
|
|
|
|
from symconf.config import ConfigManager
|
2024-05-18 22:35:10 +00:00
|
|
|
|
|
|
|
|
2024-07-12 10:01:13 +00:00
|
|
|
def add_install_subparser(subparsers):
|
|
|
|
def install_apps(args):
|
2024-07-05 09:06:05 +00:00
|
|
|
cm = ConfigManager(args.config_dir)
|
2024-07-12 10:01:13 +00:00
|
|
|
cm.install_apps(apps=args.apps)
|
|
|
|
|
|
|
|
parser = subparsers.add_parser(
|
|
|
|
'install',
|
|
|
|
description='Run install scripts for registered applications.'
|
|
|
|
)
|
|
|
|
parser.add_argument(
|
|
|
|
'-a', '--apps',
|
|
|
|
required = False,
|
|
|
|
default = "*",
|
|
|
|
type = lambda s: s.split(',') if s != '*' else s,
|
|
|
|
help = 'Application target for theme. App must be present in the registry. ' \
|
|
|
|
+ 'Use "*" to apply to all registered apps'
|
|
|
|
)
|
|
|
|
parser.set_defaults(func=install_apps)
|
|
|
|
|
|
|
|
def add_update_subparser(subparsers):
|
|
|
|
def update_apps(args):
|
|
|
|
cm = ConfigManager(args.config_dir)
|
|
|
|
cm.update_apps(apps=args.apps)
|
|
|
|
|
|
|
|
parser = subparsers.add_parser(
|
|
|
|
'update',
|
|
|
|
description='Run update scripts for registered applications.'
|
|
|
|
)
|
|
|
|
parser.add_argument(
|
|
|
|
'-a', '--apps',
|
|
|
|
required = False,
|
|
|
|
default = "*",
|
|
|
|
type = lambda s: s.split(',') if s != '*' else s,
|
|
|
|
help = 'Application target for theme. App must be present in the registry. ' \
|
|
|
|
+ 'Use "*" to apply to all registered apps'
|
|
|
|
)
|
|
|
|
parser.set_defaults(func=update_apps)
|
|
|
|
|
|
|
|
def add_config_subparser(subparsers):
|
2024-08-11 06:48:35 +00:00
|
|
|
def configure_apps(args):
|
2024-07-12 10:01:13 +00:00
|
|
|
cm = ConfigManager(args.config_dir)
|
2024-08-11 06:48:35 +00:00
|
|
|
cm.configure_apps(
|
2024-07-03 08:38:52 +00:00
|
|
|
apps=args.apps,
|
|
|
|
scheme=args.scheme,
|
2024-08-11 06:48:35 +00:00
|
|
|
style=args.palette,
|
2024-07-03 08:38:52 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
parser = subparsers.add_parser(
|
2024-07-12 10:01:13 +00:00
|
|
|
'config',
|
|
|
|
description='Set config files for registered applications.'
|
2024-07-03 08:38:52 +00:00
|
|
|
)
|
|
|
|
parser.add_argument(
|
|
|
|
'-p', '--palette',
|
|
|
|
required = False,
|
|
|
|
default = "any",
|
|
|
|
help = 'Palette name, must match a folder in themes/'
|
|
|
|
)
|
|
|
|
parser.add_argument(
|
|
|
|
'-s', '--scheme',
|
|
|
|
required = False,
|
|
|
|
default = "any",
|
|
|
|
help = 'Preferred lightness scheme, either "light" or "dark".'
|
|
|
|
)
|
|
|
|
parser.add_argument(
|
|
|
|
'-a', '--apps',
|
|
|
|
required = False,
|
2024-07-05 09:06:05 +00:00
|
|
|
default = "*",
|
|
|
|
type = lambda s: s.split(',') if s != '*' else s,
|
2024-07-03 08:38:52 +00:00
|
|
|
help = 'Application target for theme. App must be present in the registry. ' \
|
|
|
|
+ 'Use "*" to apply to all registered apps'
|
|
|
|
)
|
|
|
|
parser.add_argument(
|
2024-07-12 10:01:13 +00:00
|
|
|
'-T', '--template-vars',
|
|
|
|
required = False,
|
|
|
|
nargs='+',
|
|
|
|
action=util.KVPair,
|
|
|
|
help='Groups to use when populating templates, in the form group=value'
|
2024-07-03 08:38:52 +00:00
|
|
|
)
|
2024-08-11 06:48:35 +00:00
|
|
|
parser.set_defaults(func=configure_apps)
|
2024-07-03 08:38:52 +00:00
|
|
|
|
|
|
|
|
|
|
|
# central argparse entry point
|
2024-05-18 22:35:10 +00:00
|
|
|
parser = argparse.ArgumentParser(
|
2024-07-05 09:06:05 +00:00
|
|
|
'symconf',
|
2024-07-12 10:01:13 +00:00
|
|
|
description='Manage application configuration with symlinks.'
|
2024-05-18 22:35:10 +00:00
|
|
|
)
|
2024-07-03 08:38:52 +00:00
|
|
|
parser.add_argument(
|
|
|
|
'-c', '--config-dir',
|
|
|
|
default = util.xdg_config_path(),
|
|
|
|
type = util.absolute_path,
|
|
|
|
help = 'Path to config directory'
|
|
|
|
)
|
|
|
|
|
|
|
|
# add subparsers
|
2024-07-05 09:06:05 +00:00
|
|
|
subparsers = parser.add_subparsers(title='subcommand actions')
|
2024-07-12 10:01:13 +00:00
|
|
|
add_install_subparser(subparsers)
|
|
|
|
add_update_subparser(subparsers)
|
|
|
|
add_config_subparser(subparsers)
|
2024-05-18 22:35:10 +00:00
|
|
|
|
|
|
|
|
2024-07-09 19:18:16 +00:00
|
|
|
def main():
|
2024-07-03 08:38:52 +00:00
|
|
|
args = parser.parse_args()
|
|
|
|
|
2024-05-18 22:35:10 +00:00
|
|
|
if 'func' in args:
|
|
|
|
args.func(args)
|
|
|
|
else:
|
|
|
|
parser.print_help()
|
2024-07-09 19:18:16 +00:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|