From 5200b080c58e701fb90b260dc617b4760992b4a4 Mon Sep 17 00:00:00 2001 From: Marcelo Moreira de Mello Date: Thu, 16 Mar 2017 05:06:04 -0400 Subject: [PATCH] Fixed a few lint problems --- pylintrc | 2 ++ src/amcrest/__init__.py | 2 +- src/amcrest/audio.py | 2 +- src/amcrest/event.py | 2 +- src/amcrest/http.py | 10 +++++----- src/amcrest/log.py | 2 +- src/amcrest/motion_detection.py | 12 ++++++------ src/amcrest/network.py | 32 ++++++++++++++++++-------------- src/amcrest/ptz.py | 4 ++-- src/amcrest/record.py | 5 +++-- src/amcrest/snapshot.py | 2 +- src/amcrest/special.py | 5 +++-- src/amcrest/storage.py | 2 +- src/amcrest/system.py | 6 +++--- src/amcrest/user_management.py | 6 +++--- src/amcrest/utils.py | 2 +- src/amcrest/video.py | 5 ++++- tox.ini | 1 - 18 files changed, 56 insertions(+), 46 deletions(-) diff --git a/pylintrc b/pylintrc index 44efbbf..25bf6bb 100644 --- a/pylintrc +++ b/pylintrc @@ -13,6 +13,7 @@ reports=no # too-many-* - are not enforced for the sake of readability # too-few-* - same as too-many-* # abstract-method - with intro of async there are always methods missing +# missing-docstring, #currently testing travis integration disable= locally-disabled, @@ -22,6 +23,7 @@ disable= abstract-class-not-used, unused-argument, global-statement, + missing-docstring, no-init, no-member, redefined-variable-type, diff --git a/src/amcrest/__init__.py b/src/amcrest/__init__.py index 3d88cc7..46014e8 100644 --- a/src/amcrest/__init__.py +++ b/src/amcrest/__init__.py @@ -11,7 +11,7 @@ # # vim:sw=4:ts=4:et -from .http import Http +from amcrest.http import Http class AmcrestCamera(Http): diff --git a/src/amcrest/audio.py b/src/amcrest/audio.py index 0545e41..2a0037c 100644 --- a/src/amcrest/audio.py +++ b/src/amcrest/audio.py @@ -13,7 +13,7 @@ import shutil -class Audio: +class Audio(object): @property def audio_input_channels_numbers(self): diff --git a/src/amcrest/event.py b/src/amcrest/event.py index 12c9bfd..e07939a 100644 --- a/src/amcrest/event.py +++ b/src/amcrest/event.py @@ -12,7 +12,7 @@ # vim:sw=4:ts=4:et -class Event: +class Event(object): def event_handler_config(self, handlername): ret = self.command( diff --git a/src/amcrest/http.py b/src/amcrest/http.py index cacfbf8..9b719ff 100644 --- a/src/amcrest/http.py +++ b/src/amcrest/http.py @@ -10,8 +10,8 @@ # GNU General Public License for more details. # # vim:sw=4:ts=4:et -import requests import re +import requests from requests.adapters import HTTPAdapter @@ -87,13 +87,13 @@ def command(self, cmd, retries=None, timeout_cmd=None): if retries is not None: self._retries_conn = retries - s = requests.Session() - s.mount('http://', HTTPAdapter(max_retries=self._retries_conn)) - s.mount('https://', HTTPAdapter(max_retries=self._retries_conn)) + session = requests.Session() + session.mount('http://', HTTPAdapter(max_retries=self._retries_conn)) + session.mount('https://', HTTPAdapter(max_retries=self._retries_conn)) url = self.__base_url(cmd) try: - resp = s.get( + resp = session.get( url, auth=self._token, stream=True, diff --git a/src/amcrest/log.py b/src/amcrest/log.py index 4bfc3ad..e204f18 100644 --- a/src/amcrest/log.py +++ b/src/amcrest/log.py @@ -12,7 +12,7 @@ # vim:sw=4:ts=4:et -class Log: +class Log(object): @property def log_clear_all(self): diff --git a/src/amcrest/motion_detection.py b/src/amcrest/motion_detection.py index ccbccdd..b04dbb9 100644 --- a/src/amcrest/motion_detection.py +++ b/src/amcrest/motion_detection.py @@ -10,10 +10,10 @@ # GNU General Public License for more details. # # vim:sw=4:ts=4:et -from .utils import Utils +from amcrest.utils import Utils -class MotionDetection: +class MotionDetection(object): def __get_config(self, config_name): ret = self.command( 'configManager.cgi?action=getConfig&name={0}'.format(config_name) @@ -26,14 +26,14 @@ def motion_detection(self): def is_motion_detector_on(self): ret = self.motion_detection - status = [s for s in ret.split() if '.Enable=' in s][0].split( - '=')[-1] + status = [s for s in ret.split() if '.Enable=' in s][0]\ + .split('=')[-1] return Utils.str2bool(status) def is_record_on_motion_detection(self): ret = self.motion_detection - status = [s for s in ret.split() if '.RecordEnable=' in s][0].split( - '=')[-1] + status = [s for s in ret.split() if '.RecordEnable=' in s][0]\ + .split('=')[-1] return Utils.str2bool(status) @motion_detection.setter diff --git a/src/amcrest/network.py b/src/amcrest/network.py index 148aeac..876e1e9 100644 --- a/src/amcrest/network.py +++ b/src/amcrest/network.py @@ -15,24 +15,26 @@ import threading -class Network: +class Network(object): amcrest_ips = [] __RTSP_PORT = 554 __PWGPSI_PORT = 3800 - def __raw_scan(self, ip, timeout=None): + def __raw_scan(self, ipaddr, timeout=None): # If devices not found, try increasing timeout socket.setdefaulttimeout(0.2) if timeout: socket.setdefaulttimeout(timeout) - with closing(socket.socket()) as sk: + with closing(socket.socket()) as sock: try: - sk.connect((ip, self.__RTSP_PORT)) - sk.connect((ip, self.__PWGPSI_PORT)) - self.amcrest_ips.append(ip) + sock.connect((ipaddr, self.__RTSP_PORT)) + sock.connect((ipaddr, self.__PWGPSI_PORT)) + self.amcrest_ips.append(ipaddr) + + # pylint: disable=bare-except except: pass @@ -80,6 +82,8 @@ def scan_devices(self, subnet, timeout=None): if mask == 16: # For mask 16, we must cut the last two # entries with . + + # pylint: disable=unused-variable for i in range(0, 1): network = network.rpartition(".")[0] @@ -89,18 +93,18 @@ def scan_devices(self, subnet, timeout=None): if mask == 16: for seq1 in range(0, max_range[mask]): for seq2 in range(0, max_range[mask]): - ip = "{0}.{1}.{2}".format(network, seq1, seq2) - t = threading.Thread( - target=self.__raw_scan, args=(ip, timeout) + ipaddr = "{0}.{1}.{2}".format(network, seq1, seq2) + thd = threading.Thread( + target=self.__raw_scan, args=(ipaddr, timeout) ) - t.start() + thd.start() else: for seq1 in range(0, max_range[mask]): - ip = "{0}.{1}".format(network, seq1) - t = threading.Thread( - target=self.__raw_scan, args=(ip, timeout) + ipaddr = "{0}.{1}".format(network, seq1) + thd = threading.Thread( + target=self.__raw_scan, args=(ipaddr, timeout) ) - t.start() + thd.start() return self.amcrest_ips diff --git a/src/amcrest/ptz.py b/src/amcrest/ptz.py index 7f7b952..c2f56b1 100644 --- a/src/amcrest/ptz.py +++ b/src/amcrest/ptz.py @@ -12,7 +12,7 @@ # vim:sw=4:ts=4:et -class Ptz: +class Ptz(object): @property def ptz_config(self): @@ -306,6 +306,6 @@ def move_directly(self, ret = self.command( 'ptzBase.cgi?action=moveDirectly&channel={0}&startPoint[0]={1}' '&startPoint[1]={2}&endPoint[0]={3}&endPoint[1]={4}'.format( - channel, startpoint_x, startpoint_y, endpoint_x, endpoint_y) + channel, startpoint_x, startpoint_y, endpoint_x, endpoint_y) ) return ret.content.decode('utf-8') diff --git a/src/amcrest/record.py b/src/amcrest/record.py index 0b6faf7..d6f7801 100644 --- a/src/amcrest/record.py +++ b/src/amcrest/record.py @@ -12,7 +12,7 @@ # vim:sw=4:ts=4:et -class Record: +class Record(object): @property def record_capability(self): @@ -71,7 +71,6 @@ def record_config(self, rec_opt): =[&=...] """ - print(rec_opt) ret = self.command( 'configManager.cgi?action=setConfig&{0}'.format(rec_opt) ) @@ -98,6 +97,8 @@ def record_mode(self): try: status = int([s for s in ret.content.decode( 'utf-8').split() if 'Mode=' in s][0].split('=')[-1]) + + #pylint: disable=bare-except except: status = None diff --git a/src/amcrest/snapshot.py b/src/amcrest/snapshot.py index d4b5e39..a269faa 100644 --- a/src/amcrest/snapshot.py +++ b/src/amcrest/snapshot.py @@ -13,7 +13,7 @@ import shutil -class Snapshot: +class Snapshot(object): def __get_config(self, config_name): ret = self.command( 'configManager.cgi?action=getConfig&name={0}'.format(config_name) diff --git a/src/amcrest/special.py b/src/amcrest/special.py index 2e72397..51377e3 100644 --- a/src/amcrest/special.py +++ b/src/amcrest/special.py @@ -13,7 +13,7 @@ import shutil -class Special: +class Special(object): def realtime_stream(self, channel=1, typeno=0, path_file=None): """ @@ -34,6 +34,7 @@ def realtime_stream(self, channel=1, typeno=0, path_file=None): return ret.raw + # pylint: disable=pointless-string-statement """ 11/05/2016 @@ -55,8 +56,8 @@ def realtime_stream(self, channel=1, typeno=0, path_file=None): Users complaining here too: https://amcrest.com/forum/technical-discussion-f3/lost-mjpeg-encode-for-main-stream-after-firmware-u-t1516.html - """ + def mjpg_stream(self, channelno=None, typeno=None, path_file=None): """ Params: diff --git a/src/amcrest/storage.py b/src/amcrest/storage.py index 78c856b..ee58e70 100644 --- a/src/amcrest/storage.py +++ b/src/amcrest/storage.py @@ -12,7 +12,7 @@ # vim:sw=4:ts=4:et -class Storage: +class Storage(object): @property def storage_device_info(self): diff --git a/src/amcrest/system.py b/src/amcrest/system.py index ce20293..d8571bb 100644 --- a/src/amcrest/system.py +++ b/src/amcrest/system.py @@ -13,7 +13,7 @@ # vim:sw=4:ts=4:et -class System: +class System(object): """Amcrest system class.""" @property def current_time(self): @@ -124,8 +124,8 @@ def config_backup(self, filename=None): ) if filename: - with open(filename, "w+") as f: - f.write(ret.content.decode('utf-8')) + with open(filename, "w+") as cfg: + cfg.write(ret.content.decode('utf-8')) return return ret.content.decode('utf-8') diff --git a/src/amcrest/user_management.py b/src/amcrest/user_management.py index 2c4f335..5620a30 100644 --- a/src/amcrest/user_management.py +++ b/src/amcrest/user_management.py @@ -12,7 +12,7 @@ # vim:sw=4:ts=4:et -class UserManagement: +class UserManagement(object): def info_user(self, username): ret = self.command( @@ -72,8 +72,8 @@ def add_user(self, username, password, group, sharable=True, cmd = "userManager.cgi?action=addUser&user.Name={0}" \ "&user.Password={1}&user.Group={2}&user.Sharable={3}" \ "&user.Reserved={4}".format( - username, password, group.lower(), sharable.lower(), - reserved.lower()) + username, password, group.lower(), sharable.lower(), + reserved.lower()) if memo: cmd += "&user.Memo=%s" % memo diff --git a/src/amcrest/utils.py b/src/amcrest/utils.py index a742b16..3b8dbdd 100644 --- a/src/amcrest/utils.py +++ b/src/amcrest/utils.py @@ -16,7 +16,7 @@ PRECISION = 2 -class Utils: +class Utils(object): def str2bool(self, value): """ diff --git a/src/amcrest/video.py b/src/amcrest/video.py index 8049d82..91171ee 100644 --- a/src/amcrest/video.py +++ b/src/amcrest/video.py @@ -12,7 +12,7 @@ # vim:sw=4:ts=4:et -class Video: +class Video(object): @property def video_max_extra_stream(self): @@ -62,6 +62,7 @@ def video_channel_title(self): ) return ret.content.decode('utf-8') + # pylint: disable=invalid-name @property def video_input_channels_device_supported(self): ret = self.command( @@ -69,6 +70,7 @@ def video_input_channels_device_supported(self): ) return ret.content.decode('utf-8') + # pylint: disable=invalid-name @property def video_output_channels_device_supported(self): ret = self.command( @@ -76,6 +78,7 @@ def video_output_channels_device_supported(self): ) return ret.content.decode('utf-8') + # pylint: disable=invalid-name @property def video_max_remote_input_channels(self): ret = self.command( diff --git a/tox.ini b/tox.ini index 74d0905..e901936 100644 --- a/tox.ini +++ b/tox.ini @@ -10,7 +10,6 @@ whitelist_externals = /usr/bin/env make install_command = /usr/bin/env LANG=C.UTF-8 pip install {opts} {packages} commands = - ./autogen.sh py.test --verbose --color=auto --duration=0 coverage run --source=src/amcrest setup.py test deps =