コード例 #1
0
 def run_card_test(card_id):
     try:
         # - - - -
         utils = sb6utils.sb6Utils()
         proc_name = f"{card_id}_test"
         for p in psutil.process_iter():
             if p.name() == proc_name:
                 msg = f"Process Exists: {proc_name}"
                 utils.new_error_file(card_id, msg)
                 print(fr"proc exists; kill it first!: {proc_name}")
                 sys.exit(1001)
         # - - - -
         setproctitle.setproctitle(proc_name)
         utils = sb6utils.sb6Utils()
         testPID = os.getpid()
         state = utils.new_state_object("OrderCallerTester", card_id,
                                        "test", testPID)
         utils.new_state_file(card_id, state)
         # - - - -
         os.putenv("AUDIODEV", f"hw:{card_id}")
         for num in range(1, 100):
             mp3_path = f"mp3s/nums/num{num}.mp3"
             os.system(f"play -q {mp3_path}")
             state["lastOrderCalled"] = mp3_path
             state["lastTestCallUtcDts"] = utils.utc_now()
             utils.new_state_file(card_id, state)
             time.sleep(1.0)
         # - - - -
     except Exception as ex:
         print(ex)
コード例 #2
0
 def play_fld_proc(card_id: str, fld: str):
     try:
         setproctitle.setproctitle(f"{card_id}_ply_fld")
         utils = sb6utils.sb6Utils()
         path = f"{defs.MUSIC_ROOT}/{fld}"
         # -- do ---
         # mp3s in the folder
         mp3s = os.listdir(path)
         # set sound card for play cmd process
         os.putenv("AUDIODEV", f"hw:{card_id}")
         # - - - -
         sb6sPID = os.getpid()
         state = utils.new_state_object("FolderPlayer", card_id, "sb6s",
                                        sb6sPID)
         state["playingFolder"] = fld
         # - - - -
         while True:
             rid = random.randrange(0, len(mp3s), 1)
             track = f"{path}/{mp3s[rid]}"
             # update state json file
             state["playingTrack"] = track
             state["updateUtcDts"] = utils.utc_now()
             play = sp.Popen(["play", "-q", track])
             state["playPID"] = play.pid
             utils.new_state_file(card_id, state)
             ref_play = psutil.Process(play.pid)
             # wait on play
             while ref_play.status() != "zombie":
                 time.sleep(0.66)
             play.kill()
             time.sleep(1.0)
     except Exception as ex:
         print(ex)
コード例 #3
0
 def update_cards_config(self, jsonBuff):
     try:
         # - - - -
         utils = sb6utils.sb6Utils()
         utils.save_snd_cards_conf(jsonBuff)
         self.update_cards_volume(jsonBuff)
         # - - - -
         return "OK"
     except Exception as ex:
         print(ex)
         return "ERR"
コード例 #4
0
 def stop_card_test(card_id):
     try:
         print(f"stop_card_test ~ card_id: {card_id}")
         utils = sb6utils.sb6Utils()
         state = utils.get_state_object(card_id)
         # get testPID from state object
         if "testPID" in state:
             test_pid = state["testPID"]
             utils.kill_pid(test_pid)
         else:
             # return "testPID not found in state object"
             pass
     except Exception as ex:
         print(ex)
コード例 #5
0
 def kill_folder_play(card_id):
     try:
         utils = sb6utils.sb6Utils()
         buff = utils.get_state_file(card_id)
         if buff.startswith("NO_STATE_FILE"):
             return buff
         # - - - -
         jobj = json.loads(buff)
         utils.kill_pid(int(jobj["playPID"]))
         utils.kill_pid(int(jobj["sb6sPID"]))
         utils.rm_state_file(card_id)
         # - - - -
         return "OK"
     except Exception as ex:
         print(ex)
コード例 #6
0
 def get_snd_crd_state(card_id):
     try:
         state_file = f"{defs.RUNTIME_FLD}/{card_id}_state.json"
         if not os.path.exists(state_file):
             return f"STATE_FILE_NOT_FOUND: {state_file}"
         utils = sb6utils.sb6Utils()
         state = utils.get_state_object(card_id)
         # - - - -
         if "playPID" in state:
             utils.update_state_pid_info(state, "play")
         # - - - -
         if "sb6sPID" in state:
             utils.update_state_pid_info(state, "sb6s")
         # - - - -
         if "testPID" in state:
             utils.update_state_pid_info(state, "test")
         # - - - -
         return json.dumps(state)
     except Exception as e:
         return f"ERROR: {str(e)}"