Compare commits
	
		
			1 Commits
		
	
	
		
			867cd1c022
			...
			b139f4bb8c
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| b139f4bb8c | 
							
								
								
									
										1
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										1
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							| @ -159,7 +159,6 @@ cython_debug/ | ||||
| #  and can be added to the global gitignore or merged into this file.  For a more nuclear | ||||
| #  option (not recommended) you can uncomment the following to ignore the entire idea folder. | ||||
| .idea/ | ||||
| .vscode/ | ||||
| 
 | ||||
| # Project specific | ||||
| config.json | ||||
|  | ||||
| @ -1,12 +0,0 @@ | ||||
| import click | ||||
| 
 | ||||
| 
 | ||||
| @click.group(help='access command for lazy example') | ||||
| @click.option('--debug/--no-debug', default=False) | ||||
| def cli(debug): | ||||
|     click.echo(f"Debug mode is {'on' if debug else 'off'}") | ||||
| 
 | ||||
| 
 | ||||
| @cli.command() | ||||
| def enable(): | ||||
|     click.echo('Access granted') | ||||
| @ -1,13 +0,0 @@ | ||||
| import click | ||||
| 
 | ||||
| from core.cli.lazy_group import LazyGroup | ||||
| from settings.general import INSTALLED_APPS | ||||
| 
 | ||||
| 
 | ||||
| @click.group( | ||||
|     cls=LazyGroup, | ||||
|     lazy_subcommands=INSTALLED_APPS['dci6'], | ||||
|     help='dci6 command for lazy example', | ||||
| ) | ||||
| def cli(): | ||||
|     pass | ||||
| @ -1,12 +0,0 @@ | ||||
| import click | ||||
| 
 | ||||
| 
 | ||||
| @click.group(help='access command for lazy example') | ||||
| @click.option('--debug/--no-debug', default=False) | ||||
| def cli(debug): | ||||
|     click.echo(f"Debug mode is {'on' if debug else 'off'}") | ||||
| 
 | ||||
| 
 | ||||
| @cli.command() | ||||
| def enable(): | ||||
|     click.echo('Access granted') | ||||
| @ -1,12 +0,0 @@ | ||||
| import click | ||||
| from core.cli.lazy_group import LazyGroup | ||||
| from settings.general import INSTALLED_APPS | ||||
| 
 | ||||
| 
 | ||||
| @click.group( | ||||
|     cls=LazyGroup, | ||||
|     lazy_subcommands=INSTALLED_APPS['vm6'], | ||||
|     help='vm6 command for lazy example', | ||||
| ) | ||||
| def cli(): | ||||
|     pass | ||||
| @ -1,13 +0,0 @@ | ||||
| import click | ||||
| 
 | ||||
| 
 | ||||
| @click.group(help='nodes command for lazy example') | ||||
| def cli(): | ||||
|     pass | ||||
| 
 | ||||
| 
 | ||||
| @cli.command(name='list') | ||||
| def nodes_list(): | ||||
|     click.echo('NODES LIST: etc...') | ||||
|     for num in range(1, 10): | ||||
|         click.echo(num) | ||||
| @ -1,39 +0,0 @@ | ||||
| import importlib | ||||
| import click | ||||
| 
 | ||||
| 
 | ||||
| class LazyGroup(click.Group): | ||||
|     def __init__(self, *args, lazy_subcommands=None, **kwargs): | ||||
|         super().__init__(*args, **kwargs) | ||||
|         # lazy_subcommands is a map of the form: | ||||
|         # | ||||
|         #   {command-name} -> {module-name}.{command-object-name} | ||||
|         # | ||||
|         self.lazy_subcommands = lazy_subcommands or {} | ||||
| 
 | ||||
|     def list_commands(self, ctx): | ||||
|         base = super().list_commands(ctx) | ||||
|         lazy = sorted(self.lazy_subcommands.keys()) | ||||
|         return base + lazy | ||||
| 
 | ||||
|     def get_command(self, ctx, cmd_name): | ||||
|         if cmd_name in self.lazy_subcommands: | ||||
|             return self._lazy_load(cmd_name) | ||||
|         return super().get_command(ctx, cmd_name) | ||||
| 
 | ||||
|     def _lazy_load(self, cmd_name): | ||||
|         # lazily loading a command, | ||||
|         # first get the module name and attribute name | ||||
|         import_path = self.lazy_subcommands[cmd_name] | ||||
|         modname, cmd_object_name = import_path.rsplit(".", 1) | ||||
|         # do the import | ||||
|         mod = importlib.import_module(modname) | ||||
|         # get the Command object from that module | ||||
|         cmd_object = getattr(mod, cmd_object_name) | ||||
|         # check the result to make debugging easier | ||||
|         if not isinstance(cmd_object, click.BaseCommand): | ||||
|             raise ValueError( | ||||
|                 f"Lazy loading of {import_path} failed by returning " | ||||
|                 "a non-command object" | ||||
|             ) | ||||
|         return cmd_object | ||||
| @ -1,21 +1,9 @@ | ||||
| #!/usr/bin/env python3 | ||||
| # -*- coding: utf-8 -*- | ||||
| import click | ||||
| 
 | ||||
| from core.cli.lazy_group import LazyGroup | ||||
| from settings.environment import env | ||||
| 
 | ||||
| 
 | ||||
| @click.group( | ||||
|     cls=LazyGroup, | ||||
|     lazy_subcommands={ | ||||
|         'vm6': 'apps.vm6.commands.cli', | ||||
|         'dci6': 'apps.dci6.commands.cli', | ||||
|     }, | ||||
|     help='main CLI command for lazy example', | ||||
| ) | ||||
| def cli(): | ||||
|     pass | ||||
| 
 | ||||
| 
 | ||||
| if __name__ == '__main__': | ||||
|     cli() | ||||
| # TODO: delete this demo | ||||
| # Just show you which env get application or default values | ||||
| for key, value in env.dump().items(): | ||||
|     print(key, '|', value) | ||||
|  | ||||
| @ -1,4 +1,4 @@ | ||||
| from settings.general import BASE_DIR | ||||
| from settings.environment import BASE_DIR | ||||
| 
 | ||||
| from settings.platform import ( | ||||
|     PLATFORM_TYPE, | ||||
|  | ||||
| @ -2,21 +2,18 @@ from settings.environment import env | ||||
| from settings.platform import PLATFORM_CONFIG | ||||
| 
 | ||||
| 
 | ||||
| # ! Required because some instance use psql db: | ||||
| #! Required because some instance use psql db: | ||||
| DB_ENGINE = env.str( | ||||
|     'DB_ENGINE', | ||||
|     PLATFORM_CONFIG.get('DatabaseType', 'mysql') | ||||
| ) | ||||
| 
 | ||||
| # Connection parameters: | ||||
| DB_HOST = env.str( | ||||
|     'DB_HOST', | ||||
|     PLATFORM_CONFIG.get('DatabaseType', 'mysql') | ||||
| ) | ||||
| DB_HOST = env.str('DB_HOST', 'mysql') | ||||
| DB_PORT = env.int('DB_PORT', 3306) | ||||
| DB_USER = env.str('DB_USER', 'root') | ||||
| 
 | ||||
| # ! Do not pass password on production. Use value from config.json | ||||
| #! Do not pass password on production. Use value from config.json | ||||
| DB_PASSWORD = env.str( | ||||
|     'DB_PASSWORD', | ||||
|     PLATFORM_CONFIG.get('MysqlRootPassword', '') | ||||
|  | ||||
| @ -1,6 +1,11 @@ | ||||
| import pathlib | ||||
| from environs import Env | ||||
| 
 | ||||
| 
 | ||||
| # Build paths inside the project like this: BASE_DIR / 'subdir'. | ||||
| BASE_DIR = pathlib.Path(__file__).resolve().parent.parent | ||||
| 
 | ||||
| 
 | ||||
| # Init environment: | ||||
| env = Env() | ||||
| 
 | ||||
|  | ||||
| @ -1,15 +0,0 @@ | ||||
| import pathlib | ||||
| 
 | ||||
| 
 | ||||
| # Build paths inside the project like this: BASE_DIR / 'subdir'. | ||||
| BASE_DIR = pathlib.Path(__file__).resolve().parent.parent | ||||
| 
 | ||||
| INSTALLED_APPS = { | ||||
|     'vm6': { | ||||
|         'access': 'apps.vm6.access.commands.cli', | ||||
|         'nodes': 'apps.vm6.nodes.commands.cli', | ||||
|     }, | ||||
|     'dci6': { | ||||
|         'access': 'apps.dci6.access.commands.cli', | ||||
|     }, | ||||
| } | ||||
| @ -1,5 +1,4 @@ | ||||
| from settings.environment import env | ||||
| from settings.general import BASE_DIR | ||||
| from settings.environment import env, BASE_DIR | ||||
| from utils.helpers import parse_json_file | ||||
| 
 | ||||
| 
 | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user