|
45 | 45 | import mmap |
46 | 46 | import ctypes |
47 | 47 | import re |
48 | | -import stat |
49 | 48 | import select |
| 49 | +import shlex |
| 50 | +import stat |
50 | 51 | import time |
51 | 52 | from os.path import abspath |
52 | 53 | from struct import pack, unpack |
53 | | -from subprocess import Popen, check_output |
| 54 | +from subprocess import Popen, check_output, PIPE |
54 | 55 |
|
55 | 56 | try: |
56 | 57 | # This is a linux-specific module. |
@@ -1794,13 +1795,13 @@ def list_sensors(name_pattern=Sensor.SYSTEM_DEVICE_NAME_CONVENTION, **kwargs): |
1794 | 1795 | For example, 'sensor*'. Default value: '*'. |
1795 | 1796 | keyword arguments: used for matching the corresponding device |
1796 | 1797 | attributes. For example, driver_name='lego-ev3-touch', or |
1797 | | - address=['in1', 'in3']. When argument value is a list, |
| 1798 | + address=['in1', 'in3']. When argument value is a list, |
1798 | 1799 | then a match against any entry of the list is enough. |
1799 | 1800 | """ |
1800 | 1801 | class_path = abspath(Device.DEVICE_ROOT_PATH + '/' + Sensor.SYSTEM_CLASS_NAME) |
1801 | | - return (Sensor(name_pattern=name, name_exact=True) |
| 1802 | + return (Sensor(name_pattern=name, name_exact=True) |
1802 | 1803 | for name in list_device_names(class_path, name_pattern, **kwargs)) |
1803 | | - |
| 1804 | + |
1804 | 1805 |
|
1805 | 1806 | # ~autogen generic-class classes.i2cSensor>currentClass |
1806 | 1807 |
|
@@ -3276,7 +3277,7 @@ def beep(args=''): |
3276 | 3277 | .. _`linux beep music`: https://www.google.com/search?q=linux+beep+music |
3277 | 3278 | """ |
3278 | 3279 | with open(os.devnull, 'w') as n: |
3279 | | - return Popen('/usr/bin/beep %s' % args, stdout=n, shell=True) |
| 3280 | + return Popen(shlex.split('/usr/bin/beep %s' % args), stdout=n) |
3280 | 3281 |
|
3281 | 3282 | @staticmethod |
3282 | 3283 | def tone(*args): |
@@ -3340,16 +3341,18 @@ def play(wav_file): |
3340 | 3341 | Play wav file. |
3341 | 3342 | """ |
3342 | 3343 | with open(os.devnull, 'w') as n: |
3343 | | - return Popen('/usr/bin/aplay -q "%s"' % wav_file, stdout=n, shell=True) |
| 3344 | + return Popen(shlex.split('/usr/bin/aplay -q "%s"' % wav_file), stdout=n) |
3344 | 3345 |
|
3345 | 3346 | @staticmethod |
3346 | 3347 | def speak(text, espeak_opts='-a 200 -s 130'): |
3347 | 3348 | """ |
3348 | 3349 | Speak the given text aloud. |
3349 | 3350 | """ |
3350 | 3351 | with open(os.devnull, 'w') as n: |
3351 | | - cmd_line = '/usr/bin/espeak --stdout {0} "{1}" | /usr/bin/aplay -q'.format(espeak_opts, text) |
3352 | | - return Popen(cmd_line, stdout=n, shell=True) |
| 3352 | + cmd_line = '/usr/bin/espeak --stdout {0} "{1}"'.format(espeak_opts, text) |
| 3353 | + espeak = Popen(shlex.split(cmd_line), stdout=PIPE) |
| 3354 | + play = Popen(['/usr/bin/aplay', '-q'], stdin=espeak.stdout, stdout=n) |
| 3355 | + return espeak |
3353 | 3356 |
|
3354 | 3357 | @staticmethod |
3355 | 3358 | def _get_channel(): |
@@ -3387,7 +3390,7 @@ def set_volume(pct, channel=None): |
3387 | 3390 | channel = Sound._get_channel() |
3388 | 3391 |
|
3389 | 3392 | cmd_line = '/usr/bin/amixer -q set {0} {1:d}%'.format(channel, pct) |
3390 | | - Popen(cmd_line, shell=True).wait() |
| 3393 | + Popen(shlex.split(cmd_line)).wait() |
3391 | 3394 |
|
3392 | 3395 | @staticmethod |
3393 | 3396 | def get_volume(channel=None): |
|
0 commit comments