コード例 #1
0
ファイル: resources.py プロジェクト: PoeBlu/botodocs
def create_sub_resource_index(path, resource_name, class_name,
                              sub_resource_name, param_str,
                              sub_resource_shape_name, shapes_path):
    create_new_file(path)
    sub_resource_variable = pythonic.xform_name(sub_resource_name)
    if '_' in sub_resource_variable:
        sub_resource_variable = sub_resource_variable[sub_resource_variable.
                                                      rindex('_') + 1:]
    resource_hint = f"botostubs.{class_name}.{class_name}Resource"
    sub_resource_title = f'{class_name}.{sub_resource_name}'
    return [
        f'# {sub_resource_title} sub-resource',
        f'A sub-resource representing `{sub_resource_title}`:\n',
        'You create such a resource as follows:',
        f"""```python
import boto3

resource = boto3.resource('{resource_name}')  # type: {resource_hint}
{sub_resource_variable} = resource.{sub_resource_name}({param_str})  # type: {resource_hint}.{sub_resource_name}
```
""",
        get_resource_equivalence_message(sub_resource_name,
                                         sub_resource_shape_name, shapes_path),
        get_botostubs_message(),
    ]
コード例 #2
0
ファイル: resources.py プロジェクト: PoeBlu/botodocs
def create_resource_index(path, resource_name, service_name, class_name):
    create_new_file(path)
    return [
        f'# {service_name} resource',
        f'A resource representing {service_name}:\n',
        'You create such a resource as follows:',
        f"""```python
import boto3

resource = boto3.resource('{resource_name}')  # type: botostubs.{class_name}.{class_name}Resource
```
""",
        get_botostubs_message(),
    ]
コード例 #3
0
ファイル: waiters.py プロジェクト: jeshan/botodocs
def create_waiter_index(path, client_name, service_name, waiter_name):
    create_new_file(path)
    return [
        f'# {service_name} waiters',
        f"""You get a waiter by calling `get_waiter` on a certain client:
```python
import boto3

client = boto3.client('{client_name}')
waiter = client.get_waiter('{pythonic.xform_name(waiter_name)}')  # type: botostubs.{service_name}.{waiter_name}Waiter
```
""",
        get_botostubs_message(),
        'The available client waiters are:',
    ]
コード例 #4
0
ファイル: paginators.py プロジェクト: jeshan/botodocs
def create_paginator_index(path, client_name, service_name,
                           example_paginator_name):
    create_new_file(path)
    return [
        f'# {service_name} paginators',
        f"""You get a paginator by calling `get_paginator` on a certain client:
```python
import boto3

client = boto3.client('{client_name}')
paginator = client.get_paginator('{pythonic.xform_name(example_paginator_name)}')  # type: botostubs.{service_name}.{example_paginator_name}Paginator
```
""",
        get_botostubs_message(),
        'The available client paginators are:',
    ]
コード例 #5
0
def create_collection_page(path, collection_name, resource_name, class_name,
                           parameter_str, client_name, service_path, op_name,
                           resource_path):
    create_new_file(path)

    def all():
        return f'Creates an iterable of all {resource_name} resources in the collection', ''

    def filter():
        return f'{all()[0]} filtered by kwargs passed to the method', parameter_str

    def limit():
        return (
            f'Creates an iterable up to a specified number of {resource_name} resources in the collection',
            'count=123',
        )

    def page_size():
        return (
            f'Creates an iterable of all {resource_name} resources in the collection, but limits the number of items returned by each service call by the specified number',
            'count=123',
        )

    new_resource_path = get_resource_path_for(resource_name, resource_path)
    result = [
        f'# {collection_name} collection',
        f'A collection of [{resource_name}]({new_resource_path}) resources:\n',
        '# Actions',
    ]
    for fn in [all, filter, limit, page_size]:
        result.append(f'## {fn.__name__}')
        doc, param_str = fn()
        result.append(doc)
        item_name = pythonic.xform_name(resource_name)
        result.append(f"""```python
{item_name}: botostubs.{class_name}.{class_name}Resource.{resource_name}
for {item_name} in resource.{collection_name}.{fn.__name__}({param_str}):
    pass # TODO: add your code here
```
""")
        if fn == filter:
            pythonic_op_name = pythonic.xform_name(op_name)
            result.append(f"""#### Accepts
{get_accepts_redirect_link(client_name, pythonic_op_name, service_path)}
""")
    result.append(get_botostubs_message())
    return result
コード例 #6
0
def create_client_index(path, client_name, service_name, class_name):
    create_new_file(path)
    return [
        f'# {service_name} client',
        f'A low-level client representing {service_name}.',
        'There are 2 main ways of creating clients; with a default `boto3.Session` or with one that you define:',
        f"""```python
import boto3

client = boto3.client('{client_name}')  # type: botostubs.{class_name}
```
""",
        'or ...',
        f"""```python
from boto3 import Session

session = Session(profile_name='your-aws-cli-profile')
client = session.client('{client_name}')  # type: botostubs.{class_name}
```""",
        get_botostubs_message(),
        '# Operations',
        'These are the available operations:',
    ]