def command(): """Render all commands spec. Render all commands with their spec, examples, schemas etc. so far created for a current version of the service. """ config = Config() commands_dir_path = os.path.join(Config.get_lily_path(), 'commands') if not os.path.exists(commands_dir_path): os.mkdir(commands_dir_path) version = config.next_version or config.version commands_path = os.path.join(commands_dir_path, f'{version}.json') with open(commands_path, 'w') as f: commands = CommandsRenderer().render() enums = commands.pop('enums') commands = { name: CommandSerializer(conf).data for name, conf in commands.items() } f.write( json.dumps({ **commands, 'enums': enums, }, indent=4, sort_keys=False)) click.secho(f'Commands rendered for to file {commands_path}', fg='green')
def command(): config = Config() commands_dir = os.path.join(config.get_lily_path(), 'commands') excluded = (settings.LILY_EXCLUDE_QUERY_PARSER_ALL_OPTIONAL_ASSERTIONS or []) with open(os.path.join(commands_dir, f'{config.version}.json'), 'r') as f: commands = json.loads(f.read()) for name, command in commands.items(): if name in excluded or name == 'enums': continue input_query = command['schemas'].get('input_query', {'schema': { 'required': [] }}) if input_query['schema']['required']: fields = ','.join(input_query['schema']['required']) raise CommandError( f"ERROR: query parser for '{name}' has some not optional " f"fields: [{fields}]")
def get_commands(self, version=None): config = Config() version = version or config.version commands_dir_path = os.path.join(Config.get_lily_path(), 'commands') commands_path = os.path.join(commands_dir_path, f'{version}.json') with open(commands_path, 'r') as f: return json.loads(f.read())
def get_available_versions(self): commands_dir_path = os.path.join(Config.get_lily_path(), 'commands') return sorted([ commands_file.replace('.json', '') for commands_file in os.listdir(commands_dir_path) ], key=lambda x: [int(e) for e in x.split('.')], reverse=True)
def command(): examples_path = os.path.join(Config.get_lily_path(), 'examples.json') try: os.remove(examples_path) except FileNotFoundError: pass click.echo("'examples.json' was removed")
def command(v): config = Config() migrations_dir_path = os.path.join(config.get_lily_path(), 'migrations') migrations_path = os.path.join(migrations_dir_path, f'{v}.json') with open(migrations_path, 'r') as f: migrations_plan = json.loads(f.read())['plan'] for app_name, migration in migrations_plan: management.call_command('migrate', app_name, migration) click.secho(f'Migrations plan for version {v} applied.', fg='green')
def command(): config = Config() migrations_dir_path = os.path.join(config.get_lily_path(), 'migrations') if not os.path.exists(migrations_dir_path): os.mkdir(migrations_dir_path) version = config.next_version or config.version migrations_path = os.path.join(migrations_dir_path, f'{version}.json') with open(migrations_path, 'w') as f: f.write(json.dumps(Renderer().render(), indent=4, sort_keys=False)) click.secho(f'Migrations plan rendered for to file {migrations_path}', fg='green')
def command(): """Render Markdown Specification for all registered Commands.""" # -- make sure that the main directory is also visible during # -- the search of all url patterns sys.path.insert(0, os.getcwd()) urlpatterns = import_module(settings.ROOT_URLCONF).urlpatterns with open(os.path.join(Config.get_lily_path(), 'API.md'), 'w') as f: f.write(MarkdownRenderer(urlpatterns).render()) click.secho( 'Successfully rendered Markdown Specification for all ' 'registered Commands', fg='green')
def test_get_lily_path(self): assert Config.get_lily_path() == str(self.tmpdir.join('.lily'))
def get_commands(self): commands_path = os.path.join(Config.get_lily_path(), 'commands', f'{Config().version}.json') with open(commands_path, 'r') as f: return json.loads(f.read())
def get_examples_filepath(): return os.path.join(Config.get_lily_path(), 'examples.json')