forked from platformio/platformio-core
Add package type to unpublish command
This commit is contained in:
@@ -15,7 +15,7 @@
|
|||||||
from platformio import __registry_api__
|
from platformio import __registry_api__
|
||||||
from platformio.clients.account import AccountClient
|
from platformio.clients.account import AccountClient
|
||||||
from platformio.clients.rest import RESTClient
|
from platformio.clients.rest import RESTClient
|
||||||
from platformio.package.pack import PackageType
|
from platformio.package.spec import PackageType
|
||||||
|
|
||||||
|
|
||||||
class RegistryClient(RESTClient):
|
class RegistryClient(RESTClient):
|
||||||
@@ -42,13 +42,15 @@ class RegistryClient(RESTClient):
|
|||||||
)
|
)
|
||||||
return response
|
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()
|
account = AccountClient()
|
||||||
if not owner:
|
if not owner:
|
||||||
owner = (
|
owner = (
|
||||||
account.get_account_info(offline=True).get("profile").get("username")
|
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:
|
if version:
|
||||||
path = path + "/version/" + version
|
path = path + "/version/" + version
|
||||||
response = self.send_request(
|
response = self.send_request(
|
||||||
|
@@ -19,7 +19,7 @@ import click
|
|||||||
|
|
||||||
from platformio.clients.registry import RegistryClient
|
from platformio.clients.registry import RegistryClient
|
||||||
from platformio.package.pack import PackagePacker
|
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
|
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")
|
@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(
|
@click.option(
|
||||||
"--undo",
|
"--undo",
|
||||||
is_flag=True,
|
is_flag=True,
|
||||||
help="Undo a remove, putting a version back into the registry",
|
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)
|
spec = PackageSpec(package)
|
||||||
response = RegistryClient().unpublish_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")
|
click.secho(response.get("message"), fg="green")
|
||||||
|
@@ -19,49 +19,12 @@ import tarfile
|
|||||||
import tempfile
|
import tempfile
|
||||||
|
|
||||||
from platformio import fs
|
from platformio import fs
|
||||||
from platformio.compat import get_object_members
|
|
||||||
from platformio.package.exception import PackageException
|
from platformio.package.exception import PackageException
|
||||||
from platformio.package.manifest.parser import ManifestFileType, ManifestParserFactory
|
from platformio.package.manifest.parser import ManifestFileType, ManifestParserFactory
|
||||||
from platformio.package.manifest.schema import ManifestSchema
|
from platformio.package.manifest.schema import ManifestSchema
|
||||||
from platformio.unpacker import FileUnpacker
|
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):
|
class PackagePacker(object):
|
||||||
EXCLUDE_DEFAULT = [
|
EXCLUDE_DEFAULT = [
|
||||||
"._*",
|
"._*",
|
||||||
|
@@ -12,6 +12,47 @@
|
|||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# 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):
|
class PackageSpec(object):
|
||||||
def __init__(self, raw=None, organization=None, name=None, version=None):
|
def __init__(self, raw=None, organization=None, name=None, version=None):
|
||||||
|
Reference in New Issue
Block a user