Skip to content

Commit

Permalink
fix : autopep8
Browse files Browse the repository at this point in the history
  • Loading branch information
sepandhaghighi committed Jan 16, 2024
1 parent f42740e commit eff7e52
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 15 deletions.
30 changes: 17 additions & 13 deletions nava/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from .errors import NavaBaseError
from . import params


def stop(sound_id):
"""
Stop sound.
Expand All @@ -22,6 +23,7 @@ def stop(sound_id):
"""
params._play_threads_map[sound_id].stop()


def stop_all():
"""
Stop all sounds.
Expand All @@ -31,16 +33,18 @@ def stop_all():
for thread in params._play_threads_map.values():
thread.stop()


def sound_id_gen():
"""
Sound id generator.
:return: sound id as int
"""
params._play_threads_counter +=1
params._play_threads_counter += 1
sound_id = params._play_threads_counter + 1000
return sound_id


def nava_help():
"""
Print nava details.
Expand Down Expand Up @@ -75,6 +79,7 @@ def quoter(sound_path, *args, **kwargs):
return func(sound_path, *args, **kwargs)
return quoter


def __play_win(sound_path, async_mode=True):
"""
Play sound in Windows.
Expand Down Expand Up @@ -125,8 +130,8 @@ def __play_linux(sound_path, async_mode=True):
"""
if async_mode:
sound_thread = NavaThread(target=__play_sync_linux,
args=(sound_path,),
daemon=True)
args=(sound_path,),
daemon=True)
sound_thread.start()
sound_id = sound_id_gen()
params._play_threads_map[sound_id] = sound_thread
Expand All @@ -144,15 +149,14 @@ def __play_sync_linux(sound_path):
:return: process
"""
proc = subprocess.Popen(["aplay",
sound_path],
sound_path],
shell=False,
stderr=subprocess.PIPE,
stdin=subprocess.PIPE,
stdout=subprocess.PIPE)
return proc



@quote
def __play_mac(sound_path, async_mode=True):
"""
Expand All @@ -166,8 +170,8 @@ def __play_mac(sound_path, async_mode=True):
"""
if async_mode:
sound_thread = NavaThread(target=__play_sync_mac,
args=(sound_path,),
daemon=True)
args=(sound_path,),
daemon=True)
sound_thread.start()
sound_id = sound_id_gen()
params._play_threads_map[sound_id] = sound_thread
Expand All @@ -185,11 +189,11 @@ def __play_sync_mac(sound_path):
:return: process
"""
proc = subprocess.Popen(["afplay",
sound_path],
shell=False,
stderr=subprocess.PIPE,
stdin=subprocess.PIPE,
stdout=subprocess.PIPE)
sound_path],
shell=False,
stderr=subprocess.PIPE,
stdin=subprocess.PIPE,
stdout=subprocess.PIPE)
return proc


Expand Down Expand Up @@ -240,5 +244,5 @@ def play(sound_path, async_mode=True):
return __play_mac(sound_path, async_mode)
else:
return __play_linux(sound_path, async_mode)
except Exception: # pragma: no cover
except Exception: # pragma: no cover
raise NavaBaseError(SOUND_FILE_PLAY_ERROR)
2 changes: 1 addition & 1 deletion nava/params.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@
SOUND_FILE_PATH_TYPE_ERROR = "Sound file's path should be a string."

_play_threads_map = dict()
_play_threads_counter = 0
_play_threads_counter = 0
3 changes: 2 additions & 1 deletion nava/thread.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class NavaThread(threading.Thread):
"""
Nava custom thread.
"""

def __init__(self, *args, **kwargs):
"""
Init method.
Expand Down Expand Up @@ -43,4 +44,4 @@ def stop(self):
else:
if self.play_process is not None:
self.play_process.kill()
self.play_process.terminate()
self.play_process.terminate()

0 comments on commit eff7e52

Please sign in to comment.