diff --git a/platformio/clients/registry.py b/platformio/clients/registry.py index 8c4d41c6..f68c4fb4 100644 --- a/platformio/clients/registry.py +++ b/platformio/clients/registry.py @@ -15,7 +15,7 @@ from platformio import __registry_api__ from platformio.clients.account import AccountClient from platformio.clients.rest import RESTClient -from platformio.package.pack import PackageType +from platformio.package.spec import PackageType class RegistryClient(RESTClient): @@ -42,13 +42,15 @@ class RegistryClient(RESTClient): ) return response - def unpublish_package(self, name, owner=None, version=None, undo=False): + def unpublish_package( # pylint: disable=redefined-builtin,too-many-arguments + self, type, name, owner=None, version=None, undo=False + ): account = AccountClient() if not owner: owner = ( account.get_account_info(offline=True).get("profile").get("username") ) - path = "/v3/package/%s/%s" % (owner, name) + path = "/v3/package/%s/%s/%s" % (owner, type, name) if version: path = path + "/version/" + version response = self.send_request( diff --git a/platformio/commands/package.py b/platformio/commands/package.py index 93423cc7..04e78e30 100644 --- a/platformio/commands/package.py +++ b/platformio/commands/package.py @@ -19,7 +19,7 @@ import click from platformio.clients.registry import RegistryClient from platformio.package.pack import PackagePacker -from platformio.package.spec import PackageSpec +from platformio.package.spec import PackageSpec, PackageType def validate_datetime(ctx, param, value): # pylint: disable=unused-argument @@ -67,15 +67,27 @@ def package_publish(package, owner, released_at, private): @cli.command("unpublish", short_help="Remove a pushed package from the registry") -@click.argument("package", required=True, metavar="[<@organization>/][@]") +@click.argument( + "package", required=True, metavar="[<@organization>/][@]" +) +@click.option( + "--type", + type=click.Choice(list(PackageType.items().values())), + default="library", + help="Package type, default is set to `library`", +) @click.option( "--undo", is_flag=True, help="Undo a remove, putting a version back into the registry", ) -def package_unpublish(package, undo): +def package_unpublish(package, type, undo): # pylint: disable=redefined-builtin spec = PackageSpec(package) response = RegistryClient().unpublish_package( - name=spec.name, owner=spec.organization, version=spec.version, undo=undo + type=type, + name=spec.name, + owner=spec.organization, + version=spec.version, + undo=undo, ) click.secho(response.get("message"), fg="green") diff --git a/platformio/package/pack.py b/platformio/package/pack.py index ecf14a4f..1e18c55a 100644 --- a/platformio/package/pack.py +++ b/platformio/package/pack.py @@ -19,49 +19,12 @@ import tarfile import tempfile from platformio import fs -from platformio.compat import get_object_members from platformio.package.exception import PackageException from platformio.package.manifest.parser import ManifestFileType, ManifestParserFactory from platformio.package.manifest.schema import ManifestSchema from platformio.unpacker import FileUnpacker -class PackageType(object): - LIBRARY = "library" - PLATFORM = "platform" - TOOL = "tool" - - @classmethod - def items(cls): - return get_object_members(cls) - - @classmethod - def get_manifest_map(cls): - return { - cls.PLATFORM: (ManifestFileType.PLATFORM_JSON,), - cls.LIBRARY: ( - ManifestFileType.LIBRARY_JSON, - ManifestFileType.LIBRARY_PROPERTIES, - ManifestFileType.MODULE_JSON, - ), - cls.TOOL: (ManifestFileType.PACKAGE_JSON,), - } - - @classmethod - def from_archive(cls, path): - assert path.endswith("tar.gz") - manifest_map = cls.get_manifest_map() - with tarfile.open(path, mode="r|gz") as tf: - for t in sorted(cls.items().values()): - try: - for manifest in manifest_map[t]: - if tf.getmember(manifest): - return t - except KeyError: - pass - return None - - class PackagePacker(object): EXCLUDE_DEFAULT = [ "._*", diff --git a/platformio/package/spec.py b/platformio/package/spec.py index 0de8227a..e729dae2 100644 --- a/platformio/package/spec.py +++ b/platformio/package/spec.py @@ -12,6 +12,47 @@ # See the License for the specific language governing permissions and # limitations under the License. +import tarfile + +from platformio.compat import get_object_members +from platformio.package.manifest.parser import ManifestFileType + + +class PackageType(object): + LIBRARY = "library" + PLATFORM = "platform" + TOOL = "tool" + + @classmethod + def items(cls): + return get_object_members(cls) + + @classmethod + def get_manifest_map(cls): + return { + cls.PLATFORM: (ManifestFileType.PLATFORM_JSON,), + cls.LIBRARY: ( + ManifestFileType.LIBRARY_JSON, + ManifestFileType.LIBRARY_PROPERTIES, + ManifestFileType.MODULE_JSON, + ), + cls.TOOL: (ManifestFileType.PACKAGE_JSON,), + } + + @classmethod + def from_archive(cls, path): + assert path.endswith("tar.gz") + manifest_map = cls.get_manifest_map() + with tarfile.open(path, mode="r|gz") as tf: + for t in sorted(cls.items().values()): + try: + for manifest in manifest_map[t]: + if tf.getmember(manifest): + return t + except KeyError: + pass + return None + class PackageSpec(object): def __init__(self, raw=None, organization=None, name=None, version=None):