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 (?)
|
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)
|
0.7.1 (2014-10-06)
|
||||||
------------------
|
------------------
|
||||||
|
|
||||||
|
@ -10,13 +10,14 @@ Usage
|
|||||||
|
|
||||||
.. code-block:: bash
|
.. code-block:: bash
|
||||||
|
|
||||||
platformio lib install [OPTIONS] [NAMES]
|
platformio lib install [OPTIONS] [LIBRARY_ID]
|
||||||
|
|
||||||
|
|
||||||
Description
|
Description
|
||||||
-----------
|
-----------
|
||||||
|
|
||||||
Install new library
|
Install new library by specified
|
||||||
|
`PlatformIO Library Registry ID <http://platformio.ikravets.com/#!/lib>`_.
|
||||||
|
|
||||||
Options
|
Options
|
||||||
-------
|
-------
|
||||||
@ -34,35 +35,38 @@ Examples
|
|||||||
|
|
||||||
.. code-block:: bash
|
.. code-block:: bash
|
||||||
|
|
||||||
$ platformio lib install Arduino-IRremote
|
# IRremote: http://platformio.ikravets.com/#!/lib/show/4
|
||||||
Installing Arduino-IRremote library:
|
$ platformio lib install 4
|
||||||
|
Installing library [ 4 ]:
|
||||||
Downloading [####################################] 100%
|
Downloading [####################################] 100%
|
||||||
Unpacking [####################################] 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
|
2. Install specified version of library
|
||||||
|
|
||||||
.. code-block:: bash
|
.. code-block:: bash
|
||||||
|
|
||||||
$ platformio lib install Arduino-XBee --version=0.5
|
# XBee: http://platformio.ikravets.com/#!/lib/show/6
|
||||||
Installing Arduino-XBee library:
|
$ platformio lib install 6 --version=0.5
|
||||||
|
Installing library [ 6 ]:
|
||||||
Downloading [####################################] 100%
|
Downloading [####################################] 100%
|
||||||
Unpacking [####################################] 100%
|
Unpacking [####################################] 100%
|
||||||
The library 'Arduino-XBee' has been successfully installed!
|
The library #6 'XBee' has been successfully installed!
|
||||||
|
|
||||||
|
|
||||||
3. Install library with dependencies
|
3. Install library with dependencies
|
||||||
|
|
||||||
.. code-block:: bash
|
.. code-block:: bash
|
||||||
|
|
||||||
$ platformio lib install Adafruit-Arduino-ST7735
|
# Adafruit-ST7735: http://platformio.ikravets.com/#!/lib/show/12
|
||||||
Installing Adafruit-Arduino-ST7735 library:
|
$ platformio lib install 12
|
||||||
|
Installing library [ 12 ]:
|
||||||
Downloading [####################################] 100%
|
Downloading [####################################] 100%
|
||||||
Unpacking [####################################] 100%
|
Unpacking [####################################] 100%
|
||||||
The library 'Adafruit-Arduino-ST7735' has been successfully installed!
|
The library #12 'Adafruit-ST7735' has been successfully installed!
|
||||||
Installing dependencies:
|
Installing dependencies:
|
||||||
Installing Adafruit-Arduino-GFX library:
|
Installing library [ 13 ]:
|
||||||
Downloading [####################################] 100%
|
Downloading [####################################] 100%
|
||||||
Unpacking [####################################] 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
|
.. code-block:: bash
|
||||||
|
|
||||||
$ platformio lib list
|
$ 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
|
Description
|
||||||
-----------
|
-----------
|
||||||
|
|
||||||
Search for library over ``name``, ``description`` and ``keywords`` fields from
|
Search for library in *PlatformIO Library Registry* by
|
||||||
the :ref:`library_config` file in the boolean mode.
|
:ref:`library_config` fields in the boolean mode.
|
||||||
|
|
||||||
The boolean search capability supports the following operators:
|
The boolean search capability supports the following operators:
|
||||||
|
|
||||||
@ -71,66 +71,119 @@ Filter libraries by specified author
|
|||||||
|
|
||||||
Filter libraries by specified keyword
|
Filter libraries by specified keyword
|
||||||
|
|
||||||
|
|
||||||
|
.. option::
|
||||||
|
-f, --framework
|
||||||
|
|
||||||
|
Filter libraries by specified framework
|
||||||
|
|
||||||
|
|
||||||
|
.. option::
|
||||||
|
-p, --platform
|
||||||
|
|
||||||
|
Filter libraries by specified keyword
|
||||||
|
|
||||||
Examples
|
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
|
.. code-block:: bash
|
||||||
|
|
||||||
$ platformio lib search 1-wire
|
$ platformio lib search 1-wire
|
||||||
Found N libraries:
|
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.
|
operator.
|
||||||
|
|
||||||
.. code-block:: bash
|
.. code-block:: bash
|
||||||
|
|
||||||
$ platformio lib search "+i2c +arduino"
|
$ platformio lib search "+i2c" --framework=arduino
|
||||||
Found N libraries:
|
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.
|
"empty" query argument.
|
||||||
|
|
||||||
.. code-block:: bash
|
.. code-block:: bash
|
||||||
|
|
||||||
$ platformio lib search "" --keyword web --keyword http
|
$ platformio lib search "" --keyword=web --keyword=http
|
||||||
Found N libraries:
|
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
|
.. code-block:: bash
|
||||||
|
|
||||||
$ platformio lib search "" --author "Adafruit Industries"
|
$ platformio lib search "" --author="Adafruit Industries"
|
||||||
Found N libraries:
|
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.
|
like DS18B20, DS18S20 and etc.
|
||||||
|
|
||||||
.. code-block:: bash
|
.. code-block:: bash
|
||||||
|
|
||||||
$ platformio lib search "DS*"
|
$ platformio lib search "DS*"
|
||||||
Found N libraries:
|
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``.
|
described below can be interpreted like ``arduino x10 OR arduino xbee``.
|
||||||
|
|
||||||
.. code-block:: bash
|
.. code-block:: bash
|
||||||
|
|
||||||
$ platformio lib search "+arduino +(x10 xbee)"
|
$ platformio lib search --framework=arduino "+(x10 xbee)"
|
||||||
Found 2 libraries:
|
Found 2 libraries:
|
||||||
Arduino-X10 Sending X10 signals over AC power lines
|
Arduino-X10 Sending X10 signals over AC power lines
|
||||||
Arduino-XBee Arduino library for communicating with XBees in API mode
|
Arduino-XBee Arduino library for communicating with XBees in API mode
|
||||||
|
@ -10,7 +10,7 @@ Usage
|
|||||||
|
|
||||||
.. code-block:: bash
|
.. code-block:: bash
|
||||||
|
|
||||||
platformio lib show NAME
|
platformio lib show ID
|
||||||
|
|
||||||
|
|
||||||
Description
|
Description
|
||||||
@ -24,11 +24,14 @@ Examples
|
|||||||
|
|
||||||
.. code-block:: bash
|
.. code-block:: bash
|
||||||
|
|
||||||
$ platformio lib show Arduino-XBee
|
# OneWire: http://platformio.ikravets.com/#!/lib/show/1
|
||||||
Arduino-XBee
|
$ platformio lib show 1
|
||||||
------------
|
OneWire
|
||||||
Author: Andrew Rapp <andrew.rapp@gmail.com>
|
-------
|
||||||
Keywords: xbee, protocol, radio
|
Authors: Paul Stoffregen http://www.pjrc.com/teensy/td_libs_OneWire.html
|
||||||
Version: 0.5
|
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
|
.. code-block:: bash
|
||||||
|
|
||||||
platformio lib uninstall NAME
|
platformio lib uninstall ID
|
||||||
|
|
||||||
|
|
||||||
Description
|
Description
|
||||||
@ -24,8 +24,6 @@ Examples
|
|||||||
|
|
||||||
.. code-block:: bash
|
.. code-block:: bash
|
||||||
|
|
||||||
$ platformio lib install Arduino-IRremote
|
# XBee: http://platformio.ikravets.com/#!/lib/show/6
|
||||||
Installing Arduino-IRremote library:
|
$ platformio lib uninstall 6
|
||||||
Downloading [####################################] 100%
|
The library #6 'XBee' has been successfully uninstalled!
|
||||||
Unpacking [####################################] 100%
|
|
||||||
The library 'Arduino-IRremote' has been successfully installed!
|
|
||||||
|
@ -25,9 +25,19 @@ Examples
|
|||||||
.. code-block:: bash
|
.. code-block:: bash
|
||||||
|
|
||||||
$ platformio lib update
|
$ platformio lib update
|
||||||
Updating Arduino-IRremote library:
|
Updating [ 23 ] Adafruit-L3GD20-Unified library:
|
||||||
Versions: Current=24ba950f5c, Latest=24ba950f5c [Up-to-date]
|
Versions: Current=63de2eb9ea, Latest=63de2eb9ea [Up-to-date]
|
||||||
Updating Arduino-Webduino library:
|
Updating [ 12 ] Adafruit-ST7735 library:
|
||||||
Versions: Current=3631af8e02, Latest=3631af8e02 [Up-to-date]
|
Versions: Current=e880eb1687, Latest=e880eb1687 [Up-to-date]
|
||||||
Updating Arduino-XBee library:
|
Updating [ 31 ] Adafruit-Unified-Sensor library:
|
||||||
Versions: Current=0.5, Latest=0.5 [Up-to-date]
|
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
|
import click
|
||||||
|
|
||||||
from platformio.exception import LibAlreadyInstalledError
|
from platformio.exception import (LibAlreadyInstalledError,
|
||||||
|
LibInstallDependencyError)
|
||||||
from platformio.libmanager import LibraryManager
|
from platformio.libmanager import LibraryManager
|
||||||
from platformio.util import get_api_result, get_lib_dir
|
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")
|
@click.group(short_help="Library Manager")
|
||||||
def cli():
|
def cli():
|
||||||
pass
|
pass
|
||||||
@ -16,22 +45,24 @@ def cli():
|
|||||||
@cli.command("search", short_help="Search for library")
|
@cli.command("search", short_help="Search for library")
|
||||||
@click.option("-a", "--author", multiple=True)
|
@click.option("-a", "--author", multiple=True)
|
||||||
@click.option("-k", "--keyword", multiple=True)
|
@click.option("-k", "--keyword", multiple=True)
|
||||||
|
@click.option("-f", "--framework", multiple=True)
|
||||||
|
@click.option("-p", "--platform", multiple=True)
|
||||||
@click.argument("query")
|
@click.argument("query")
|
||||||
def lib_search(query, author, keyword):
|
def lib_search(query, **filters):
|
||||||
for key, values in dict(author=author, keyword=keyword).iteritems():
|
for key, values in filters.iteritems():
|
||||||
for value in values:
|
for value in values:
|
||||||
query += ' %s:"%s"' % (key, value)
|
query += ' %s:"%s"' % (key, value)
|
||||||
|
|
||||||
result = get_api_result("/lib/search", dict(query=query))
|
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")
|
fg="green" if result['total'] else "yellow")
|
||||||
|
|
||||||
|
if result['total']:
|
||||||
|
echo_liblist_header()
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
for item in result['items']:
|
for item in result['items']:
|
||||||
click.echo("{name:<30} {description}".format(
|
echo_liblist_item(item)
|
||||||
name=click.style(item['name'], fg="cyan"),
|
|
||||||
description=item['description']
|
|
||||||
))
|
|
||||||
|
|
||||||
if int(result['page'])*int(result['perpage']) >= int(result['total']):
|
if int(result['page'])*int(result['perpage']) >= int(result['total']):
|
||||||
break
|
break
|
||||||
@ -46,91 +77,115 @@ def lib_search(query, author, keyword):
|
|||||||
|
|
||||||
|
|
||||||
@cli.command("install", short_help="Install library")
|
@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")
|
@click.option("-v", "--version")
|
||||||
def lib_install_cli(names, version):
|
def lib_install_cli(ids, version):
|
||||||
lib_install(names, version)
|
lib_install(ids, version)
|
||||||
|
|
||||||
|
|
||||||
def lib_install(names, version=None):
|
def lib_install(ids, version=None):
|
||||||
lm = LibraryManager(get_lib_dir())
|
lm = LibraryManager(get_lib_dir())
|
||||||
for name in names:
|
for id_ in ids:
|
||||||
click.echo("Installing %s library:" % click.style(name, fg="cyan"))
|
click.echo(
|
||||||
|
"Installing library [ %s ]:" % click.style(str(id_), fg="green"))
|
||||||
try:
|
try:
|
||||||
if lm.install(name, version):
|
if not lm.install(id_, version):
|
||||||
click.secho(
|
continue
|
||||||
"The library '%s' has been successfully installed!" %
|
|
||||||
name, fg="green")
|
info = lm.get_info(id_)
|
||||||
info = lm.get_info(name)
|
click.secho(
|
||||||
if "dependencies" in info:
|
"The library #%s '%s' has been successfully installed!"
|
||||||
click.secho("Installing dependencies:", fg="yellow")
|
% (str(id_), info['name']), fg="green")
|
||||||
lib_install(info['dependencies'])
|
|
||||||
|
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:
|
except LibAlreadyInstalledError:
|
||||||
click.secho("Already installed", fg="yellow")
|
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")
|
@cli.command("uninstall", short_help="Uninstall libraries")
|
||||||
@click.argument("names", nargs=-1)
|
@click.argument("ids", type=click.INT, nargs=-1)
|
||||||
def lib_uninstall_cli(names):
|
def lib_uninstall_cli(ids):
|
||||||
lib_uninstall(names)
|
lib_uninstall(ids)
|
||||||
|
|
||||||
|
|
||||||
def lib_uninstall_dependency(dependency):
|
def lib_uninstall(ids):
|
||||||
lm = LibraryManager(get_lib_dir())
|
lm = LibraryManager(get_lib_dir())
|
||||||
|
for id_ in ids:
|
||||||
for name in lm.get_installed():
|
info = lm.get_info(id_)
|
||||||
info = lm.get_info(name)
|
if lm.uninstall(id_):
|
||||||
if dependency in info.get("dependencies", []):
|
click.secho("The library #%s '%s' has been successfully "
|
||||||
return
|
"uninstalled!" % (str(id_), info['name']), fg="green")
|
||||||
|
|
||||||
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")
|
|
||||||
|
|
||||||
|
|
||||||
@cli.command("list", short_help="List installed libraries")
|
@cli.command("list", short_help="List installed libraries")
|
||||||
def lib_list():
|
def lib_list():
|
||||||
lm = LibraryManager(get_lib_dir())
|
lm = LibraryManager(get_lib_dir())
|
||||||
for name in lm.get_installed():
|
items = lm.get_installed().values()
|
||||||
info = lm.get_info(name)
|
if not items:
|
||||||
click.echo("{name:<30} {description}".format(
|
return
|
||||||
name=click.style(info['name'], fg="cyan"),
|
|
||||||
description=info['description']
|
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")
|
@cli.command("show", short_help="Show details about installed libraries")
|
||||||
@click.argument("name")
|
@click.argument("id", type=click.INT)
|
||||||
def lib_show(name):
|
def lib_show(id):
|
||||||
lm = LibraryManager(get_lib_dir())
|
lm = LibraryManager(get_lib_dir())
|
||||||
info = lm.get_info(name)
|
info = lm.get_info(id)
|
||||||
click.secho(info['name'], fg="cyan")
|
click.secho(info['name'], fg="cyan")
|
||||||
click.echo("-" * len(info['name']))
|
click.echo("-" * len(info['name']))
|
||||||
|
|
||||||
if "author" in info:
|
_authors = []
|
||||||
|
for author in info['authors']:
|
||||||
_data = []
|
_data = []
|
||||||
for k in ("name", "email"):
|
for key in ("name", "email", "url", "maintainer"):
|
||||||
if k in info['author'] and info['author'][k] is not None:
|
if not author[key]:
|
||||||
_value = info['author'][k]
|
continue
|
||||||
if k == "email":
|
if key == "email":
|
||||||
_value = "<%s>" % _value
|
_data.append("<%s>" % author[key])
|
||||||
_data.append(_value)
|
elif key == "maintainer":
|
||||||
click.echo("Author: %s" % " ".join(_data))
|
_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("Version: %s" % info['version'])
|
||||||
click.echo()
|
click.echo()
|
||||||
click.echo(info['description'])
|
click.echo(info['description'])
|
||||||
@ -141,18 +196,25 @@ def lib_show(name):
|
|||||||
def lib_update():
|
def lib_update():
|
||||||
lm = LibraryManager(get_lib_dir())
|
lm = LibraryManager(get_lib_dir())
|
||||||
|
|
||||||
lib_names = lm.get_installed()
|
lib_ids = [str(item['id']) for item in lm.get_installed().values()]
|
||||||
if not lib_names:
|
if not lib_ids:
|
||||||
return
|
return
|
||||||
|
|
||||||
versions = get_api_result("/lib/version/" + ",".join(lib_names))
|
versions = get_api_result("/lib/version/" + str(",".join(lib_ids)))
|
||||||
for name in lib_names:
|
for id_ in lib_ids:
|
||||||
info = lm.get_info(name)
|
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']
|
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 " % (
|
click.echo("Versions: Current=%s, Latest=%s \t " % (
|
||||||
current_version, latest_version), nl=False)
|
current_version, latest_version), nl=False)
|
||||||
@ -163,8 +225,8 @@ def lib_update():
|
|||||||
else:
|
else:
|
||||||
click.echo("[%s]" % (click.style("Out-of-date", fg="red")))
|
click.echo("[%s]" % (click.style("Out-of-date", fg="red")))
|
||||||
|
|
||||||
lib_uninstall([name])
|
lib_uninstall([int(id_)])
|
||||||
lib_install([name])
|
lib_install([int(id_)])
|
||||||
|
|
||||||
|
|
||||||
@cli.command("register", short_help="Register new library")
|
@cli.command("register", short_help="Register new library")
|
||||||
|
@ -118,4 +118,9 @@ class LibAlreadyInstalledError(PlatformioException):
|
|||||||
|
|
||||||
class LibNotInstalledError(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.
|
# See LICENSE for details.
|
||||||
|
|
||||||
import json
|
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 os.path import isdir, isfile, join
|
||||||
from shutil import rmtree
|
from shutil import rmtree
|
||||||
from tempfile import gettempdir
|
from tempfile import gettempdir
|
||||||
@ -15,7 +16,7 @@ from platformio.util import get_api_result
|
|||||||
|
|
||||||
class LibraryManager(object):
|
class LibraryManager(object):
|
||||||
|
|
||||||
CONFIG_NAME = "library.json"
|
CONFIG_NAME = ".library.json"
|
||||||
|
|
||||||
def __init__(self, lib_dir):
|
def __init__(self, lib_dir):
|
||||||
self.lib_dir = lib_dir
|
self.lib_dir = lib_dir
|
||||||
@ -32,45 +33,54 @@ class LibraryManager(object):
|
|||||||
return fu.start()
|
return fu.start()
|
||||||
|
|
||||||
def get_installed(self):
|
def get_installed(self):
|
||||||
items = []
|
items = {}
|
||||||
if not isdir(self.lib_dir):
|
if not isdir(self.lib_dir):
|
||||||
return items
|
return items
|
||||||
for item in listdir(self.lib_dir):
|
for dirname in listdir(self.lib_dir):
|
||||||
conf_path = join(self.lib_dir, item, self.CONFIG_NAME)
|
conf_path = join(self.lib_dir, dirname, self.CONFIG_NAME)
|
||||||
if isfile(conf_path):
|
if not isfile(conf_path):
|
||||||
items.append(item)
|
continue
|
||||||
|
with open(conf_path, "r") as f:
|
||||||
|
items[dirname] = json.load(f)
|
||||||
return items
|
return items
|
||||||
|
|
||||||
def get_info(self, name):
|
def get_info(self, id_):
|
||||||
conf_path = join(self.lib_dir, name, self.CONFIG_NAME)
|
for item in self.get_installed().values():
|
||||||
if not isfile(conf_path):
|
if "id" in item and item['id'] == id_:
|
||||||
raise LibNotInstalledError(name)
|
return item
|
||||||
with open(conf_path, "r") as f:
|
raise LibNotInstalledError(id_)
|
||||||
return json.load(f)
|
|
||||||
|
|
||||||
def is_installed(self, name):
|
def is_installed(self, id_):
|
||||||
return isfile(join(self.lib_dir, name, self.CONFIG_NAME))
|
try:
|
||||||
|
return int(self.get_info(id_)['id']) == id_
|
||||||
|
except LibNotInstalledError:
|
||||||
|
return False
|
||||||
|
|
||||||
def install(self, name, version=None):
|
def install(self, id_, version=None):
|
||||||
if self.is_installed(name):
|
if self.is_installed(id_):
|
||||||
raise LibAlreadyInstalledError()
|
raise LibAlreadyInstalledError()
|
||||||
|
|
||||||
dlinfo = get_api_result("/lib/download/" + name, dict(version=version)
|
dlinfo = get_api_result("/lib/download/" + str(id_),
|
||||||
if version else None)
|
dict(version=version) if version else None)
|
||||||
|
dlpath = None
|
||||||
|
tmplib_dir = join(self.lib_dir, str(id_))
|
||||||
try:
|
try:
|
||||||
dlpath = self.download(dlinfo['url'], gettempdir())
|
dlpath = self.download(dlinfo['url'], gettempdir())
|
||||||
_lib_dir = join(self.lib_dir, name)
|
if not isdir(tmplib_dir):
|
||||||
if not isdir(_lib_dir):
|
makedirs(tmplib_dir)
|
||||||
makedirs(_lib_dir)
|
self.unpack(dlpath, tmplib_dir)
|
||||||
self.unpack(dlpath, _lib_dir)
|
|
||||||
finally:
|
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):
|
def uninstall(self, id_):
|
||||||
if self.is_installed(name):
|
for libdir, item in self.get_installed().iteritems():
|
||||||
rmtree(join(self.lib_dir, name))
|
if "id" in item and item['id'] == id_:
|
||||||
return True
|
rmtree(join(self.lib_dir, libdir))
|
||||||
else:
|
return True
|
||||||
raise LibNotInstalledError(name)
|
raise LibNotInstalledError(id_)
|
||||||
|
@ -137,7 +137,8 @@ def get_api_result(path, params=None, data=None):
|
|||||||
else:
|
else:
|
||||||
raise APIRequestError(e)
|
raise APIRequestError(e)
|
||||||
except ConnectionError:
|
except ConnectionError:
|
||||||
raise APIRequestError("Could not connect to PlatformIO API Service")
|
raise APIRequestError(
|
||||||
|
"Could not connect to PlatformIO Registry Service")
|
||||||
except ValueError:
|
except ValueError:
|
||||||
raise APIRequestError("Invalid response: %s" % r.text)
|
raise APIRequestError("Invalid response: %s" % r.text)
|
||||||
finally:
|
finally:
|
||||||
|
Reference in New Issue
Block a user