Add package type to unpublish command

This commit is contained in:
Ivan Kravets
2020-05-27 14:30:27 +03:00
parent e706a2cfe2
commit c06859aa9f
4 changed files with 62 additions and 44 deletions

View File

@@ -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(

View File

@@ -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>/]<pkg>[@<version>]")
@click.argument(
"package", required=True, metavar="[<@organization>/]<pkgname>[@<version>]"
)
@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")

View File

@@ -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 = [
"._*",

View File

@@ -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):