glances_api 0.1.0__tar.gz → 0.2.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,29 @@
1
+ name: Python package and lint
2
+
3
+ on:
4
+ push:
5
+ branches: [ master ]
6
+ pull_request:
7
+ branches: [ master ]
8
+
9
+ jobs:
10
+ build:
11
+
12
+ runs-on: ubuntu-latest
13
+ strategy:
14
+ matrix:
15
+ python-version: [3.5, 3.6, 3.7, 3.8]
16
+
17
+ steps:
18
+ - uses: actions/checkout@v2
19
+ - name: Set up Python ${{ matrix.python-version }}
20
+ uses: actions/setup-python@v2
21
+ with:
22
+ python-version: ${{ matrix.python-version }}
23
+ - name: Install dependencies
24
+ run: |
25
+ python -m pip install --upgrade pip
26
+ pip install flake8 pytest
27
+ if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
28
+ - name: Black Code Formatter
29
+ uses: lgeiger/black-action@v1.0.1
@@ -0,0 +1,10 @@
1
+ Changes
2
+ =======
3
+
4
+ 20181121 - 0.2.0
5
+ ----------------
6
+ - Support for HTTP Basic authentication
7
+
8
+ 20180814 - 0.1.0
9
+ ----------------
10
+ - Initial release
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2017-2018 Fabian Affolter
3
+ Copyright (c) 2017-2021 Fabian Affolter <fabian@affolter-engineering.ch>
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
@@ -0,0 +1,2 @@
1
+ include LICENSE
2
+ include CHANGES.rst
@@ -1,16 +1,16 @@
1
1
  Metadata-Version: 1.1
2
2
  Name: glances_api
3
- Version: 0.1.0
3
+ Version: 0.2.1
4
4
  Summary: Python API for interacting with Glances.
5
- Home-page: https://github.com/fabaff/python-glances-api
5
+ Home-page: https://github.com/home-assistant-ecosystem/python-glances-api
6
6
  Author: Fabian Affolter
7
7
  Author-email: fabian@affolter-engineering.ch
8
8
  License: MIT
9
- Download-URL: https://github.com/fabaff/python-glances-api/releases
9
+ Download-URL: https://github.com/home-assistant-ecosystem/python-glances-api/releases
10
10
  Description: python-glances-api
11
11
  ==================
12
12
 
13
- Python API for interacting with `Glances <https://nicolargo.github.io/glances/>`_.
13
+ A Python client for interacting with `Glances <https://nicolargo.github.io/glances/>`_.
14
14
 
15
15
  This module is not official, developed, supported or endorsed by Glances.
16
16
 
@@ -23,6 +23,12 @@ Description: python-glances-api
23
23
 
24
24
  $ pip3 install glances_api
25
25
 
26
+ Or on a Fedora-based system or on a CentOS/RHEL machine with has EPEL enabled.
27
+
28
+ .. code:: bash
29
+
30
+ $ sudo dnf -y install python3-glances-api
31
+
26
32
  Usage
27
33
  -----
28
34
 
@@ -35,7 +41,7 @@ Description: python-glances-api
35
41
 
36
42
  .. code:: bash
37
43
 
38
- $ python3.6 -m venv .
44
+ $ python3 -m venv .
39
45
  $ source bin/activate
40
46
  $ python3 setup.py develop
41
47
 
@@ -1,7 +1,7 @@
1
1
  python-glances-api
2
2
  ==================
3
3
 
4
- Python API for interacting with `Glances <https://nicolargo.github.io/glances/>`_.
4
+ A Python client for interacting with `Glances <https://nicolargo.github.io/glances/>`_.
5
5
 
6
6
  This module is not official, developed, supported or endorsed by Glances.
7
7
 
@@ -14,6 +14,12 @@ The module is available from the `Python Package Index <https://pypi.python.org/
14
14
 
15
15
  $ pip3 install glances_api
16
16
 
17
+ Or on a Fedora-based system or on a CentOS/RHEL machine with has EPEL enabled.
18
+
19
+ .. code:: bash
20
+
21
+ $ sudo dnf -y install python3-glances-api
22
+
17
23
  Usage
18
24
  -----
19
25
 
@@ -26,7 +32,7 @@ For development is recommended to use a ``venv``.
26
32
 
27
33
  .. code:: bash
28
34
 
29
- $ python3.6 -m venv .
35
+ $ python3 -m venv .
30
36
  $ source bin/activate
31
37
  $ python3 setup.py develop
32
38
 
@@ -0,0 +1,31 @@
1
+ """Sample script to use the Python API client for Glances."""
2
+ import asyncio
3
+
4
+ import aiohttp
5
+
6
+ from glances_api import Glances
7
+
8
+ HOST = "127.0.0.1"
9
+ VERSION = 3
10
+
11
+
12
+ async def main():
13
+ """The main part of the example script."""
14
+ async with aiohttp.ClientSession() as session:
15
+ data = Glances(loop, session, version=VERSION)
16
+
17
+ # Get the metrics for the memory
18
+ await data.get_metrics("mem")
19
+
20
+ # Print the values
21
+ print("Memory values:", data.values)
22
+
23
+ # Get the metrics about the disks
24
+ await data.get_metrics("diskio")
25
+
26
+ # Print the values
27
+ print("Disk values:", data.values)
28
+
29
+
30
+ loop = asyncio.get_event_loop()
31
+ loop.run_until_complete(main())
@@ -1,8 +1,4 @@
1
- """
2
- Copyright (c) 2017-2018 Fabian Affolter <fabian@affolter-engineering.ch>
3
-
4
- Licensed under MIT. All rights reserved.
5
- """
1
+ """Client to interact with the Glances API."""
6
2
  import asyncio
7
3
  import logging
8
4
 
@@ -12,30 +8,51 @@ import async_timeout
12
8
  from . import exceptions
13
9
 
14
10
  _LOGGER = logging.getLogger(__name__)
15
- _RESOURCE = 'http://{host}:{port}/api/{version}'
11
+ _RESOURCE = "{schema}://{host}:{port}/api/{version}"
16
12
 
17
13
 
18
14
  class Glances(object):
19
15
  """A class for handling the data retrieval."""
20
16
 
21
- def __init__(self, loop, session, host='localhost', port=61208, version=2):
17
+ def __init__(
18
+ self,
19
+ loop,
20
+ session,
21
+ host="localhost",
22
+ port=61208,
23
+ version=2,
24
+ ssl=False,
25
+ username=None,
26
+ password=None,
27
+ ):
22
28
  """Initialize the connection."""
29
+ schema = "https" if ssl else "http"
23
30
  self._loop = loop
24
31
  self._session = session
25
- self.url = _RESOURCE.format(host=host, port=port, version=version)
32
+ self.url = _RESOURCE.format(
33
+ schema=schema, host=host, port=port, version=version
34
+ )
26
35
  self.data = None
27
36
  self.values = None
28
37
  self.plugins = None
38
+ self.username = username
39
+ self.password = password
29
40
 
30
41
  async def get_data(self):
31
42
  """Retrieve the data."""
32
- url = '{}/{}'.format(self.url, 'all')
43
+ url = "{}/{}".format(self.url, "all")
33
44
 
34
45
  try:
35
46
  with async_timeout.timeout(5, loop=self._loop):
36
- response = await self._session.get(url)
47
+ if self.password is None:
48
+ response = await self._session.get(url)
49
+ else:
50
+ auth = aiohttp.BasicAuth(self.username, self.password)
51
+ response = await self._session.get(url, auth=auth)
37
52
 
38
53
  _LOGGER.debug("Response from Glances API: %s", response.status)
54
+ print(response.status)
55
+ print(response.text)
39
56
  self.data = await response.json()
40
57
  _LOGGER.debug(self.data)
41
58
  except (asyncio.TimeoutError, aiohttp.ClientError):
@@ -54,11 +71,15 @@ class Glances(object):
54
71
 
55
72
  async def get_plugins(self):
56
73
  """Retrieve the available plugins."""
57
- url = '{}/{}'.format(self.url, 'pluginslist')
74
+ url = "{}/{}".format(self.url, "pluginslist")
58
75
 
59
76
  try:
60
77
  with async_timeout.timeout(5, loop=self._loop):
61
- response = await self._session.get(url)
78
+ if self.password is None:
79
+ response = await self._session.get(url)
80
+ else:
81
+ auth = aiohttp.BasicAuth(self.username, self.password)
82
+ response = await self._session.get(url, auth=auth)
62
83
 
63
84
  _LOGGER.debug("Response from Glances API: %s", response.status)
64
85
  self.plugins = await response.json()
@@ -1,12 +1,8 @@
1
- """
2
- Copyright (c) 2017-2018 Fabian Affolter <fabian@affolter-engineering.ch>
3
-
4
- Licensed under MIT. All rights reserved.
5
- """
1
+ """Exceptions for the client."""
6
2
 
7
3
 
8
4
  class GlancesApiError(Exception):
9
- """General GlancesApiErrorError exception occurred."""
5
+ """General GlancesApiError exception occurred."""
10
6
 
11
7
  pass
12
8
 
@@ -1,16 +1,16 @@
1
1
  Metadata-Version: 1.1
2
2
  Name: glances-api
3
- Version: 0.1.0
3
+ Version: 0.2.1
4
4
  Summary: Python API for interacting with Glances.
5
- Home-page: https://github.com/fabaff/python-glances-api
5
+ Home-page: https://github.com/home-assistant-ecosystem/python-glances-api
6
6
  Author: Fabian Affolter
7
7
  Author-email: fabian@affolter-engineering.ch
8
8
  License: MIT
9
- Download-URL: https://github.com/fabaff/python-glances-api/releases
9
+ Download-URL: https://github.com/home-assistant-ecosystem/python-glances-api/releases
10
10
  Description: python-glances-api
11
11
  ==================
12
12
 
13
- Python API for interacting with `Glances <https://nicolargo.github.io/glances/>`_.
13
+ A Python client for interacting with `Glances <https://nicolargo.github.io/glances/>`_.
14
14
 
15
15
  This module is not official, developed, supported or endorsed by Glances.
16
16
 
@@ -23,6 +23,12 @@ Description: python-glances-api
23
23
 
24
24
  $ pip3 install glances_api
25
25
 
26
+ Or on a Fedora-based system or on a CentOS/RHEL machine with has EPEL enabled.
27
+
28
+ .. code:: bash
29
+
30
+ $ sudo dnf -y install python3-glances-api
31
+
26
32
  Usage
27
33
  -----
28
34
 
@@ -35,7 +41,7 @@ Description: python-glances-api
35
41
 
36
42
  .. code:: bash
37
43
 
38
- $ python3.6 -m venv .
44
+ $ python3 -m venv .
39
45
  $ source bin/activate
40
46
  $ python3 setup.py develop
41
47
 
@@ -1,7 +1,11 @@
1
+ CHANGES.rst
1
2
  LICENSE
2
3
  MANIFEST.in
3
4
  README.rst
5
+ example.py
6
+ requirements.txt
4
7
  setup.py
8
+ .github/workflows/python-package.yml
5
9
  glances_api/__init__.py
6
10
  glances_api/exceptions.py
7
11
  glances_api.egg-info/PKG-INFO
@@ -0,0 +1,2 @@
1
+ aiohttp<4,>=3.7.4
2
+ async_timeout<4
@@ -0,0 +1,2 @@
1
+ # python-glances-api requirements. Use setup.py for the dependencies.
2
+ .
@@ -0,0 +1,41 @@
1
+ #!/usr/bin/env python3
2
+ """Set up the Python API client for Glances."""
3
+ import os
4
+ import sys
5
+
6
+ try:
7
+ from setuptools import setup
8
+ except ImportError:
9
+ from distutils.core import setup
10
+
11
+ here = os.path.abspath(os.path.dirname(__file__))
12
+
13
+ with open(os.path.join(here, "README.rst"), encoding="utf-8") as readme_file:
14
+ long_description = readme_file.read()
15
+
16
+ setup(
17
+ name="glances_api",
18
+ version="0.2.1",
19
+ description="Python API for interacting with Glances.",
20
+ long_description=long_description,
21
+ url="https://github.com/home-assistant-ecosystem/python-glances-api",
22
+ download_url="https://github.com/home-assistant-ecosystem/python-glances-api/releases",
23
+ author="Fabian Affolter",
24
+ author_email="fabian@affolter-engineering.ch",
25
+ license="MIT",
26
+ install_requires=["aiohttp>=3.7.4,<4", "async_timeout<4"],
27
+ packages=["glances_api"],
28
+ zip_safe=True,
29
+ classifiers=[
30
+ "Development Status :: 3 - Alpha",
31
+ "Environment :: Console",
32
+ "Intended Audience :: Developers",
33
+ "License :: OSI Approved :: MIT License",
34
+ "Operating System :: MacOS :: MacOS X",
35
+ "Operating System :: Microsoft :: Windows",
36
+ "Operating System :: POSIX",
37
+ "Programming Language :: Python :: 3.5",
38
+ "Programming Language :: Python :: 3.6",
39
+ "Topic :: Utilities",
40
+ ],
41
+ )
@@ -1 +0,0 @@
1
- include LICENSE
@@ -1,2 +0,0 @@
1
- aiohttp
2
- async_timeout
@@ -1,49 +0,0 @@
1
- #!/usr/bin/env python3
2
- """
3
- Copyright (c) 2017-2018 Fabian Affolter <fabian@affolter-engineering.ch>
4
-
5
- Licensed under MIT. All rights reserved.
6
- """
7
- import os
8
- import sys
9
-
10
- try:
11
- from setuptools import setup
12
- except ImportError:
13
- from distutils.core import setup
14
-
15
- here = os.path.abspath(os.path.dirname(__file__))
16
-
17
- with open(os.path.join(here, 'README.rst'), encoding='utf-8') as f:
18
- long_description = f.read()
19
-
20
- if sys.argv[-1] == 'publish':
21
- os.system('python3 setup.py sdist upload')
22
- sys.exit()
23
-
24
- setup(
25
- name='glances_api',
26
- version='0.1.0',
27
- description='Python API for interacting with Glances.',
28
- long_description=long_description,
29
- url='https://github.com/fabaff/python-glances-api',
30
- download_url='https://github.com/fabaff/python-glances-api/releases',
31
- author='Fabian Affolter',
32
- author_email='fabian@affolter-engineering.ch',
33
- license='MIT',
34
- install_requires=['aiohttp', 'async_timeout'],
35
- packages=['glances_api'],
36
- zip_safe=True,
37
- classifiers=[
38
- 'Development Status :: 3 - Alpha',
39
- 'Environment :: Console',
40
- 'Intended Audience :: Developers',
41
- 'License :: OSI Approved :: MIT License',
42
- 'Operating System :: MacOS :: MacOS X',
43
- 'Operating System :: Microsoft :: Windows',
44
- 'Operating System :: POSIX',
45
- 'Programming Language :: Python :: 3.5',
46
- 'Programming Language :: Python :: 3.6',
47
- 'Topic :: Utilities',
48
- ],
49
- )
File without changes