Add new option to package publishing CLI which allows to disable email notiication

This commit is contained in:
Ivan Kravets
2020-05-28 17:06:36 +03:00
parent ae58cc74bd
commit 26ba6e4756
2 changed files with 16 additions and 5 deletions

View File

@ -17,13 +17,15 @@ from platformio.clients.account import AccountClient
from platformio.clients.rest import RESTClient from platformio.clients.rest import RESTClient
from platformio.package.spec import PackageType from platformio.package.spec import PackageType
# pylint: disable=too-many-arguments
class RegistryClient(RESTClient): class RegistryClient(RESTClient):
def __init__(self): def __init__(self):
super(RegistryClient, self).__init__(base_url=__registry_api__) super(RegistryClient, self).__init__(base_url=__registry_api__)
def publish_package( def publish_package(
self, archive_path, owner=None, released_at=None, private=False self, archive_path, owner=None, released_at=None, private=False, notify=True
): ):
account = AccountClient() account = AccountClient()
if not owner: if not owner:
@ -34,7 +36,11 @@ class RegistryClient(RESTClient):
response = self.send_request( response = self.send_request(
"post", "post",
"/v3/package/%s/%s" % (owner, PackageType.from_archive(archive_path)), "/v3/package/%s/%s" % (owner, PackageType.from_archive(archive_path)),
params={"private": 1 if private else 0, "released_at": released_at}, params={
"private": 1 if private else 0,
"notify": 1 if notify else 0,
"released_at": released_at,
},
headers={ headers={
"Authorization": "Bearer %s" % account.fetch_authentication_token(), "Authorization": "Bearer %s" % account.fetch_authentication_token(),
"Content-Type": "application/octet-stream", "Content-Type": "application/octet-stream",
@ -46,7 +52,7 @@ class RegistryClient(RESTClient):
) )
return response return response
def unpublish_package( # pylint: disable=redefined-builtin,too-many-arguments def unpublish_package( # pylint: disable=redefined-builtin
self, type, name, owner=None, version=None, undo=False self, type, name, owner=None, version=None, undo=False
): ):
account = AccountClient() account = AccountClient()

View File

@ -58,11 +58,16 @@ def package_pack(package):
help="Custom release date and time in the next format (UTC): 2014-06-13 17:08:52", help="Custom release date and time in the next format (UTC): 2014-06-13 17:08:52",
) )
@click.option("--private", is_flag=True, help="Restricted access (not a public)") @click.option("--private", is_flag=True, help="Restricted access (not a public)")
def package_publish(package, owner, released_at, private): @click.option(
"--notify/--no-notify",
default=True,
help="Notify by email when package is processed",
)
def package_publish(package, owner, released_at, private, notify):
p = PackagePacker(package) p = PackagePacker(package)
archive_path = p.pack() archive_path = p.pack()
response = RegistryClient().publish_package( response = RegistryClient().publish_package(
archive_path, owner, released_at, private archive_path, owner, released_at, private, notify
) )
os.remove(archive_path) os.remove(archive_path)
click.secho(response.get("message"), fg="green") click.secho(response.get("message"), fg="green")