Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
0d993cc
add syno system data and actions
mib1185 Oct 4, 2020
1041b76
add system usage examples
mib1185 Oct 4, 2020
9e91ec0
add upgrade information
mib1185 Oct 4, 2020
ce8c2c4
Fix default login Exception (#73)
Quentame Oct 14, 2020
212f029
Migrate to Python 3.6+ (#70)
Quentame Oct 14, 2020
5244a49
correct alphabetically order
mib1185 Oct 16, 2020
1892770
add SynoCoreUpgrade instance
mib1185 Oct 16, 2020
97bc931
simplify update_available()
mib1185 Oct 16, 2020
5b63dfd
correct defaults of .get()
mib1185 Oct 16, 2020
abcb8f1
harmonize use of API_KEY
mib1185 Oct 16, 2020
bdfd8c8
update docs
mib1185 Oct 16, 2020
3c94ef3
add test data
mib1185 Oct 16, 2020
fbc2810
due to #70
mib1185 Oct 16, 2020
4e190d4
update docs
mib1185 Oct 16, 2020
34bf335
solve conflict
mib1185 Oct 16, 2020
d4c006c
add syno system data and actions
mib1185 Oct 4, 2020
b61e90d
add system usage examples
mib1185 Oct 4, 2020
8d6bef6
add upgrade information
mib1185 Oct 4, 2020
609bc32
correct alphabetically order
mib1185 Oct 16, 2020
2a3e609
add SynoCoreUpgrade instance
mib1185 Oct 16, 2020
13a63fa
simplify update_available()
mib1185 Oct 16, 2020
b878050
correct defaults of .get()
mib1185 Oct 16, 2020
aa217cf
harmonize use of API_KEY
mib1185 Oct 16, 2020
907e74c
update docs
mib1185 Oct 16, 2020
17016a9
add test data
mib1185 Oct 16, 2020
f9c8819
due to #70
mib1185 Oct 16, 2020
5d58f17
update docs
mib1185 Oct 16, 2020
c8775b7
Merge branch 'master' of https://github.com/mib1185/python-synology
mib1185 Oct 16, 2020
c6b337c
Apply suggestions from code review: function return type
Quentame Oct 18, 2020
81bafb1
Don't save previous update data
Quentame Oct 18, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ dist: xenial

language: python
python:
- 2.7
- 3.4
- 3.6
- 3.7
- 3.8
cache:
pip: true
Expand All @@ -17,7 +17,7 @@ install:
- python setup.py sdist
before_script:
- pylint synology_dsm tests
- ./scripts/check_format.sh
- black --check --fast .
script:
- py.test

Expand Down
60 changes: 60 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,66 @@ Surveillance Station usage
surveillance.set_home_mode(True)


System usage
--------------------------

.. code-block:: python

from synology_dsm import SynologyDSM

api = SynologyDSM("<IP/DNS>", "<port>", "<username>", "<password>")
system = api.system

# Reboot NAS
system.reboot()

# Shutdown NAS
system.shutdown()

# Manual update system information
system.update()

# Get CPU information
system.cpu_clock_speed
system.cpu_cores
system.cpu_family
system.cpu_series

# Get NTP settings
system.enabled_ntp
system.ntp_server

# Get system information
system.firmware_ver
system.model
system.ram_size
system.serial
system.sys_temp
system.time
system.time_zone
system.time_zone_desc
system.up_time

# Get list of all connected USB devices
system.usb_dev


Upgrade usage
--------------------------

.. code-block:: python

from synology_dsm import SynologyDSM

api = SynologyDSM("<IP/DNS>", "<port>", "<username>", "<password>")
upgrade = api.upgrade

# Manual update upgrade information
upgrade.update()

# check if DSM update is available
if upgrade.update_available:
do something ...

Credits / Special Thanks
========================
Expand Down
8 changes: 3 additions & 5 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
requests>=2.20.0
urllib3>=1.24.3,<1.25
six>=1.14.0
future>=0.18.2
simplejson>=3.16.0
requests>=2.24.0
# Constrain urllib3 to ensure we deal with CVE-2019-11236 & CVE-2019-11324
urllib3>=1.24.3
3 changes: 2 additions & 1 deletion requirements_test.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
pytest
pylint>=1.9.5,<=2.4.4
pylint>=2.6.0
pylint-strict-informational==0.1
black==20.8b1
16 changes: 0 additions & 16 deletions scripts/check_format.sh

This file was deleted.

14 changes: 7 additions & 7 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""Synology DSM setup."""

# NOTE(ProtoThis) Guidelines for Major.Minor.Micro
# - Major means an API contract change
# - Minor means API bugfix or new functionality
# - Micro means change of any kind (unless significant enough for a minor/major).

from setuptools import setup, find_packages
from codecs import open

REPO_URL = "https://github.com/ProtoThis/python-synology"
VERSION = "0.9.0"
Expand All @@ -25,23 +24,24 @@
download_url=REPO_URL + "/tarball/" + VERSION,
description="Python API for communication with Synology DSM",
long_description=long_description,
author="FG van Zeelst (ProtoThis)",
author="Quentin POLLET (Quentame) & FG van Zeelst (ProtoThis)",
packages=find_packages(include=["synology_dsm*"]),
install_requires=required,
python_requires=">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*",
python_requires=">=3.6",
license="MIT",
classifiers=[
"Development Status :: 5 - Production/Stable",
"Intended Audience :: Developers",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
"Programming Language :: Python",
"Programming Language :: Python :: 2.7",
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.4",
"Programming Language :: Python :: 3.5",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Topic :: Software Development :: Libraries",
],
keywords=["synology-dsm", "synology"],
)
3 changes: 1 addition & 2 deletions synology_dsm/api/core/security.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# -*- coding: utf-8 -*-
"""DSM Security data."""


class SynoCoreSecurity(object):
class SynoCoreSecurity:
"""Class containing Security data."""

API_KEY = "SYNO.Core.SecurityScan.Status"
Expand Down
3 changes: 1 addition & 2 deletions synology_dsm/api/core/share.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
# -*- coding: utf-8 -*-
"""Shared Folders data."""
from synology_dsm.helpers import SynoFormatHelper


class SynoCoreShare(object):
class SynoCoreShare:
"""Class containing Share data."""

API_KEY = "SYNO.Core.Share"
Expand Down
117 changes: 117 additions & 0 deletions synology_dsm/api/core/system.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
"""DSM System data and actions."""


class SynoCoreSystem:
"""Class containing System data and actions."""

API_KEY = "SYNO.Core.System"

def __init__(self, dsm):
self._dsm = dsm
self._data = {}

def update(self):
"""Updates System data."""
raw_data = self._dsm.get(self.API_KEY, "info")
if raw_data:
self._data = raw_data["data"]

### get information
@property
def cpu_clock_speed(self):
"""Gets System CPU clock speed."""
return self._data.get('cpu_clock_speed')

@property
def cpu_cores(self):
"""Gets System CPU cores."""
return self._data.get('cpu_cores')

@property
def cpu_family(self):
"""Gets System CPU family."""
return self._data.get('cpu_family')

@property
def cpu_series(self):
"""Gets System CPU series."""
return self._data.get('cpu_series')

@property
def enabled_ntp(self):
"""Gets System NTP state."""
return self._data.get('enabled_ntp')

@property
def ntp_server(self):
"""Gets System NTP server."""
return self._data.get('ntp_server')

@property
def firmware_ver(self):
"""Gets System firmware version."""
return self._data.get('firmware_ver')

@property
def model(self):
"""Gets System model."""
return self._data.get('model')

@property
def ram_size(self):
"""Gets System ram size."""
return self._data.get('ram_size')

@property
def serial(self):
"""Gets System serial number."""
return self._data.get('serial')

@property
def sys_temp(self):
"""Gets System temperature."""
return self._data.get('sys_temp')

@property
def time(self):
"""Gets System time."""
return self._data.get('time')

@property
def time_zone(self):
"""Gets System time zone."""
return self._data.get('time_zone')

@property
def time_zone_desc(self):
"""Gets System time zone description."""
return self._data.get('time_zone_desc')

@property
def up_time(self):
"""Gets System uptime."""
return self._data.get('up_time')

@property
def usb_dev(self):
"""Gets System connected usb devices."""
return self._data.get('usb_dev', [])

### do system actions
def shutdown(self):
"""Shutdown NAS."""
res = self._dsm.get(
self.API_KEY,
"shutdown",
max_version=1, # shutdown method is only available on api version 1
)
return res

def reboot(self):
"""Reboot NAS."""
res = self._dsm.get(
self.API_KEY,
"reboot",
max_version=1, # reboot method is only available on api version 1
)
return res
23 changes: 23 additions & 0 deletions synology_dsm/api/core/upgrade.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
"""DSM Upgrade data and actions."""


class SynoCoreUpgrade:
"""Class containing upgrade data and actions."""

API_KEY = "SYNO.Core.Upgrade"
API_SERVER_KEY = API_KEY + ".Server"

def __init__(self, dsm):
self._dsm = dsm
self._data = {}

def update(self):
"""Updates Upgrade data."""
raw_data = self._dsm.get(self.API_SERVER_KEY, "check")
if raw_data:
self._data = raw_data["data"]

@property
def update_available(self):
"""Gets all Upgrade info."""
return self._data["update"].get("available")
3 changes: 1 addition & 2 deletions synology_dsm/api/core/utilization.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
# -*- coding: utf-8 -*-
"""DSM Utilization data."""
from synology_dsm.helpers import SynoFormatHelper


class SynoCoreUtilization(object):
class SynoCoreUtilization:
"""Class containing Utilization data."""

API_KEY = "SYNO.Core.System.Utilization"
Expand Down
2 changes: 1 addition & 1 deletion synology_dsm/api/download_station/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from .task import SynoDownloadTask


class SynoDownloadStation(object):
class SynoDownloadStation:
"""An implementation of a Synology DownloadStation."""

API_KEY = "SYNO.DownloadStation.*"
Expand Down
2 changes: 1 addition & 1 deletion synology_dsm/api/download_station/task.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""DownloadStation task."""


class SynoDownloadTask(object):
class SynoDownloadTask:
"""An representation of a Synology DownloadStation task."""

def __init__(self, data):
Expand Down
3 changes: 1 addition & 2 deletions synology_dsm/api/dsm/information.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# -*- coding: utf-8 -*-
"""DSM Information data."""


class SynoDSMInformation(object):
class SynoDSMInformation:
"""Class containing Information data."""

API_KEY = "SYNO.DSM.Info"
Expand Down
3 changes: 1 addition & 2 deletions synology_dsm/api/dsm/network.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# -*- coding: utf-8 -*-
"""DSM Network data."""


class SynoDSMNetwork(object):
class SynoDSMNetwork:
"""Class containing Network data."""

API_KEY = "SYNO.DSM.Network"
Expand Down
4 changes: 1 addition & 3 deletions synology_dsm/api/storage/storage.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
# -*- coding: utf-8 -*-
"""DSM Storage data."""
from __future__ import division

from synology_dsm.helpers import SynoFormatHelper


class SynoStorage(object):
class SynoStorage:
"""Class containing Storage data."""

API_KEY = "SYNO.Storage.CGI.Storage"
Expand Down
Loading