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 | #  Messkit -- Generic-ish Data Utility App | ||||||
| #  Copyright © 2022-2023 Lance Edgar | #  Copyright © 2022-2024 Lance Edgar | ||||||
| # | # | ||||||
| #  This file is part of Messkit. | #  This file is part of Messkit. | ||||||
| # | # | ||||||
|  | @ -24,95 +24,34 @@ | ||||||
| Messkit commands | Messkit commands | ||||||
| """ | """ | ||||||
| 
 | 
 | ||||||
| import os | import typer | ||||||
| import sys |  | ||||||
| import subprocess |  | ||||||
| 
 | 
 | ||||||
| from rattail import commands | from rattail.commands.typer import typer_callback | ||||||
| 
 |  | ||||||
| from messkit import __version__ |  | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| def main(*args): | messkit_typer = typer.Typer( | ||||||
|     """ |     callback=typer_callback, | ||||||
|     Main entry point for Messkit command system |     help="Messkit (Generic Data App)" | ||||||
|     """ | ) | ||||||
|     args = list(args or sys.argv[1:]) |  | ||||||
|     cmd = Command() |  | ||||||
|     cmd.run(*args) |  | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| class Command(commands.Command): | @messkit_typer.command() | ||||||
|     """ | def install( | ||||||
|     Main command for Messkit |         ctx: typer.Context, | ||||||
|     """ | ): | ||||||
|     name = 'messkit' |  | ||||||
|     version = __version__ |  | ||||||
|     description = "Messkit (Generic Data App)" |  | ||||||
|     long_description = '' |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| class Install(commands.InstallSubcommand): |  | ||||||
|     """ |     """ | ||||||
|     Install the Messkit app |     Install the Messkit app | ||||||
|     """ |     """ | ||||||
|     name = 'install' |     from messkit.install import MesskitInstallHandler | ||||||
|     description = __doc__.strip() |  | ||||||
| 
 | 
 | ||||||
|     # nb. these must be explicitly set b/c config is not available |     config = ctx.parent.rattail_config | ||||||
|     # when running normally, e.g. `messkit -n install` |     handler = MesskitInstallHandler( | ||||||
|     app_title = "Messkit" |         config, | ||||||
|     app_package = 'messkit' |         app_title="Messkit", | ||||||
|     app_eggname = 'Messkit' |         app_package='messkit', | ||||||
|     app_pypiname = 'Messkit' |         app_eggname='Messkit', | ||||||
| 
 |         app_pypiname='Messkit', | ||||||
|     def do_install_steps(self): |         main_image_url='/messkit/img/messkit.png', | ||||||
| 
 |         header_image_url='/messkit/img/messkit-small.png', | ||||||
|         # first all normal steps |         favicon_url='/messkit/img/messkit-small.png') | ||||||
|         super(Install, self).do_install_steps() |     handler.run() | ||||||
| 
 |  | ||||||
|         # 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 |  | ||||||
|  |  | ||||||
							
								
								
									
										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 |         rich | ||||||
|         Sphinx |         Sphinx | ||||||
|         Tailbone |         Tailbone | ||||||
|  |         typer | ||||||
| 
 | 
 | ||||||
| packages = find: | packages = find: | ||||||
| include_package_data = True | include_package_data = True | ||||||
|  | @ -39,14 +40,11 @@ include_package_data = True | ||||||
| 
 | 
 | ||||||
| [options.entry_points] | [options.entry_points] | ||||||
| 
 | 
 | ||||||
| rattail.config.extensions = |  | ||||||
|         messkit = messkit.config:MesskitConfig |  | ||||||
| 
 |  | ||||||
| console_scripts = | console_scripts = | ||||||
|         messkit = messkit.commands:main |         messkit = messkit.commands:messkit_typer | ||||||
| 
 |  | ||||||
| messkit.subcommands = |  | ||||||
|         install = messkit.commands:Install |  | ||||||
| 
 | 
 | ||||||
| paste.app_factory = | paste.app_factory = | ||||||
|         main = messkit.web.app:main |         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