Migrate commands to use 'typer' framework
This commit is contained in:
		
							parent
							
								
									b44d133d3a
								
							
						
					
					
						commit
						783e5770f1
					
				
					 3 changed files with 80 additions and 91 deletions
				
			
		|  | @ -2,7 +2,7 @@ | |||
| ###################################################################### | ||||
| # | ||||
| #  Messkit -- Generic-ish Data Utility App | ||||
| #  Copyright © 2022-2023 Lance Edgar | ||||
| #  Copyright © 2022-2024 Lance Edgar | ||||
| # | ||||
| #  This file is part of Messkit. | ||||
| # | ||||
|  | @ -24,95 +24,34 @@ | |||
| Messkit commands | ||||
| """ | ||||
| 
 | ||||
| import os | ||||
| import sys | ||||
| import subprocess | ||||
| import typer | ||||
| 
 | ||||
| from rattail import commands | ||||
| 
 | ||||
| from messkit import __version__ | ||||
| from rattail.commands.typer import typer_callback | ||||
| 
 | ||||
| 
 | ||||
| def main(*args): | ||||
|     """ | ||||
|     Main entry point for Messkit command system | ||||
|     """ | ||||
|     args = list(args or sys.argv[1:]) | ||||
|     cmd = Command() | ||||
|     cmd.run(*args) | ||||
| messkit_typer = typer.Typer( | ||||
|     callback=typer_callback, | ||||
|     help="Messkit (Generic Data App)" | ||||
| ) | ||||
| 
 | ||||
| 
 | ||||
| class Command(commands.Command): | ||||
|     """ | ||||
|     Main command for Messkit | ||||
|     """ | ||||
|     name = 'messkit' | ||||
|     version = __version__ | ||||
|     description = "Messkit (Generic Data App)" | ||||
|     long_description = '' | ||||
| 
 | ||||
| 
 | ||||
| class Install(commands.InstallSubcommand): | ||||
| @messkit_typer.command() | ||||
| def install( | ||||
|         ctx: typer.Context, | ||||
| ): | ||||
|     """ | ||||
|     Install the Messkit app | ||||
|     """ | ||||
|     name = 'install' | ||||
|     description = __doc__.strip() | ||||
|     from messkit.install import MesskitInstallHandler | ||||
| 
 | ||||
|     # nb. these must be explicitly set b/c config is not available | ||||
|     # when running normally, e.g. `messkit -n install` | ||||
|     app_title = "Messkit" | ||||
|     app_package = 'messkit' | ||||
|     app_eggname = 'Messkit' | ||||
|     app_pypiname = 'Messkit' | ||||
| 
 | ||||
|     def do_install_steps(self): | ||||
| 
 | ||||
|         # first all normal steps | ||||
|         super(Install, self).do_install_steps() | ||||
| 
 | ||||
|         # we also install poser..for now..? | ||||
|         self.install_poser() | ||||
| 
 | ||||
|     def put_settings(self, **kwargs): | ||||
| 
 | ||||
|         rattail = [os.path.join(sys.prefix, 'bin', 'rattail'), | ||||
|                    '-c', os.path.join(sys.prefix, 'app', 'silent.conf')] | ||||
| 
 | ||||
|         # set falafel theme | ||||
|         cmd = rattail + ['setting-put', 'tailbone.theme', 'falafel'] | ||||
|         subprocess.check_call(cmd) | ||||
| 
 | ||||
|         # hide theme picker | ||||
|         cmd = rattail + ['setting-put', 'tailbone.themes.expose_picker', 'false'] | ||||
|         subprocess.check_call(cmd) | ||||
| 
 | ||||
|         # set main image | ||||
|         cmd = rattail + ['setting-put', 'tailbone.main_image_url', '/messkit/img/messkit.png'] | ||||
|         subprocess.check_call(cmd) | ||||
| 
 | ||||
|         # set header image | ||||
|         cmd = rattail + ['setting-put', 'tailbone.header_image_url', '/messkit/img/messkit-small.png'] | ||||
|         subprocess.check_call(cmd) | ||||
| 
 | ||||
|         # set favicon image | ||||
|         cmd = rattail + ['setting-put', 'tailbone.favicon_url', '/messkit/img/messkit-small.png'] | ||||
|         subprocess.check_call(cmd) | ||||
| 
 | ||||
|         # set default grid page size | ||||
|         cmd = rattail + ['setting-put', 'tailbone.grid.default_pagesize', '20'] | ||||
|         subprocess.check_call(cmd) | ||||
| 
 | ||||
|     def install_poser(self): | ||||
|         if not self.basic_prompt("make poser dir?", True, is_bool=True): | ||||
|             return False | ||||
| 
 | ||||
|         self.rprint() | ||||
| 
 | ||||
|         # make poser dir | ||||
|         poser_handler = self.app.get_poser_handler() | ||||
|         poserdir = poser_handler.make_poser_dir() | ||||
| 
 | ||||
|         self.rprint("\n\tposer dir created:  [bold green]{}[/bold green]".format( | ||||
|             poserdir)) | ||||
|         return True | ||||
|     config = ctx.parent.rattail_config | ||||
|     handler = MesskitInstallHandler( | ||||
|         config, | ||||
|         app_title="Messkit", | ||||
|         app_package='messkit', | ||||
|         app_eggname='Messkit', | ||||
|         app_pypiname='Messkit', | ||||
|         main_image_url='/messkit/img/messkit.png', | ||||
|         header_image_url='/messkit/img/messkit-small.png', | ||||
|         favicon_url='/messkit/img/messkit-small.png') | ||||
|     handler.run() | ||||
|  |  | |||
							
								
								
									
										52
									
								
								messkit/install.py
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										52
									
								
								messkit/install.py
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,52 @@ | |||
| # -*- coding: utf-8; -*- | ||||
| ###################################################################### | ||||
| # | ||||
| #  Messkit -- Generic-ish Data Utility App | ||||
| #  Copyright © 2022-2024 Lance Edgar | ||||
| # | ||||
| #  This file is part of Messkit. | ||||
| # | ||||
| #  Messkit is free software: you can redistribute it and/or modify it | ||||
| #  under the terms of the GNU General Public License as published by | ||||
| #  the Free Software Foundation, either version 3 of the License, or | ||||
| #  (at your option) any later version. | ||||
| # | ||||
| #  Messkit is distributed in the hope that it will be useful, but | ||||
| #  WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
| #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU | ||||
| #  General Public License for more details. | ||||
| # | ||||
| #  You should have received a copy of the GNU General Public License | ||||
| #  along with Messkit.  If not, see <http://www.gnu.org/licenses/>. | ||||
| # | ||||
| ###################################################################### | ||||
| """ | ||||
| Messkit install handler | ||||
| """ | ||||
| 
 | ||||
| from rattail import install as base | ||||
| from rattail.commands.util import rprint, basic_prompt | ||||
| 
 | ||||
| 
 | ||||
| class MesskitInstallHandler(base.InstallHandler): | ||||
|     """ | ||||
|     Custom install handler for Messkit | ||||
|     """ | ||||
| 
 | ||||
|     def do_install_steps(self): | ||||
|         super().do_install_steps() | ||||
|         self.install_poser() | ||||
| 
 | ||||
|     def install_poser(self): | ||||
|         if not basic_prompt("make poser dir?", True, is_bool=True): | ||||
|             return False | ||||
| 
 | ||||
|         rprint() | ||||
| 
 | ||||
|         # make poser dir | ||||
|         poser_handler = self.app.get_poser_handler() | ||||
|         poserdir = poser_handler.make_poser_dir() | ||||
| 
 | ||||
|         rprint("\n\tposer dir created:  [bold green]{}[/bold green]".format( | ||||
|             poserdir)) | ||||
|         return True | ||||
							
								
								
									
										12
									
								
								setup.cfg
									
										
									
									
									
								
							
							
						
						
									
										12
									
								
								setup.cfg
									
										
									
									
									
								
							|  | @ -32,6 +32,7 @@ install_requires = | |||
|         rich | ||||
|         Sphinx | ||||
|         Tailbone | ||||
|         typer | ||||
| 
 | ||||
| packages = find: | ||||
| include_package_data = True | ||||
|  | @ -39,14 +40,11 @@ include_package_data = True | |||
| 
 | ||||
| [options.entry_points] | ||||
| 
 | ||||
| rattail.config.extensions = | ||||
|         messkit = messkit.config:MesskitConfig | ||||
| 
 | ||||
| console_scripts = | ||||
|         messkit = messkit.commands:main | ||||
| 
 | ||||
| messkit.subcommands = | ||||
|         install = messkit.commands:Install | ||||
|         messkit = messkit.commands:messkit_typer | ||||
| 
 | ||||
| paste.app_factory = | ||||
|         main = messkit.web.app:main | ||||
| 
 | ||||
| rattail.config.extensions = | ||||
|         messkit = messkit.config:MesskitConfig | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Lance Edgar
						Lance Edgar