Implement "lib register" command

This commit is contained in:
Ivan Kravets
2014-09-08 22:02:57 +03:00
parent c4b28ab252
commit 813c818477
2 changed files with 16 additions and 3 deletions

View File

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

View File

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