main.py 文件源码

python
阅读 31 收藏 0 点赞 0 评论 0

项目:thunderbolt100k 作者: cuyu 项目源码 文件源码
def main():
    parser = argparse.ArgumentParser(formatter_class=argparse.RawDescriptionHelpFormatter,
                                     description='A cmdline tool to enhance PL9K theme for ZSH\n')
    subparsers = parser.add_subparsers(help='Use {subcommand} -h for each subcommand\'s optional arguments details',
                                       dest='command')
    subparsers.add_parser('init', help='Init the settings in `~/.zshrc` file')
    subparsers.add_parser('polling', help='Start the polling daemon process')
    display_parser = subparsers.add_parser('display', help='Print the corresponding info on the terminal')
    display_parser.add_argument('widget', help='The widget to display, e.g. weather')

    args = parser.parse_args()
    if args.command == 'polling':
        with daemon.DaemonContext(pidfile=daemon.pidfile.PIDLockFile(constants.PID_PATH)):
            polling()
    elif args.command == 'display':
        widgets = sys.modules['thunderbolt100k.widgets']
        assert hasattr(widgets, args.widget), 'There is no widget called {0}'.format(args.widget)
        assert hasattr(getattr(widgets, args.widget),
                       'display'), 'The widget {0} must contains a `display` method'.format(args.widget)
        result = getattr(widgets, args.widget).display()
        if result:
            print(result)
    elif args.command == 'init':
        init_zshrc()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号