Exemplo n.º 1
0
def audacious_watchdog(session):


   from distutils.version import LooseVersion
   reqversion=LooseVersion("1.5")
   version=LooseVersion("0.0")

   logging.debug( "audacious_watchdog: test if audacious is running" )

   try:
      aud=autoaudacious.audacious()

   except:
      logging.error("audacious_watchdog: audacious is not running or error on is_running")
      import subprocess
      try:
         logging.info("audacious_watchdog: try launching audacious")
         subprocess.Popen("audacious" , shell=True)
      except:
         logging.error("audacious_watchdog: error launching audacious")
         try:
            logging.info("audacious_watchdog: try launching audacious2")
            subprocess.Popen("audacious2" , shell=True)
         except:
            logging.error("audacious_watchdog: error launching audacious2")

      import time
      time.sleep(5)
      logging.info("audacious_watchdog: launch_audacious")
      aud=autoaudacious.audacious()

      try:
         aud=autoaudacious.audacious()

      except:
         logging.error("audacious_watchdog: audacious2  not started: try with audacious")
         import subprocess
         subprocess.Popen("audacious" , shell=True)
         import time
         time.sleep(5)
         logging.info("audacious_watchdog: launch_audacious")
         aud=autoaudacious.audacious()

   try:
      # aud.root.Identity()
      version=LooseVersion(aud.org.Version())
      logging.info("audacious_watchdog: audacious version: %s" % str(version))

   except:
      logging.error("audacious_watchdog: eror gettin audacious version")
      return True
   
   if ( version < reqversion ):
      logging.error("audacious_watchdog: audacious %s version is wrong (>=1.5) " % version )
      raise Exception

   aud.play_ifnot()
   logging.debug("audacious_watchdog: audacious start playing if not")

   return True
Exemplo n.º 2
0
def ManageAudacious(session, schedule):
    "Manage audacious to do operation on media"

    try:

        if (schedule.type == "spot"):
            operation = "queueMedia"
        elif (schedule.type == "program"):
            operation = "queueMedia"
        elif (schedule.type == "jingle"):
            operation = "queueMedia"
        elif (schedule.type == "playlist"):
            operation = "loadPlaylist"
        else:
            raise AudaciousError("ManageAudacious: type not supported: %s" %
                                 schedule.type)

        if operation == "loadPlaylist":
            media = shuffle_playlist(schedule.filename,
                                     schedule.shuffle,
                                     relative_path=False,
                                     length=schedule.maxlength)
        else:
            media = schedule.filename

        aud = autoaudacious.audacious()

        # Regione critica
        lock.acquire()
        try:
            if not aud.playlist_clear_up(atlast=10):
                raise AudaciousError(
                    "ManageAudacious: ERROR in playlist_clear_up")

            #print settings.MEDIA_ROOT
            #pos=aud.get_playlist_posauto(autopath=settings.MEDIA_ROOT,securesec=10)

            pos = aud.get_playlist_posauto(autopath="/cacca", securesec=10)

            curpos = aud.get_playlist_pos()

            # inserisco il file nella playlist
            if pos is None:
                raise AudaciousError(
                    "ManageXmms: ERROR in xmms.control.get_playlist_posauto")

            logging.info("ManageXmms: insert media: %s at position %d", media,
                         pos)
            aud.org.PlaylistInsUrlString("file://" + media, pos)

            # recheck for consistency
            newpos = aud.get_playlist_pos()
            if curpos != newpos:
                raise AudaciousError(
                    "Manageaudacious: strange ERROR: consinstency problem; pos: %d , newpos: %d"
                    % (curpos, newpos))

            if not aud.playlist_clear_down(atlast=500):
                raise AudaciousError(
                    "ManageAudacious: ERROR in playlist_clear_down")

        finally:
            #signal.alarm(0)
            lock.release()
            if schedule.shuffle:
                os.remove(media)

        logging.info("ManageAudacious: write in django: %s", schedule.djobj)
        ar_emitted(schedule.djobj)
        logging.info("ManageAudacious: write in django: %s", schedule.djobj)

    except AudaciousError, e:
        logging.error(e)
Exemplo n.º 3
0
def audacious_watchdog(session):

    from distutils.version import LooseVersion
    reqversion = LooseVersion("1.5")
    version = LooseVersion("0.0")

    logging.debug("audacious_watchdog: test if audacious is running")

    try:
        aud = autoaudacious.audacious()

    except:
        logging.error(
            "audacious_watchdog: audacious is not running or error on is_running"
        )
        import subprocess
        try:
            logging.info("audacious_watchdog: try launching audacious")
            subprocess.Popen("audacious", shell=True)
        except:
            logging.error("audacious_watchdog: error launching audacious")
            try:
                logging.info("audacious_watchdog: try launching audacious2")
                subprocess.Popen("audacious2", shell=True)
            except:
                logging.error("audacious_watchdog: error launching audacious2")

        import time
        time.sleep(5)
        logging.info("audacious_watchdog: launch_audacious")
        aud = autoaudacious.audacious()

        try:
            aud = autoaudacious.audacious()

        except:
            logging.error(
                "audacious_watchdog: audacious2  not started: try with audacious"
            )
            import subprocess
            subprocess.Popen("audacious", shell=True)
            import time
            time.sleep(5)
            logging.info("audacious_watchdog: launch_audacious")
            aud = autoaudacious.audacious()

    try:
        # aud.root.Identity()
        version = LooseVersion(aud.org.Version())
        logging.info("audacious_watchdog: audacious version: %s" %
                     str(version))

    except:
        logging.error("audacious_watchdog: eror gettin audacious version")
        return True

    if (version < reqversion):
        logging.error(
            "audacious_watchdog: audacious %s version is wrong (>=1.5) " %
            version)
        raise Exception

    aud.play_ifnot()
    logging.debug("audacious_watchdog: audacious start playing if not")

    return True
Exemplo n.º 4
0
def ManageAudacious (session,schedule):
   "Manage audacious to do operation on media"
    
   try:

      if ( schedule.type == "spot" ): 
         operation="queueMedia"
      elif ( schedule.type == "program" ): 
         operation="queueMedia"
      elif ( schedule.type == "jingle" ):
         operation="queueMedia"
      elif ( schedule.type == "playlist" ):
         operation="loadPlaylist"
      else:
         raise AudaciousError("ManageAudacious: type not supported: %s"% schedule.type)

      if operation == "loadPlaylist":
         media=shuffle_playlist(schedule.filename,schedule.shuffle,relative_path=False,length=schedule.maxlength)
      else:
         media=schedule.filename

      aud=autoaudacious.audacious()

      # Regione critica
      lock.acquire()
      try:
         if not aud.playlist_clear_up(atlast=10):
            raise AudaciousError("ManageAudacious: ERROR in playlist_clear_up")

         #print settings.MEDIA_ROOT
         #pos=aud.get_playlist_posauto(autopath=settings.MEDIA_ROOT,securesec=10)

         pos=aud.get_playlist_posauto(autopath="/cacca",securesec=10)

         curpos=aud.get_playlist_pos()

         # inserisco il file nella playlist
         if pos is None:
            raise AudaciousError("ManageXmms: ERROR in xmms.control.get_playlist_posauto")

         logging.info( "ManageXmms: insert media: %s at position %d",media,pos)
         aud.org.PlaylistInsUrlString("file://"+media,pos)
                
         # recheck for consistency
         newpos=aud.get_playlist_pos()
         if curpos != newpos:
            raise AudaciousError("Manageaudacious: strange ERROR: consinstency problem; pos: %d , newpos: %d"% (curpos,newpos))

         if not aud.playlist_clear_down(atlast=500):
            raise AudaciousError("ManageAudacious: ERROR in playlist_clear_down")

      finally:
         #signal.alarm(0)
         lock.release()
         if schedule.shuffle:
            os.remove(media)

      logging.info( "ManageAudacious: write in django: %s",schedule.djobj)
      ar_emitted(schedule.djobj)
      logging.info( "ManageAudacious: write in django: %s",schedule.djobj)

   except AudaciousError, e:
      logging.error(e)