Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/dev' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
weblate committed May 28, 2024
2 parents 368edd9 + 91a491b commit fce71ac
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 18 deletions.
6 changes: 4 additions & 2 deletions .github/workflows/python_safety.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,7 @@ jobs:
check-latest: true
- run: pip install --upgrade pip setuptools
- run: pip install safety .
- run: rm -Rfv /opt/hostedtoolcache/Python/3.12.1/x64/lib/python3.12/site-packages/pip-23.2.1.dist-info # Workaround: https://github.com/motioneye-project/motioneye/pull/2883
- run: safety check
# Ignore CVE-2018-20225, which is IMO reasonably disputed: https://data.safetycli.com/v/67599/97c/
# "extra"-index-url means an index to "additionally" look for newer versions, pre-compiled wheels, or similar, not to force this index being used.
# There is "index-url" to enforce a different index: https://pip.pypa.io/en/stable/cli/pip_install/#cmdoption-i
- run: safety check --ignore 67599
4 changes: 2 additions & 2 deletions motioneye/mediafiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ def find_ffmpeg() -> tuple:
output = utils.call_subprocess([quote(binary), '-version'])

except subprocess.CalledProcessError as e:
logging.error(f'ffmpeg: could find version: {e}')
logging.error(f'ffmpeg: could not find version: {e}')
return None, None, None

result = re.findall('ffmpeg version (.+?) ', output, re.IGNORECASE)
Expand Down Expand Up @@ -278,7 +278,7 @@ def find_ffmpeg() -> tuple:

codecs[codec] = {'encoders': encoders, 'decoders': decoders}

logging.debug(f'using ffmpeg version {version}')
logging.debug(f'found ffmpeg executable "{binary}" version "{version}"')

_ffmpeg_binary_cache = (binary, version, codecs)

Expand Down
30 changes: 16 additions & 14 deletions motioneye/motionctl.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import signal
import subprocess
import time
from shlex import quote

from tornado.httpclient import AsyncHTTPClient, HTTPRequest
from tornado.ioloop import IOLoop
Expand All @@ -40,6 +41,7 @@ def find_motion():
if _motion_binary_cache:
return _motion_binary_cache

# binary
if settings.MOTION_BINARY:
if os.path.exists(settings.MOTION_BINARY):
binary = settings.MOTION_BINARY
Expand All @@ -54,16 +56,18 @@ def find_motion():
except subprocess.CalledProcessError: # not found
return None, None

# version
try:
help = utils.call_subprocess(binary + ' -h || true', shell=True)
output = utils.call_subprocess(quote(binary) + ' -h || true', shell=True)

except subprocess.CalledProcessError: # not found
except subprocess.CalledProcessError as e: # not found as
logging.error(f'motion version could not be found: {e}')
return None, None

result = re.findall('motion Version ([^,]+)', help, re.IGNORECASE)
result = re.findall('motion Version ([^,]+)', output, re.IGNORECASE)
version = result and result[0] or ''

logging.debug(f'using motion version {version}')
logging.debug(f'found motion executable "{binary}" version "{version}"')

_motion_binary_cache = (binary, version)

Expand All @@ -85,21 +89,19 @@ def start(deferred=False):
if running() or not enabled_local_motion_cameras:
return

logging.debug('starting motion')
logging.debug('searching motion executable')

program = find_motion()
if not program[0]:
binary, version = find_motion()
if not binary:
raise Exception('motion executable could not be found')

program, version = program # @UnusedVariable

logging.debug(f'starting motion binary "{program}"')
logging.debug(f'starting motion executable "{binary}" version "{version}"')

motion_config_path = os.path.join(settings.CONF_PATH, 'motion.conf')
motion_cfg_path = os.path.join(settings.CONF_PATH, 'motion.conf')
motion_log_path = os.path.join(settings.LOG_PATH, 'motion.log')
motion_pid_path = os.path.join(settings.RUN_PATH, 'motion.pid')

args = [program, '-n', '-c', motion_config_path, '-d']
args = [binary, '-n', '-c', motion_cfg_path, '-d']

if settings.LOG_LEVEL <= logging.DEBUG:
args.append('9')
Expand All @@ -120,11 +122,11 @@ def start(deferred=False):
)

# wait 2 seconds to see that the process has successfully started
for i in range(20): # @UnusedVariable
for _ in range(20):
time.sleep(0.1)
exit_code = process.poll()
if exit_code is not None and exit_code != 0:
raise Exception('motion failed to start')
raise Exception(f'motion failed to start with exit code "{exit_code}"')

pid = process.pid

Expand Down

0 comments on commit fce71ac

Please sign in to comment.