forked from platformio/platformio-core
PIO Account, Subscription, other improvements
This commit is contained in:
@ -14,7 +14,7 @@
|
|||||||
|
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
VERSION = (3, 2, "0a7")
|
VERSION = (3, 2, "0a8")
|
||||||
__version__ = ".".join([str(s) for s in VERSION])
|
__version__ = ".".join([str(s) for s in VERSION])
|
||||||
|
|
||||||
__title__ = "platformio"
|
__title__ = "platformio"
|
||||||
|
55
platformio/commands/account.py
Normal file
55
platformio/commands/account.py
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
# Copyright 2014-present PlatformIO <contact@platformio.org>
|
||||||
|
#
|
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
# you may not use this file except in compliance with the License.
|
||||||
|
# You may obtain a copy of the License at
|
||||||
|
#
|
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
# See the License for the specific language governing permissions and
|
||||||
|
# limitations under the License.
|
||||||
|
|
||||||
|
# pylint: disable=unused-argument
|
||||||
|
|
||||||
|
import sys
|
||||||
|
|
||||||
|
import click
|
||||||
|
|
||||||
|
from platformio.pioplus import pioplus_call
|
||||||
|
|
||||||
|
|
||||||
|
@click.group("account", short_help="Manage PIO Account")
|
||||||
|
def cli():
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
@cli.command("register", short_help="Create new PIO Account")
|
||||||
|
@click.option("-u", "--username")
|
||||||
|
def account_register(**kwargs):
|
||||||
|
pioplus_call(sys.argv[1:])
|
||||||
|
|
||||||
|
|
||||||
|
@cli.command("login", short_help="Log in to PIO Account")
|
||||||
|
@click.option("-u", "--username")
|
||||||
|
@click.option("-p", "--password")
|
||||||
|
def account_login(**kwargs):
|
||||||
|
pioplus_call(sys.argv[1:])
|
||||||
|
|
||||||
|
|
||||||
|
@cli.command("logout", short_help="Log out of PIO Account")
|
||||||
|
def account_logout():
|
||||||
|
pioplus_call(sys.argv[1:])
|
||||||
|
|
||||||
|
|
||||||
|
@cli.command("password", short_help="Change password")
|
||||||
|
def account_password():
|
||||||
|
pioplus_call(sys.argv[1:])
|
||||||
|
|
||||||
|
|
||||||
|
@cli.command("forgot", short_help="Forgot password")
|
||||||
|
@click.option("-u", "--username")
|
||||||
|
def account_forgot(**kwargs):
|
||||||
|
pioplus_call(sys.argv[1:])
|
@ -203,8 +203,8 @@ class EnvironmentProcessor(object):
|
|||||||
# warn about unknown options
|
# warn about unknown options
|
||||||
if k not in self.KNOWN_OPTIONS:
|
if k not in self.KNOWN_OPTIONS:
|
||||||
click.secho(
|
click.secho(
|
||||||
"Detected non-PlatformIO `%s` option in `[env:]` section"
|
"Detected non-PlatformIO `%s` option in `[env:]` section" %
|
||||||
% k,
|
k,
|
||||||
fg="yellow")
|
fg="yellow")
|
||||||
result[k] = v
|
result[k] = v
|
||||||
return result
|
return result
|
||||||
|
@ -23,7 +23,7 @@ from platformio.managers.package import PackageManager
|
|||||||
PACKAGE_DEPS = {"pysite": {"name": "pysite-pioplus",
|
PACKAGE_DEPS = {"pysite": {"name": "pysite-pioplus",
|
||||||
"requirements": ">=0.1.0"},
|
"requirements": ">=0.1.0"},
|
||||||
"tool": {"name": "tool-pioplus",
|
"tool": {"name": "tool-pioplus",
|
||||||
"requirements": ">=0.2.0"}}
|
"requirements": ">=0.3.0"}}
|
||||||
|
|
||||||
|
|
||||||
class PioPlusPackageManager(PackageManager):
|
class PioPlusPackageManager(PackageManager):
|
||||||
|
@ -392,8 +392,10 @@ def get_logicaldisks():
|
|||||||
match = disknamere.search(line.strip())
|
match = disknamere.search(line.strip())
|
||||||
if not match:
|
if not match:
|
||||||
continue
|
continue
|
||||||
disks.append({"disk": match.group(1),
|
disks.append({
|
||||||
"name": basename(match.group(1))})
|
"disk": match.group(1),
|
||||||
|
"name": basename(match.group(1))
|
||||||
|
})
|
||||||
return disks
|
return disks
|
||||||
|
|
||||||
|
|
||||||
@ -407,33 +409,43 @@ def _api_request_session():
|
|||||||
return requests.Session()
|
return requests.Session()
|
||||||
|
|
||||||
|
|
||||||
def _get_api_result(
|
def _get_api_result(url, # pylint: disable=too-many-branches
|
||||||
path, # pylint: disable=too-many-branches
|
|
||||||
params=None,
|
params=None,
|
||||||
data=None):
|
data=None,
|
||||||
|
auth=None):
|
||||||
from platformio.app import get_setting
|
from platformio.app import get_setting
|
||||||
|
|
||||||
result = None
|
result = None
|
||||||
r = None
|
r = None
|
||||||
|
disable_ssl_check = sys.version_info < (2, 7, 9)
|
||||||
|
|
||||||
headers = get_request_defheaders()
|
headers = get_request_defheaders()
|
||||||
url = __apiurl__
|
if not url.startswith("http"):
|
||||||
|
url = __apiurl__ + url
|
||||||
if not get_setting("enable_ssl"):
|
if not get_setting("enable_ssl"):
|
||||||
url = url.replace("https://", "http://")
|
url = url.replace("https://", "http://")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if data:
|
if data:
|
||||||
r = _api_request_session().post(
|
r = _api_request_session().post(
|
||||||
url + path, params=params, data=data, headers=headers)
|
url,
|
||||||
else:
|
|
||||||
r = _api_request_session().get(url + path,
|
|
||||||
params=params,
|
params=params,
|
||||||
headers=headers)
|
data=data,
|
||||||
|
headers=headers,
|
||||||
|
auth=auth,
|
||||||
|
verify=disable_ssl_check)
|
||||||
|
else:
|
||||||
|
r = _api_request_session().get(url,
|
||||||
|
params=params,
|
||||||
|
headers=headers,
|
||||||
|
auth=auth,
|
||||||
|
verify=disable_ssl_check)
|
||||||
result = r.json()
|
result = r.json()
|
||||||
r.raise_for_status()
|
r.raise_for_status()
|
||||||
except requests.exceptions.HTTPError as e:
|
except requests.exceptions.HTTPError as e:
|
||||||
if result and "errors" in result:
|
if result and "message" in result:
|
||||||
|
raise exception.APIRequestError(result['message'])
|
||||||
|
elif result and "errors" in result:
|
||||||
raise exception.APIRequestError(result['errors'][0]['title'])
|
raise exception.APIRequestError(result['errors'][0]['title'])
|
||||||
else:
|
else:
|
||||||
raise exception.APIRequestError(e)
|
raise exception.APIRequestError(e)
|
||||||
@ -446,11 +458,11 @@ def _get_api_result(
|
|||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
def get_api_result(path, params=None, data=None, cache_valid=None):
|
def get_api_result(url, params=None, data=None, auth=None, cache_valid=None):
|
||||||
from platformio.app import LocalCache
|
from platformio.app import LocalCache
|
||||||
total = 0
|
total = 0
|
||||||
max_retries = 5
|
max_retries = 5
|
||||||
cache_key = (LocalCache.key_from_args(path, params, data)
|
cache_key = (LocalCache.key_from_args(url, params, data, auth)
|
||||||
if cache_valid else None)
|
if cache_valid else None)
|
||||||
while total < max_retries:
|
while total < max_retries:
|
||||||
try:
|
try:
|
||||||
@ -459,7 +471,7 @@ def get_api_result(path, params=None, data=None, cache_valid=None):
|
|||||||
result = lc.get(cache_key)
|
result = lc.get(cache_key)
|
||||||
if result is not None:
|
if result is not None:
|
||||||
return result
|
return result
|
||||||
result = _get_api_result(path, params, data)
|
result = _get_api_result(url, params, data)
|
||||||
if cache_valid:
|
if cache_valid:
|
||||||
with LocalCache() as lc:
|
with LocalCache() as lc:
|
||||||
lc.set(cache_key, result, cache_valid)
|
lc.set(cache_key, result, cache_valid)
|
||||||
@ -478,7 +490,7 @@ def get_api_result(path, params=None, data=None, cache_valid=None):
|
|||||||
sleep(2 * total)
|
sleep(2 * total)
|
||||||
|
|
||||||
raise exception.APIRequestError(
|
raise exception.APIRequestError(
|
||||||
"Could not connect to PlatformIO Registry Service. "
|
"Could not connect to PlatformIO API Service. "
|
||||||
"Please try later.")
|
"Please try later.")
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user