forked from platformio/platformio-core
Avoid trademark issues in library.json; switch to PlatformIO Library Registry ID logic
Resolve issue #17
This commit is contained in:
10
HISTORY.rst
10
HISTORY.rst
@ -4,6 +4,16 @@ Release History
|
||||
0.8.0 (?)
|
||||
---------
|
||||
|
||||
* Avoided trademark issues in ``library.json`` with new fields:
|
||||
``frameworks``, ``platforms`` and ``dependencies`` (`issue #17 <https://github.com/ivankravets/platformio/issues/17>`_)
|
||||
* Switched logic from "Library Name" to "Library Registry ID" for all
|
||||
``platformio lib`` commands (install, uninstall, update and etc.)
|
||||
* Renamed ``author`` field to ``authors`` and allowed to setup multiple authors
|
||||
per library in ``library.json``
|
||||
* Added option to specify "maintainer" status in ``authors`` field
|
||||
* New filters/options for ``platformio lib search`` command: ``--framework``
|
||||
and ``--platform``
|
||||
|
||||
0.7.1 (2014-10-06)
|
||||
------------------
|
||||
|
||||
|
@ -10,13 +10,14 @@ Usage
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
platformio lib install [OPTIONS] [NAMES]
|
||||
platformio lib install [OPTIONS] [LIBRARY_ID]
|
||||
|
||||
|
||||
Description
|
||||
-----------
|
||||
|
||||
Install new library
|
||||
Install new library by specified
|
||||
`PlatformIO Library Registry ID <http://platformio.ikravets.com/#!/lib>`_.
|
||||
|
||||
Options
|
||||
-------
|
||||
@ -34,35 +35,38 @@ Examples
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
$ platformio lib install Arduino-IRremote
|
||||
Installing Arduino-IRremote library:
|
||||
# IRremote: http://platformio.ikravets.com/#!/lib/show/4
|
||||
$ platformio lib install 4
|
||||
Installing library [ 4 ]:
|
||||
Downloading [####################################] 100%
|
||||
Unpacking [####################################] 100%
|
||||
The library 'Arduino-IRremote' has been successfully installed!
|
||||
The library #4 'IRremote' has been successfully installed!
|
||||
|
||||
|
||||
2. Install specified version of library
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
$ platformio lib install Arduino-XBee --version=0.5
|
||||
Installing Arduino-XBee library:
|
||||
# XBee: http://platformio.ikravets.com/#!/lib/show/6
|
||||
$ platformio lib install 6 --version=0.5
|
||||
Installing library [ 6 ]:
|
||||
Downloading [####################################] 100%
|
||||
Unpacking [####################################] 100%
|
||||
The library 'Arduino-XBee' has been successfully installed!
|
||||
The library #6 'XBee' has been successfully installed!
|
||||
|
||||
|
||||
3. Install library with dependencies
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
$ platformio lib install Adafruit-Arduino-ST7735
|
||||
Installing Adafruit-Arduino-ST7735 library:
|
||||
# Adafruit-ST7735: http://platformio.ikravets.com/#!/lib/show/12
|
||||
$ platformio lib install 12
|
||||
Installing library [ 12 ]:
|
||||
Downloading [####################################] 100%
|
||||
Unpacking [####################################] 100%
|
||||
The library 'Adafruit-Arduino-ST7735' has been successfully installed!
|
||||
The library #12 'Adafruit-ST7735' has been successfully installed!
|
||||
Installing dependencies:
|
||||
Installing Adafruit-Arduino-GFX library:
|
||||
Installing library [ 13 ]:
|
||||
Downloading [####################################] 100%
|
||||
Unpacking [####################################] 100%
|
||||
The library 'Adafruit-Arduino-GFX' has been successfully installed!
|
||||
The library #13 'Adafruit-GFX' has been successfully installed!
|
||||
|
@ -25,7 +25,15 @@ Examples
|
||||
.. code-block:: bash
|
||||
|
||||
$ platformio lib list
|
||||
Arduino-IRremote Send and receive infrared signals with multiple protocols
|
||||
|
||||
[ ID ] Name Compatibility "Authors": Description
|
||||
-------------------------------------------------------------------------------------
|
||||
[ 23 ] Adafruit-L3GD20-Unified arduino, atmelavr "Adafruit Industries": Unified sensor driver for the L3GD20 Gyroscope
|
||||
[ 12 ] Adafruit-ST7735 arduino, atmelavr "Adafruit Industries": A library for the Adafruit 1.8" SPI display
|
||||
[ 31 ] Adafruit-Unified-Sensor arduino, atmelavr "Adafruit Industries": Adafruit Unified Sensor Driver
|
||||
[ 26 ] Adafruit-LSM303DLHC-Unified arduino, atmelavr "Adafruit Industries": Unified sensor driver for Adafruit's LSM303 Breakout (Accelerometer + Magnetometer)
|
||||
[ 6 ] XBee arduino, atmelavr "Andrew Rapp": Arduino library for communicating with XBees in API mode
|
||||
[ 13 ] Adafruit-GFX arduino, atmelavr "Adafruit Industries": A core graphics library for all our displays, providing a common set of graphics primitives (points, lines, circles, etc.)
|
||||
[ 4 ] IRremote arduino, atmelavr "Ken Shirriff": Send and receive infrared signals with multiple protocols
|
||||
[ 14 ] Adafruit-9DOF-Unified arduino, atmelavr "Adafruit Industries": Unified sensor driver for the Adafruit 9DOF Breakout (L3GD20 / LSM303)
|
||||
...
|
||||
Arduino-Webduino An extensible web server library (for use with the Arduino Ethernet Shield)
|
||||
Arduino-XBee Arduino library for communicating with XBees in API mode
|
||||
|
@ -16,8 +16,8 @@ Usage
|
||||
Description
|
||||
-----------
|
||||
|
||||
Search for library over ``name``, ``description`` and ``keywords`` fields from
|
||||
the :ref:`library_config` file in the boolean mode.
|
||||
Search for library in *PlatformIO Library Registry* by
|
||||
:ref:`library_config` fields in the boolean mode.
|
||||
|
||||
The boolean search capability supports the following operators:
|
||||
|
||||
@ -71,66 +71,119 @@ Filter libraries by specified author
|
||||
|
||||
Filter libraries by specified keyword
|
||||
|
||||
|
||||
.. option::
|
||||
-f, --framework
|
||||
|
||||
Filter libraries by specified framework
|
||||
|
||||
|
||||
.. option::
|
||||
-p, --platform
|
||||
|
||||
Filter libraries by specified keyword
|
||||
|
||||
Examples
|
||||
--------
|
||||
|
||||
1. Search for "1-Wire" library
|
||||
1. List all libraries
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
$ platformio lib search ""
|
||||
Found N libraries:
|
||||
|
||||
[ ID ] Name Compatibility "Authors": Description
|
||||
-------------------------------------------------------------------------------------
|
||||
[ 14 ] Adafruit-9DOF-Unified arduino, atmelavr "Adafruit Industries": Unified sensor driver for the Adafruit 9DOF Breakout (L3GD20 / LSM303)
|
||||
[ 13 ] Adafruit-GFX arduino, atmelavr "Adafruit Industries": A core graphics library for all our displays, providing a common set of graphics primitives (points, lines, circles, etc.)
|
||||
[ 23 ] Adafruit-L3GD20-Unified arduino, atmelavr "Adafruit Industries": Unified sensor driver for the L3GD20 Gyroscope
|
||||
[ 26 ] Adafruit-LSM303DLHC-Unified arduino, atmelavr "Adafruit Industries": Unified sensor driver for Adafruit's LSM303 Breakout (Accelerometer + Magnetometer)
|
||||
[ 12 ] Adafruit-ST7735 arduino, atmelavr "Adafruit Industries": A library for the Adafruit 1.8" SPI display
|
||||
[ 31 ] Adafruit-Unified-Sensor arduino, atmelavr "Adafruit Industries": Adafruit Unified Sensor Driver
|
||||
[ 4 ] IRremote arduino, atmelavr "Ken Shirriff": Send and receive infrared signals with multiple protocols
|
||||
[ 1 ] OneWire arduino, atmelavr "Paul Stoffregen": Control devices (from Dallas Semiconductor) that use the One Wire protocol (DS18S20, DS18B20, DS2408 and etc)
|
||||
[ 6 ] XBee arduino, atmelavr "Andrew Rapp": Arduino library for communicating with XBees in API mode
|
||||
[ 15 ] Adafruit-ADXL345-Unified arduino, atmelavr "Adafruit Industries": Unified driver for the ADXL345 Accelerometer
|
||||
Show next libraries? [y/N]:
|
||||
...
|
||||
|
||||
2. Search for "1-Wire" library
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
$ platformio lib search 1-wire
|
||||
Found N libraries:
|
||||
Arduino-OneWire Control devices (from Dallas Semiconductor) that use the One Wire protocol
|
||||
|
||||
[ ID ] Name Compatibility "Authors": Description
|
||||
-------------------------------------------------------------------------------------
|
||||
[ 1 ] OneWire arduino, atmelavr "Paul Stoffregen": Control devices (from Dallas Semiconductor) that use the One Wire protocol (DS18S20, DS18B20, DS2408 and etc)
|
||||
...
|
||||
|
||||
2. Search for Arduino-based "I2C" libraries. The ``+`` sign is here like ``AND``
|
||||
3. Search for Arduino-based "I2C" libraries. The ``+`` sign is here like ``AND``
|
||||
operator.
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
$ platformio lib search "+i2c +arduino"
|
||||
$ platformio lib search "+i2c" --framework=arduino
|
||||
Found N libraries:
|
||||
i2cdevlib-Arduino-i2cdev The I2C Device Library (i2cdevlib) is a collection of uniform and well-documented classes to provide simple and intuitive interfaces to I2C devices.
|
||||
i2cdevlib-Arduino-AK8975 AK8975 is 3-axis electronic compass IC with high sensitive Hall sensor technology
|
||||
|
||||
[ ID ] Name Compatibility "Authors": Description
|
||||
-------------------------------------------------------------------------------------
|
||||
[ 11 ] I2Cdevlib-Core arduino, atmelavr "Jeff Rowberg": The I2C Device Library (I2Cdevlib) is a collection of uniform and well-documented classes to provide simple and intuitive interfaces to I2C devices.
|
||||
[ 24 ] Adafruit-L3GD20 arduino, atmelavr "Adafruit Industries": Driver for Adafruit's L3GD20 I2C Gyroscope Breakout
|
||||
[ 10 ] I2Cdevlib-AK8975 arduino, atmelavr "Jeff Rowberg": AK8975 is 3-axis electronic compass IC with high sensitive Hall sensor technology
|
||||
[ 14 ] Adafruit-9DOF-Unified arduino, atmelavr "Adafruit Industries": Unified sensor driver for the Adafruit 9DOF Breakout (L3GD20 / LSM303)
|
||||
...
|
||||
|
||||
3. Search for libraries by "web" and "http" keywords. The ``""`` here is for
|
||||
4. Search for libraries by "web" and "http" keywords. The ``""`` here is for
|
||||
"empty" query argument.
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
$ platformio lib search "" --keyword web --keyword http
|
||||
$ platformio lib search "" --keyword=web --keyword=http
|
||||
Found N libraries:
|
||||
Arduino-Webduino An extensible web server library (for use with the Arduino Ethernet Shield)
|
||||
Arduino-aJson An Arduino library to enable JSON processing with Arduino
|
||||
|
||||
[ ID ] Name Compatibility "Authors": Description
|
||||
-------------------------------------------------------------------------------------
|
||||
[ 5 ] Webduino arduino, atmelavr "Ben Combee": An extensible web server library (for use with the Arduino WizNet Ethernet Shield)
|
||||
[ 17 ] Adafruit-CC3000 arduino, atmelavr "Adafruit Industries": Library code for Adafruit's CC3000 Wi-Fi/WiFi breakouts
|
||||
...
|
||||
|
||||
4. Search for libraries from "Adafruit Industries" author.
|
||||
5. Search for libraries from "Adafruit Industries" author.
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
$ platformio lib search "" --author "Adafruit Industries"
|
||||
$ platformio lib search "" --author="Adafruit Industries"
|
||||
Found N libraries:
|
||||
Adafruit-Arduino-ST7735 A library for the Adafruit 1.8" SPI display
|
||||
Adafruit-Arduino-GFX A core graphics library for all our displays, providing a common set of graphics primitives (points, lines, circles, etc.)
|
||||
|
||||
[ ID ] Name Compatibility "Authors": Description
|
||||
-------------------------------------------------------------------------------------
|
||||
[ 14 ] Adafruit-9DOF-Unified arduino, atmelavr "Adafruit Industries": Unified sensor driver for the Adafruit 9DOF Breakout (L3GD20 / LSM303)
|
||||
[ 13 ] Adafruit-GFX arduino, atmelavr "Adafruit Industries": A core graphics library for all our displays, providing a common set of graphics primitives (points, lines, circles, etc.)
|
||||
[ 23 ] Adafruit-L3GD20-Unified arduino, atmelavr "Adafruit Industries": Unified sensor driver for the L3GD20 Gyroscope
|
||||
[ 26 ] Adafruit-LSM303DLHC-Unified arduino, atmelavr "Adafruit Industries": Unified sensor driver for Adafruit's LSM303 Breakout (Accelerometer + Magnetometer)
|
||||
...
|
||||
|
||||
5. Search for libraries that are compatible with Dallas temperature sensors
|
||||
6. Search for libraries that are compatible with Dallas temperature sensors
|
||||
like DS18B20, DS18S20 and etc.
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
$ platformio lib search "DS*"
|
||||
Found N libraries:
|
||||
Arduino-OneWire Control devices (from Dallas Semiconductor) that use the One Wire protocol
|
||||
|
||||
[ ID ] Name Compatibility "Authors": Description
|
||||
-------------------------------------------------------------------------------------
|
||||
[ 1 ] OneWire arduino, atmelavr "Paul Stoffregen": Control devices (from Dallas Semiconductor) that use the One Wire protocol (DS18S20, DS18B20, DS2408 and etc)
|
||||
...
|
||||
|
||||
6. Search for Arduino-based *X10* or *XBee* libraries. The search query that is
|
||||
7. Search for Arduino-based *X10* or *XBee* libraries. The search query that is
|
||||
described below can be interpreted like ``arduino x10 OR arduino xbee``.
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
$ platformio lib search "+arduino +(x10 xbee)"
|
||||
$ platformio lib search --framework=arduino "+(x10 xbee)"
|
||||
Found 2 libraries:
|
||||
Arduino-X10 Sending X10 signals over AC power lines
|
||||
Arduino-XBee Arduino library for communicating with XBees in API mode
|
||||
|
@ -10,7 +10,7 @@ Usage
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
platformio lib show NAME
|
||||
platformio lib show ID
|
||||
|
||||
|
||||
Description
|
||||
@ -24,11 +24,14 @@ Examples
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
$ platformio lib show Arduino-XBee
|
||||
Arduino-XBee
|
||||
------------
|
||||
Author: Andrew Rapp <andrew.rapp@gmail.com>
|
||||
Keywords: xbee, protocol, radio
|
||||
Version: 0.5
|
||||
# OneWire: http://platformio.ikravets.com/#!/lib/show/1
|
||||
$ platformio lib show 1
|
||||
OneWire
|
||||
-------
|
||||
Authors: Paul Stoffregen http://www.pjrc.com/teensy/td_libs_OneWire.html
|
||||
Keywords: onewire, 1-wire, bus, sensor, temperature, ibutton
|
||||
Frameworks: arduino
|
||||
Platforms: atmelavr
|
||||
Version: 2.2
|
||||
|
||||
Arduino library for communicating with XBees in API mode
|
||||
Control devices (from Dallas Semiconductor) that use the One Wire protocol (DS18S20, DS18B20, DS2408 and etc)
|
||||
|
@ -10,7 +10,7 @@ Usage
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
platformio lib uninstall NAME
|
||||
platformio lib uninstall ID
|
||||
|
||||
|
||||
Description
|
||||
@ -24,8 +24,6 @@ Examples
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
$ platformio lib install Arduino-IRremote
|
||||
Installing Arduino-IRremote library:
|
||||
Downloading [####################################] 100%
|
||||
Unpacking [####################################] 100%
|
||||
The library 'Arduino-IRremote' has been successfully installed!
|
||||
# XBee: http://platformio.ikravets.com/#!/lib/show/6
|
||||
$ platformio lib uninstall 6
|
||||
The library #6 'XBee' has been successfully uninstalled!
|
||||
|
@ -25,9 +25,19 @@ Examples
|
||||
.. code-block:: bash
|
||||
|
||||
$ platformio lib update
|
||||
Updating Arduino-IRremote library:
|
||||
Versions: Current=24ba950f5c, Latest=24ba950f5c [Up-to-date]
|
||||
Updating Arduino-Webduino library:
|
||||
Versions: Current=3631af8e02, Latest=3631af8e02 [Up-to-date]
|
||||
Updating Arduino-XBee library:
|
||||
Versions: Current=0.5, Latest=0.5 [Up-to-date]
|
||||
Updating [ 23 ] Adafruit-L3GD20-Unified library:
|
||||
Versions: Current=63de2eb9ea, Latest=63de2eb9ea [Up-to-date]
|
||||
Updating [ 12 ] Adafruit-ST7735 library:
|
||||
Versions: Current=e880eb1687, Latest=e880eb1687 [Up-to-date]
|
||||
Updating [ 31 ] Adafruit-Unified-Sensor library:
|
||||
Versions: Current=88ae805bce, Latest=88ae805bce [Up-to-date]
|
||||
Updating [ 26 ] Adafruit-LSM303DLHC-Unified library:
|
||||
Versions: Current=59767208a8, Latest=59767208a8 [Up-to-date]
|
||||
Updating [ 13 ] Adafruit-GFX library:
|
||||
Versions: Current=a9e5bc4707, Latest=a9e5bc4707 [Up-to-date]
|
||||
Updating [ 1 ] OneWire library:
|
||||
Versions: Current=2.2, Latest=2.2 [Up-to-date]
|
||||
Updating [ 4 ] IRremote library:
|
||||
Versions: Current=f2dafe5030, Latest=f2dafe5030 [Up-to-date]
|
||||
Updating [ 14 ] Adafruit-9DOF-Unified library:
|
||||
Versions: Current=b2f07242ac, Latest=b2f07242ac [Up-to-date]
|
||||
|
@ -3,11 +3,40 @@
|
||||
|
||||
import click
|
||||
|
||||
from platformio.exception import LibAlreadyInstalledError
|
||||
from platformio.exception import (LibAlreadyInstalledError,
|
||||
LibInstallDependencyError)
|
||||
from platformio.libmanager import LibraryManager
|
||||
from platformio.util import get_api_result, get_lib_dir
|
||||
|
||||
|
||||
LIBLIST_TPL = ("[{id:^14}] {name:<25} {compatibility:<30} "
|
||||
"\"{authornames}\": {description}")
|
||||
|
||||
|
||||
def echo_liblist_header():
|
||||
click.echo(LIBLIST_TPL.format(
|
||||
id=click.style("ID", fg="green"),
|
||||
name=click.style("Name", fg="cyan"),
|
||||
compatibility=click.style("Compatibility", fg="yellow"),
|
||||
authornames="Authors",
|
||||
description="Description"
|
||||
))
|
||||
click.echo("-" * 85)
|
||||
|
||||
|
||||
def echo_liblist_item(item):
|
||||
click.echo(LIBLIST_TPL.format(
|
||||
id=click.style(str(item['id']), fg="green"),
|
||||
name=click.style(item['name'], fg="cyan"),
|
||||
compatibility=click.style(
|
||||
", ".join(item['frameworks'] + item['platforms']),
|
||||
fg="yellow"
|
||||
),
|
||||
authornames=", ".join(item['authornames']),
|
||||
description=item['description']
|
||||
))
|
||||
|
||||
|
||||
@click.group(short_help="Library Manager")
|
||||
def cli():
|
||||
pass
|
||||
@ -16,22 +45,24 @@ def cli():
|
||||
@cli.command("search", short_help="Search for library")
|
||||
@click.option("-a", "--author", multiple=True)
|
||||
@click.option("-k", "--keyword", multiple=True)
|
||||
@click.option("-f", "--framework", multiple=True)
|
||||
@click.option("-p", "--platform", multiple=True)
|
||||
@click.argument("query")
|
||||
def lib_search(query, author, keyword):
|
||||
for key, values in dict(author=author, keyword=keyword).iteritems():
|
||||
def lib_search(query, **filters):
|
||||
for key, values in filters.iteritems():
|
||||
for value in values:
|
||||
query += ' %s:"%s"' % (key, value)
|
||||
|
||||
result = get_api_result("/lib/search", dict(query=query))
|
||||
click.secho("Found %d libraries:" % result['total'],
|
||||
click.secho("Found %d libraries:\n" % result['total'],
|
||||
fg="green" if result['total'] else "yellow")
|
||||
|
||||
if result['total']:
|
||||
echo_liblist_header()
|
||||
|
||||
while True:
|
||||
for item in result['items']:
|
||||
click.echo("{name:<30} {description}".format(
|
||||
name=click.style(item['name'], fg="cyan"),
|
||||
description=item['description']
|
||||
))
|
||||
echo_liblist_item(item)
|
||||
|
||||
if int(result['page'])*int(result['perpage']) >= int(result['total']):
|
||||
break
|
||||
@ -46,91 +77,115 @@ def lib_search(query, author, keyword):
|
||||
|
||||
|
||||
@cli.command("install", short_help="Install library")
|
||||
@click.argument("names", nargs=-1)
|
||||
@click.argument("ids", type=click.INT, nargs=-1, metavar="[LIBRARY_ID]")
|
||||
@click.option("-v", "--version")
|
||||
def lib_install_cli(names, version):
|
||||
lib_install(names, version)
|
||||
def lib_install_cli(ids, version):
|
||||
lib_install(ids, version)
|
||||
|
||||
|
||||
def lib_install(names, version=None):
|
||||
def lib_install(ids, version=None):
|
||||
lm = LibraryManager(get_lib_dir())
|
||||
for name in names:
|
||||
click.echo("Installing %s library:" % click.style(name, fg="cyan"))
|
||||
for id_ in ids:
|
||||
click.echo(
|
||||
"Installing library [ %s ]:" % click.style(str(id_), fg="green"))
|
||||
try:
|
||||
if lm.install(name, version):
|
||||
click.secho(
|
||||
"The library '%s' has been successfully installed!" %
|
||||
name, fg="green")
|
||||
info = lm.get_info(name)
|
||||
if "dependencies" in info:
|
||||
click.secho("Installing dependencies:", fg="yellow")
|
||||
lib_install(info['dependencies'])
|
||||
if not lm.install(id_, version):
|
||||
continue
|
||||
|
||||
info = lm.get_info(id_)
|
||||
click.secho(
|
||||
"The library #%s '%s' has been successfully installed!"
|
||||
% (str(id_), info['name']), fg="green")
|
||||
|
||||
if "dependencies" in info:
|
||||
click.secho("Installing dependencies:", fg="yellow")
|
||||
_dependencies = info['dependencies']
|
||||
if not isinstance(_dependencies, list):
|
||||
_dependencies = [_dependencies]
|
||||
for item in _dependencies:
|
||||
try:
|
||||
lib_install_dependency(item)
|
||||
except AssertionError:
|
||||
raise LibInstallDependencyError(str(item))
|
||||
|
||||
except LibAlreadyInstalledError:
|
||||
click.secho("Already installed", fg="yellow")
|
||||
|
||||
|
||||
def lib_install_dependency(data):
|
||||
assert isinstance(data, dict)
|
||||
query = []
|
||||
for key in data.keys():
|
||||
if key in ("authors", "frameworks", "platforms", "keywords"):
|
||||
values = data[key]
|
||||
if not isinstance(values, list):
|
||||
values = [v.strip() for v in values.split(",") if v]
|
||||
for value in values:
|
||||
query.append('%s:"%s"' % (key[:-1], value))
|
||||
elif isinstance(data[key], basestring):
|
||||
query.append('+"%s"' % data[key])
|
||||
|
||||
result = get_api_result("/lib/search", dict(query=" ".join(query)))
|
||||
assert result['total'] == 1
|
||||
lib_install([result['items'][0]['id']])
|
||||
|
||||
|
||||
@cli.command("uninstall", short_help="Uninstall libraries")
|
||||
@click.argument("names", nargs=-1)
|
||||
def lib_uninstall_cli(names):
|
||||
lib_uninstall(names)
|
||||
@click.argument("ids", type=click.INT, nargs=-1)
|
||||
def lib_uninstall_cli(ids):
|
||||
lib_uninstall(ids)
|
||||
|
||||
|
||||
def lib_uninstall_dependency(dependency):
|
||||
def lib_uninstall(ids):
|
||||
lm = LibraryManager(get_lib_dir())
|
||||
|
||||
for name in lm.get_installed():
|
||||
info = lm.get_info(name)
|
||||
if dependency in info.get("dependencies", []):
|
||||
return
|
||||
|
||||
lib_uninstall([dependency])
|
||||
|
||||
|
||||
def lib_uninstall(names):
|
||||
lm = LibraryManager(get_lib_dir())
|
||||
for name in names:
|
||||
info = lm.get_info(name)
|
||||
if lm.uninstall(name):
|
||||
# find dependencies
|
||||
if "dependencies" in info:
|
||||
for d in info['dependencies']:
|
||||
lib_uninstall_dependency(d)
|
||||
|
||||
click.secho("The library '%s' has been successfully "
|
||||
"uninstalled!" % name, fg="green")
|
||||
for id_ in ids:
|
||||
info = lm.get_info(id_)
|
||||
if lm.uninstall(id_):
|
||||
click.secho("The library #%s '%s' has been successfully "
|
||||
"uninstalled!" % (str(id_), info['name']), fg="green")
|
||||
|
||||
|
||||
@cli.command("list", short_help="List installed libraries")
|
||||
def lib_list():
|
||||
lm = LibraryManager(get_lib_dir())
|
||||
for name in lm.get_installed():
|
||||
info = lm.get_info(name)
|
||||
click.echo("{name:<30} {description}".format(
|
||||
name=click.style(info['name'], fg="cyan"),
|
||||
description=info['description']
|
||||
))
|
||||
items = lm.get_installed().values()
|
||||
if not items:
|
||||
return
|
||||
|
||||
echo_liblist_header()
|
||||
for item in items:
|
||||
item['authornames'] = [i['name'] for i in item['authors']]
|
||||
echo_liblist_item(item)
|
||||
|
||||
|
||||
@cli.command("show", short_help="Show details about installed libraries")
|
||||
@click.argument("name")
|
||||
def lib_show(name):
|
||||
@click.argument("id", type=click.INT)
|
||||
def lib_show(id):
|
||||
lm = LibraryManager(get_lib_dir())
|
||||
info = lm.get_info(name)
|
||||
info = lm.get_info(id)
|
||||
click.secho(info['name'], fg="cyan")
|
||||
click.echo("-" * len(info['name']))
|
||||
|
||||
if "author" in info:
|
||||
_authors = []
|
||||
for author in info['authors']:
|
||||
_data = []
|
||||
for k in ("name", "email"):
|
||||
if k in info['author'] and info['author'][k] is not None:
|
||||
_value = info['author'][k]
|
||||
if k == "email":
|
||||
_value = "<%s>" % _value
|
||||
_data.append(_value)
|
||||
click.echo("Author: %s" % " ".join(_data))
|
||||
for key in ("name", "email", "url", "maintainer"):
|
||||
if not author[key]:
|
||||
continue
|
||||
if key == "email":
|
||||
_data.append("<%s>" % author[key])
|
||||
elif key == "maintainer":
|
||||
_data.append("(maintainer)")
|
||||
else:
|
||||
_data.append(author[key])
|
||||
_authors.append(" ".join(_data))
|
||||
click.echo("Authors: %s" % ", ".join(_authors))
|
||||
|
||||
click.echo("Keywords: %s" % info['keywords'])
|
||||
click.echo("Keywords: %s" % ", ".join(info['keywords']))
|
||||
if "frameworks" in info:
|
||||
click.echo("Frameworks: %s" % ", ".join(info['frameworks']))
|
||||
if "platforms" in info:
|
||||
click.echo("Platforms: %s" % ", ".join(info['platforms']))
|
||||
click.echo("Version: %s" % info['version'])
|
||||
click.echo()
|
||||
click.echo(info['description'])
|
||||
@ -141,18 +196,25 @@ def lib_show(name):
|
||||
def lib_update():
|
||||
lm = LibraryManager(get_lib_dir())
|
||||
|
||||
lib_names = lm.get_installed()
|
||||
if not lib_names:
|
||||
lib_ids = [str(item['id']) for item in lm.get_installed().values()]
|
||||
if not lib_ids:
|
||||
return
|
||||
|
||||
versions = get_api_result("/lib/version/" + ",".join(lib_names))
|
||||
for name in lib_names:
|
||||
info = lm.get_info(name)
|
||||
versions = get_api_result("/lib/version/" + str(",".join(lib_ids)))
|
||||
for id_ in lib_ids:
|
||||
info = lm.get_info(int(id_))
|
||||
|
||||
click.echo("Updating %s library:" % click.style(name, fg="yellow"))
|
||||
click.echo("Updating [ %s ] %s library:" % (
|
||||
click.style(id_, fg="yellow"),
|
||||
click.style(info['name'], fg="cyan"))
|
||||
)
|
||||
|
||||
current_version = info['version']
|
||||
latest_version = versions[name]
|
||||
latest_version = versions[id_]
|
||||
|
||||
if latest_version is None:
|
||||
click.secho("Unknown library", fg="red")
|
||||
continue
|
||||
|
||||
click.echo("Versions: Current=%s, Latest=%s \t " % (
|
||||
current_version, latest_version), nl=False)
|
||||
@ -163,8 +225,8 @@ def lib_update():
|
||||
else:
|
||||
click.echo("[%s]" % (click.style("Out-of-date", fg="red")))
|
||||
|
||||
lib_uninstall([name])
|
||||
lib_install([name])
|
||||
lib_uninstall([int(id_)])
|
||||
lib_install([int(id_)])
|
||||
|
||||
|
||||
@cli.command("register", short_help="Register new library")
|
||||
|
@ -118,4 +118,9 @@ class LibAlreadyInstalledError(PlatformioException):
|
||||
|
||||
class LibNotInstalledError(PlatformioException):
|
||||
|
||||
MESSAGE = "Library '%s' has not been installed yet"
|
||||
MESSAGE = "Library #%d has not been installed yet"
|
||||
|
||||
|
||||
class LibInstallDependencyError(PlatformioException):
|
||||
|
||||
MESSAGE = "Error has been occurred for library dependency '%s'"
|
||||
|
@ -2,7 +2,8 @@
|
||||
# See LICENSE for details.
|
||||
|
||||
import json
|
||||
from os import listdir, makedirs, remove
|
||||
import re
|
||||
from os import listdir, makedirs, remove, rename
|
||||
from os.path import isdir, isfile, join
|
||||
from shutil import rmtree
|
||||
from tempfile import gettempdir
|
||||
@ -15,7 +16,7 @@ from platformio.util import get_api_result
|
||||
|
||||
class LibraryManager(object):
|
||||
|
||||
CONFIG_NAME = "library.json"
|
||||
CONFIG_NAME = ".library.json"
|
||||
|
||||
def __init__(self, lib_dir):
|
||||
self.lib_dir = lib_dir
|
||||
@ -32,45 +33,54 @@ class LibraryManager(object):
|
||||
return fu.start()
|
||||
|
||||
def get_installed(self):
|
||||
items = []
|
||||
items = {}
|
||||
if not isdir(self.lib_dir):
|
||||
return items
|
||||
for item in listdir(self.lib_dir):
|
||||
conf_path = join(self.lib_dir, item, self.CONFIG_NAME)
|
||||
if isfile(conf_path):
|
||||
items.append(item)
|
||||
for dirname in listdir(self.lib_dir):
|
||||
conf_path = join(self.lib_dir, dirname, self.CONFIG_NAME)
|
||||
if not isfile(conf_path):
|
||||
continue
|
||||
with open(conf_path, "r") as f:
|
||||
items[dirname] = json.load(f)
|
||||
return items
|
||||
|
||||
def get_info(self, name):
|
||||
conf_path = join(self.lib_dir, name, self.CONFIG_NAME)
|
||||
if not isfile(conf_path):
|
||||
raise LibNotInstalledError(name)
|
||||
with open(conf_path, "r") as f:
|
||||
return json.load(f)
|
||||
def get_info(self, id_):
|
||||
for item in self.get_installed().values():
|
||||
if "id" in item and item['id'] == id_:
|
||||
return item
|
||||
raise LibNotInstalledError(id_)
|
||||
|
||||
def is_installed(self, name):
|
||||
return isfile(join(self.lib_dir, name, self.CONFIG_NAME))
|
||||
def is_installed(self, id_):
|
||||
try:
|
||||
return int(self.get_info(id_)['id']) == id_
|
||||
except LibNotInstalledError:
|
||||
return False
|
||||
|
||||
def install(self, name, version=None):
|
||||
if self.is_installed(name):
|
||||
def install(self, id_, version=None):
|
||||
if self.is_installed(id_):
|
||||
raise LibAlreadyInstalledError()
|
||||
|
||||
dlinfo = get_api_result("/lib/download/" + name, dict(version=version)
|
||||
if version else None)
|
||||
dlinfo = get_api_result("/lib/download/" + str(id_),
|
||||
dict(version=version) if version else None)
|
||||
dlpath = None
|
||||
tmplib_dir = join(self.lib_dir, str(id_))
|
||||
try:
|
||||
dlpath = self.download(dlinfo['url'], gettempdir())
|
||||
_lib_dir = join(self.lib_dir, name)
|
||||
if not isdir(_lib_dir):
|
||||
makedirs(_lib_dir)
|
||||
self.unpack(dlpath, _lib_dir)
|
||||
if not isdir(tmplib_dir):
|
||||
makedirs(tmplib_dir)
|
||||
self.unpack(dlpath, tmplib_dir)
|
||||
finally:
|
||||
remove(dlpath)
|
||||
if dlpath:
|
||||
remove(dlpath)
|
||||
|
||||
return self.is_installed(name)
|
||||
info = self.get_info(id_)
|
||||
rename(tmplib_dir, join(self.lib_dir, "%s_ID%d" % (
|
||||
re.sub(r"[^\da-z]+", "_", info['name'], flags=re.I), id_)))
|
||||
return True
|
||||
|
||||
def uninstall(self, name):
|
||||
if self.is_installed(name):
|
||||
rmtree(join(self.lib_dir, name))
|
||||
return True
|
||||
else:
|
||||
raise LibNotInstalledError(name)
|
||||
def uninstall(self, id_):
|
||||
for libdir, item in self.get_installed().iteritems():
|
||||
if "id" in item and item['id'] == id_:
|
||||
rmtree(join(self.lib_dir, libdir))
|
||||
return True
|
||||
raise LibNotInstalledError(id_)
|
||||
|
@ -137,7 +137,8 @@ def get_api_result(path, params=None, data=None):
|
||||
else:
|
||||
raise APIRequestError(e)
|
||||
except ConnectionError:
|
||||
raise APIRequestError("Could not connect to PlatformIO API Service")
|
||||
raise APIRequestError(
|
||||
"Could not connect to PlatformIO Registry Service")
|
||||
except ValueError:
|
||||
raise APIRequestError("Invalid response: %s" % r.text)
|
||||
finally:
|
||||
|
Reference in New Issue
Block a user