Skip to content

CLI

ProxyNotFoundError

Bases: Exception

Raised when a specific proxy is not found.

Source code in sonyci/cli.py
34
35
class ProxyNotFoundError(Exception):
    """Raised when a specific proxy is not found."""

asset(ctx, asset)

Search for files in a Sony CI workspace

Source code in sonyci/cli.py
145
146
147
148
149
150
151
152
153
154
155
156
157
@app.command()
def asset(
    ctx: Context,
    asset: Annotated[str, Argument(..., help='The asset ID to search for')],
):
    """Search for files in a Sony CI workspace"""
    ci = SonyCi(
        t=ctx.parent.params['token'], workspace_id=ctx.parent.params['workspace_id']
    )
    log.trace(f'asset {asset}')
    result = ci.asset(asset)
    log.success(result)
    print(dumps(result))

download(ctx, id, proxy=None, output=None)

Download a file from Sony CI

Source code in sonyci/cli.py
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
@app.command()
def download(
    ctx: Context,
    id: Annotated[str, Argument(..., help='The SonyCi ID of the file to download')],
    proxy: Annotated[ProxyType, Option('--proxy', '-p', help='Download ')] = None,
    output: Annotated[
        Optional[Path],
        Option('--output', '-o', help='The path to download the file to'),
    ] = None,
):
    """Download a file from Sony CI"""
    ci = SonyCi(t=ctx.parent.params['token'])
    log.trace(f'download id: {id} proxy: {proxy} output: {output}')
    result = ci.asset_download(id)
    link = result['location']
    if proxy:
        for p in result['proxies']:
            if p['type'] == proxy.value:
                log.debug(f'found proxy {proxy.value}')
                link = p['location']
                break
        # Check if matching proxy was found. Raise an exception if not found.
        if link == result['location']:
            raise ProxyNotFoundError(f'proxy {proxy} not found')

    log.trace(f'link: {link}')
    filename = output or Path(link).name.split('?')[0]
    log.debug(f'downloading {id} to {filename}')
    urlretrieve(link, filename)
    log.success(f'downloaded {id} to {filename}')

get(ctx, path)

Make a GET request to Sony CI.

Source code in sonyci/cli.py
74
75
76
77
78
79
80
81
@app.command()
def get(ctx: Context, path: Annotated[str, Argument(..., help='The path to GET')]):
    """Make a GET request to Sony CI."""
    ci = SonyCi(t=ctx.parent.params['token'])
    log.trace(f'GET {path}')
    result = ci(path)
    log.success(result)
    print(dumps(result))

login(ctx, username=Option(Ellipsis, '--username', '-u', help='Sony CI username.', envvar='CI_USERNAME'), password=Option(Ellipsis, '--password', '-p', help='Sony CI password.', envvar='CI_PASSWORD'), test=Option(False, '--test', '-t', help='Skips saving the token.'))

Login to Sony CI.

Source code in sonyci/cli.py
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
@app.command()
def login(
    ctx: Context,
    username: str = Option(
        ..., '--username', '-u', help='Sony CI username.', envvar='CI_USERNAME'
    ),
    password: str = Option(
        ..., '--password', '-p', help='Sony CI password.', envvar='CI_PASSWORD'
    ),
    test: bool = Option(False, '--test', '-t', help='Skips saving the token.'),
):
    """Login to Sony CI."""
    from sonyci.utils import get_token

    token: BearerToken = get_token(
        username,
        password,
        ctx.parent.params.get('client_id'),
        ctx.parent.params.get('client_secret'),
    )
    if not test:
        save_token_to_file(token, '.token')
    log.success('logged in to Sony CI!')

parse_bearer_token(token)

Parse a bearer token from a json string.

Source code in sonyci/cli.py
19
20
21
def parse_bearer_token(token: str) -> BearerToken:
    """Parse a bearer token from a json string."""
    return BearerToken(loads(token))

post(ctx, path, data=Argument(help='The data to POST'))

Make a POST request to Sony CI.

Source code in sonyci/cli.py
84
85
86
87
88
89
90
91
92
93
94
95
96
@app.command()
def post(
    ctx: Context,
    path: Annotated[str, Argument(..., help='The path to POST')],
    data=Argument(help='The data to POST'),
):
    """Make a POST request to Sony CI."""
    ci = SonyCi(t=ctx.parent.params['token'])
    data = loads(data)
    log.debug(f'POST {path} {data}')
    result = ci.post(path, data)
    log.success(result)
    print(dumps(result))

search(ctx, query)

Search for files in a Sony CI workspace

Source code in sonyci/cli.py
 99
100
101
102
103
104
105
106
107
108
109
110
@app.command()
def search(
    ctx: Context, query: Annotated[str, Argument(..., help='The query to search for')]
):
    """Search for files in a Sony CI workspace"""
    ci = SonyCi(
        t=ctx.parent.params['token'], workspace_id=ctx.parent.params['workspace_id']
    )
    log.trace(f'search {query}')
    result = ci.workspace_search(query)
    log.success(result)
    print(dumps(result))

version_callback(value)

Print the version of the program and exit.

Source code in sonyci/cli.py
24
25
26
27
28
29
30
31
def version_callback(value: bool):
    """Print the version of the program and exit."""
    if value:
        from ._version import __version__

        print(f'v{__version__}')

        raise Exit()