mirror of
https://github.com/platformio/platformio-core.git
synced 2025-07-31 18:44:27 +02:00
Implement "lib register" command
This commit is contained in:
@@ -131,3 +131,12 @@ def lib_update():
|
||||
|
||||
lib_uninstall([name])
|
||||
lib_install([name])
|
||||
|
||||
|
||||
@cli.command("register", short_help="Register new library")
|
||||
@argument("config_url")
|
||||
def lib_register(config_url):
|
||||
result = get_api_result("/lib/register", data=dict(config_url=config_url))
|
||||
if "message" in result and result['message']:
|
||||
secho(result['message'], fg="green" if "successed" in result and
|
||||
result['successed'] else "red")
|
||||
|
@@ -8,7 +8,7 @@ from platform import system, uname
|
||||
from subprocess import PIPE, Popen
|
||||
from time import sleep
|
||||
|
||||
from requests import get
|
||||
from requests import get, post
|
||||
from requests.exceptions import ConnectionError, HTTPError
|
||||
from requests.utils import default_user_agent
|
||||
from serial import Serial
|
||||
@@ -114,13 +114,17 @@ def get_serialports():
|
||||
return[{"port": p, "description": d, "hwid": h} for p, d, h in comports()]
|
||||
|
||||
|
||||
def get_api_result(path, params=None):
|
||||
def get_api_result(path, params=None, data=None):
|
||||
result = None
|
||||
r = None
|
||||
try:
|
||||
headers = {"User-Agent": "PlatformIO/%s %s" % (
|
||||
__version__, default_user_agent())}
|
||||
r = get(__apiurl__ + path, params=params, headers=headers)
|
||||
if data:
|
||||
r = post(__apiurl__ + path, params=params, data=data,
|
||||
headers=headers)
|
||||
else:
|
||||
r = get(__apiurl__ + path, params=params, headers=headers)
|
||||
result = r.json()
|
||||
r.raise_for_status()
|
||||
except HTTPError as e:
|
||||
|
Reference in New Issue
Block a user