From: Calin Crisan Date: Wed, 18 May 2016 20:17:43 +0000 (+0300) Subject: use utils.DEV_NULL everywhere instead of opening a new /dev/null fd each X-Git-Url: http://www.vanbest.org/gitweb/?a=commitdiff_plain;h=5d0ae88ef29ab952645a4e3f969da46f5250bd4e;p=motioneye-debian use utils.DEV_NULL everywhere instead of opening a new /dev/null fd each time --- diff --git a/motioneye/diskctl.py b/motioneye/diskctl.py index aba8f7b..8691474 100644 --- a/motioneye/diskctl.py +++ b/motioneye/diskctl.py @@ -19,6 +19,7 @@ import logging import os import re import subprocess +import utils def _list_mounts(): @@ -150,7 +151,7 @@ def _list_disks_dev_by_id(): def _list_disks_fdisk(): try: - output = subprocess.check_output(['fdisk', '-l'], stderr=open('/dev/null', 'w')) + output = subprocess.check_output(['fdisk', '-l'], stderr=utils.DEV_NULL) except Exception as e: logging.error('failed to list disks using "fdisk -l": %s' % e, exc_info=True) diff --git a/motioneye/mediafiles.py b/motioneye/mediafiles.py index 6f2684f..28cb1a0 100644 --- a/motioneye/mediafiles.py +++ b/motioneye/mediafiles.py @@ -154,7 +154,7 @@ def _remove_older_files(dir, moment, exts): def find_ffmpeg(): try: - return subprocess.check_output(['which', 'ffmpeg'], stderr=open('/dev/null', 'w')).strip() + return subprocess.check_output(['which', 'ffmpeg'], stderr=utils.DEV_NULL).strip() except subprocess.CalledProcessError: # not found return None diff --git a/motioneye/motionctl.py b/motioneye/motionctl.py index 0ed7f5c..2950770 100644 --- a/motioneye/motionctl.py +++ b/motioneye/motionctl.py @@ -51,7 +51,7 @@ def find_motion(): else: # autodetect motion binary path try: - binary = subprocess.check_output(['which', 'motion'], stderr=open('/dev/null', 'w')).strip() + binary = subprocess.check_output(['which', 'motion'], stderr=utils.DEV_NULL).strip() except subprocess.CalledProcessError: # not found return None diff --git a/motioneye/powerctl.py b/motioneye/powerctl.py index 403cb49..4171fbd 100644 --- a/motioneye/powerctl.py +++ b/motioneye/powerctl.py @@ -18,11 +18,12 @@ import logging import os import subprocess +import utils def _find_prog(prog): try: - return subprocess.check_output(['which', prog], stderr=open('/dev/null', 'w')).strip() + return subprocess.check_output(['which', prog], stderr=utils.DEV_NULL).strip() except subprocess.CalledProcessError: # not found return None diff --git a/motioneye/smbctl.py b/motioneye/smbctl.py index 4281378..668f7d1 100644 --- a/motioneye/smbctl.py +++ b/motioneye/smbctl.py @@ -21,6 +21,7 @@ import os import re import subprocess import time +import utils from tornado.ioloop import IOLoop @@ -39,7 +40,7 @@ def stop(): def find_mount_cifs(): try: - return subprocess.check_output(['which', 'mount.cifs'], stderr=open('/dev/null', 'w')).strip() + return subprocess.check_output(['which', 'mount.cifs'], stderr=utils.DEV_NULL).strip() except subprocess.CalledProcessError: # not found return None diff --git a/motioneye/utils.py b/motioneye/utils.py index 212379f..bb7b995 100644 --- a/motioneye/utils.py +++ b/motioneye/utils.py @@ -43,6 +43,8 @@ except: _SIGNATURE_REGEX = re.compile('[^a-zA-Z0-9/?_.=&{}\[\]":, _-]') _SPECIAL_COOKIE_NAMES = {'expires', 'domain', 'path', 'secure', 'httponly'} +DEV_NULL = open('/dev/null', 'w') + COMMON_RESOLUTIONS = [ (320, 240), diff --git a/motioneye/v4l2ctl.py b/motioneye/v4l2ctl.py index 77bb33f..3e97de5 100644 --- a/motioneye/v4l2ctl.py +++ b/motioneye/v4l2ctl.py @@ -35,7 +35,7 @@ _DEV_V4L_BY_ID = '/dev/v4l/by-id/' def find_v4l2_ctl(): try: - return subprocess.check_output(['which', 'v4l2-ctl'], stderr=open('/dev/null', 'w')).strip() + return subprocess.check_output(['which', 'v4l2-ctl'], stderr=utils.DEV_NULL).strip() except subprocess.CalledProcessError: # not found return None