Skip to content

Commit

Permalink
Fixed a few lint problems
Browse files Browse the repository at this point in the history
  • Loading branch information
tchellomello committed Mar 16, 2017
1 parent 0555bdb commit 5200b08
Show file tree
Hide file tree
Showing 18 changed files with 56 additions and 46 deletions.
2 changes: 2 additions & 0 deletions pylintrc
Expand Up @@ -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,
Expand All @@ -22,6 +23,7 @@ disable=
abstract-class-not-used,
unused-argument,
global-statement,
missing-docstring,
no-init,
no-member,
redefined-variable-type,
Expand Down
2 changes: 1 addition & 1 deletion src/amcrest/__init__.py
Expand Up @@ -11,7 +11,7 @@
#
# vim:sw=4:ts=4:et

from .http import Http
from amcrest.http import Http


class AmcrestCamera(Http):
Expand Down
2 changes: 1 addition & 1 deletion src/amcrest/audio.py
Expand Up @@ -13,7 +13,7 @@
import shutil


class Audio:
class Audio(object):

@property
def audio_input_channels_numbers(self):
Expand Down
2 changes: 1 addition & 1 deletion src/amcrest/event.py
Expand Up @@ -12,7 +12,7 @@
# vim:sw=4:ts=4:et


class Event:
class Event(object):

def event_handler_config(self, handlername):
ret = self.command(
Expand Down
10 changes: 5 additions & 5 deletions src/amcrest/http.py
Expand Up @@ -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

Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/amcrest/log.py
Expand Up @@ -12,7 +12,7 @@
# vim:sw=4:ts=4:et


class Log:
class Log(object):

@property
def log_clear_all(self):
Expand Down
12 changes: 6 additions & 6 deletions src/amcrest/motion_detection.py
Expand Up @@ -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)
Expand All @@ -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
Expand Down
32 changes: 18 additions & 14 deletions src/amcrest/network.py
Expand Up @@ -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

Expand Down Expand Up @@ -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]

Expand All @@ -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

Expand Down
4 changes: 2 additions & 2 deletions src/amcrest/ptz.py
Expand Up @@ -12,7 +12,7 @@
# vim:sw=4:ts=4:et


class Ptz:
class Ptz(object):

@property
def ptz_config(self):
Expand Down Expand Up @@ -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')
5 changes: 3 additions & 2 deletions src/amcrest/record.py
Expand Up @@ -12,7 +12,7 @@
# vim:sw=4:ts=4:et


class Record:
class Record(object):

@property
def record_capability(self):
Expand Down Expand Up @@ -71,7 +71,6 @@ def record_config(self, rec_opt):
<paramName>=<paramValue>[&<paramName>=<paramValue>...]
"""

print(rec_opt)
ret = self.command(
'configManager.cgi?action=setConfig&{0}'.format(rec_opt)
)
Expand All @@ -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

Expand Down
2 changes: 1 addition & 1 deletion src/amcrest/snapshot.py
Expand Up @@ -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)
Expand Down
5 changes: 3 additions & 2 deletions src/amcrest/special.py
Expand Up @@ -13,7 +13,7 @@
import shutil


class Special:
class Special(object):

def realtime_stream(self, channel=1, typeno=0, path_file=None):
"""
Expand All @@ -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
Expand All @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion src/amcrest/storage.py
Expand Up @@ -12,7 +12,7 @@
# vim:sw=4:ts=4:et


class Storage:
class Storage(object):

@property
def storage_device_info(self):
Expand Down
6 changes: 3 additions & 3 deletions src/amcrest/system.py
Expand Up @@ -13,7 +13,7 @@
# vim:sw=4:ts=4:et


class System:
class System(object):
"""Amcrest system class."""
@property
def current_time(self):
Expand Down Expand Up @@ -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')
Expand Down
6 changes: 3 additions & 3 deletions src/amcrest/user_management.py
Expand Up @@ -12,7 +12,7 @@
# vim:sw=4:ts=4:et


class UserManagement:
class UserManagement(object):

def info_user(self, username):
ret = self.command(
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/amcrest/utils.py
Expand Up @@ -16,7 +16,7 @@
PRECISION = 2


class Utils:
class Utils(object):

def str2bool(self, value):
"""
Expand Down
5 changes: 4 additions & 1 deletion src/amcrest/video.py
Expand Up @@ -12,7 +12,7 @@
# vim:sw=4:ts=4:et


class Video:
class Video(object):

@property
def video_max_extra_stream(self):
Expand Down Expand Up @@ -62,20 +62,23 @@ 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(
'devVideoInput.cgi?action=getCollect'
)
return ret.content.decode('utf-8')

# pylint: disable=invalid-name
@property
def video_output_channels_device_supported(self):
ret = self.command(
'devVideoOutput.cgi?action=getCollect'
)
return ret.content.decode('utf-8')

# pylint: disable=invalid-name
@property
def video_max_remote_input_channels(self):
ret = self.command(
Expand Down
1 change: 0 additions & 1 deletion tox.ini
Expand Up @@ -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 =
Expand Down

0 comments on commit 5200b08

Please sign in to comment.