Skip to content

Commit 3e7e999

Browse files
authored
Merge pull request #66 from tchellomello/dev
Version 1.1.5
2 parents 5daff01 + d319944 commit 3e7e999

File tree

9 files changed

+54
-25
lines changed

9 files changed

+54
-25
lines changed

.travis.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ matrix:
99
env: TOXENV=py35
1010
- python: "3.6"
1111
env: TOXENV=py36
12-
- python: "2.7"
12+
- python: "3.4.2"
1313
env: TOXENV=lint
1414
cache: pip
1515
install: pip install -U tox coveralls

cli/amcrest-cli

+13-10
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,22 @@
1212
#
1313
# vim:sw=4:ts=4:et
1414

15-
try:
16-
# import for Python 2.x
17-
from ConfigParser import ConfigParser, NoOptionError, NoSectionError
18-
except:
19-
# import for Python 3.x
20-
from configparser import ConfigParser, NoOptionError, NoSectionError
15+
# pylint: disable=invalid-name
2116

22-
import argcomplete
23-
import argparse
24-
import getpass
2517
import os
2618
import signal
2719
import sys
2820
import threading
21+
import getpass
22+
import argparse
23+
import argcomplete
24+
25+
try:
26+
# import for Python 2.x
27+
from ConfigParser import ConfigParser, NoOptionError, NoSectionError
28+
except ImportError:
29+
# import for Python 3.x
30+
from configparser import ConfigParser, NoOptionError, NoSectionError
2931

3032
from amcrest import AmcrestCamera
3133

@@ -59,6 +61,7 @@ def main():
5961
formatter_class=argparse.RawTextHelpFormatter
6062
)
6163

64+
# pylint: disable=fixme
6265
# FIXME: Add metavar in the options for better understanding in the
6366
# --help output
6467

@@ -595,7 +598,7 @@ def main():
595598
camera.audio_stream_capture(httptype, channel)
596599

597600
elif args.play_wav:
598-
return(camera.play_wav(path_file=args.play_wav))
601+
return camera.play_wav(path_file=args.play_wav)
599602

600603
elif args.wlan_config:
601604
print((camera.wlan_config))

configure.ac

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
# GNU General Public License for more details.
1111
define([VERSION_MAJOR], [1])
1212
define([VERSION_MINOR], [1])
13-
define([VERSION_FIX], [4])
13+
define([VERSION_FIX], [5])
1414
define([VERSION_NUMBER], VERSION_MAJOR[.]VERSION_MINOR[.]VERSION_FIX)
1515
define([VERSION_SUFFIX], [_master])
1616

python-amcrest.spec.in

+4
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,10 @@ make check-local
165165
%{_sysconfdir}/profile.d/amcrest-cli-autocomplete.sh
166166

167167
%changelog
168+
* Tue Mar 28 2017 Marcelo Moreira de Mello <[email protected]> 1.1-5
169+
- Introduced unittests
170+
- Refactored Python imports
171+
168172
* Tue Jan 31 2017 Marcelo Moreira de Mello <[email protected]> 1.1-4
169173
- Reverted patch 20f527eb which broke external 3rd party applications
170174

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from setuptools import setup, find_packages
33

44
setup(name='amcrest',
5-
version='1.1.4',
5+
version='1.1.5',
66
description='Python wrapper implementation for Amcrest cameras.',
77
author='Douglas Schilling Landgraf, Marcelo Moreira de Mello',
88

src/amcrest/Makefile.am

-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ pycrestdir = $(amcrestpythonlibdir)
2020

2121
pycrest_PYTHON = \
2222
__init__.py \
23-
amcrest.py \
2423
http.py \
2524
config.py \
2625
system.py \

src/amcrest/utils.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def pretty(value, delimiter='='):
3535

3636
def percent(part, whole):
3737
"""Convert data to percent"""
38-
result = 100 * float(part)/float(whole)
38+
result = 100 * float(part) / float(whole)
3939
return float('{:.{prec}f}'.format(result, prec=PRECISION))
4040

4141

tox.ini

+12-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[tox]
2-
envlist = py27, py35, lint
2+
envlist = py27, py35, py36, lint
33
skip_missing_interpreters = True
44

55
[testenv]
@@ -20,4 +20,15 @@ deps =
2020
ignore_errors = True
2121
commands =
2222
flake8
23+
flake8 src/amcrest
24+
flake8 tui/amcrest-tui
25+
flake8 cli/amcrest-cli
26+
2327
pylint src/amcrest
28+
pylint tui/amcrest-tui
29+
pylint cli/amcrest-cli
30+
31+
[flake8]
32+
ignore =
33+
D102,
34+
E121,

tui/amcrest-tui

+21-9
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/usr/bin/env python
2+
"""Amcrest Text User Interface."""
23
# -*- coding: utf-8 -*-
34
#
45
# This program is free software; you can redistribute it and/or modify
@@ -11,6 +12,8 @@
1112
# GNU General Public License for more details.
1213
#
1314
# vim:sw=4:ts=4:et
15+
# pylint: disable=invalid-name
16+
1417
import os
1518
import signal
1619
import subprocess
@@ -20,14 +23,16 @@ import time
2023
try:
2124
# import for Python 2.x
2225
from ConfigParser import ConfigParser, NoOptionError, NoSectionError
23-
except:
26+
except ImportError:
2427
# import for Python 3.x
2528
from configparser import ConfigParser, NoOptionError, NoSectionError
29+
2630
from argparse import ArgumentParser
2731
from amcrest import AmcrestCamera
2832

2933

3034
class AmcrestTuiViewer():
35+
"""Amcrest Text User Interface."""
3136

3237
AMCREST_CONF = "{0}/.config/amcrest.conf".format(os.path.expanduser("~"))
3338

@@ -39,8 +44,10 @@ class AmcrestTuiViewer():
3944
merge_snapshots,
4045
framebuffer_device):
4146
"""
42-
config_file_name - optional amcrest config file
43-
timer_between_snapshots - timer between each snapshot
47+
Define AmcrestTuiViever init method.
48+
49+
Config_file_name - optional amcrest config file
50+
Timer_between_snapshots - timer between each snapshot
4451
"""
4552
if not os.path.exists(self.AMCREST_CONF):
4653
raise RuntimeError(
@@ -57,6 +64,7 @@ class AmcrestTuiViewer():
5764
# Hold fbi pid
5865
self.cmd = None
5966

67+
# pylint: disable=fixme
6068
# FIXME: User might be able to provide config file path
6169
self.config_file_name = config_file_name
6270

@@ -79,18 +87,18 @@ class AmcrestTuiViewer():
7987
try:
8088
self.amcrest_config[camera_name] = {
8189
'hostname': self.config.get(camera_name, 'hostname'),
82-
'port': self.config.get(camera_name, 'port'),
90+
'port': self.config.get(camera_name, 'port'),
8391
'username': self.config.get(camera_name, 'username'),
8492
'password': self.config.get(camera_name, 'password'),
85-
'device': AmcrestCamera(
93+
'device': AmcrestCamera(
8694
host=self.config.get(camera_name, 'hostname'),
8795
port=self.config.get(camera_name, 'port'),
8896
user=self.config.get(camera_name, 'username'),
8997
password=self.config.get(
9098
camera_name, 'password')).camera
9199
}
92100
except (NoSectionError, NoOptionError) as e:
93-
print(("ERROR! %s found at %s" % (e, self.AMCREST_CONF)))
101+
print("ERROR! %s found at %s" % (e, self.AMCREST_CONF))
94102
raise
95103

96104
def _kill_process(self, alarm, stack):
@@ -117,16 +125,19 @@ class AmcrestTuiViewer():
117125
except Exception as e:
118126
raise RuntimeError(e)
119127

128+
# pylint: disable=unused-variable
120129
def run(self):
130+
"""Call run method."""
121131
for counter, camera in enumerate(self.amcrest_config):
122-
with tempfile.NamedTemporaryFile(
123-
dir='/tmp', delete=True) as tmpfile:
132+
with tempfile.NamedTemporaryFile(dir='/tmp',
133+
delete=True) as tmpfile:
124134

135+
# pylint: disable=attribute-defined-outside-init
125136
# Add new tmpfile name
126137
self.dev = self.amcrest_config[camera]['device']
127138

128139
os.system("clear")
129-
print(("Loading new image from: {0}".format(camera)))
140+
print("Loading new image from: {0}".format(camera))
130141
try:
131142
self._snapshot(tmpfile.name)
132143
except RuntimeError as e:
@@ -195,6 +206,7 @@ if __name__ == "__main__":
195206
except Exception:
196207
raise
197208

209+
# pylint: disable=fixme
198210
# FIXME: Add option to save the snapshots in the disk
199211
# (requires to set dir as well)
200212
tui_viewer = AmcrestTuiViewer(

0 commit comments

Comments
 (0)