From 6ab5ac45821105687708581fc47fa27bebf03ceb Mon Sep 17 00:00:00 2001 From: martin Date: Wed, 1 Jun 2011 12:32:42 -0400 Subject: [PATCH] cc-2055: switch to init.d -allow install script to be created from any location (no hardcoded paths) -make python install scripts return 1 on error -daemon now started automatically on boot using rc.local autostart -change all prints to logs instead -create airtime-uninstall shell script (and remove pypo user in here) -create pypo user in shell script --- install/airtime-install | 29 ++++--- install/airtime-install.php | 4 +- install/airtime-uninstall | 27 ++++++ install/airtime-uninstall.php | 20 +---- python_apps/api_clients/api_client.py | 84 ++++++++----------- python_apps/create_pypo_user.py | 29 +++++++ python_apps/media-monitor/MediaMonitor.py | 3 +- .../install/media-monitor-install.py | 36 ++------ .../install/media-monitor-uninstall.py | 13 +-- python_apps/pypo/install/pypo-install.py | 37 ++------ python_apps/pypo/install/pypo-uninstall.py | 13 +-- python_apps/pypo/pypo-cli.py | 24 +++--- python_apps/pypo/pypofetch.py | 9 +- python_apps/pypo/pypopush.py | 1 + python_apps/pypo/util/cue_file.py | 2 - python_apps/remove_pypo_user.py | 14 ++++ .../show-recorder/install/recorder-install.py | 34 ++------ .../install/recorder-uninstall.py | 13 +-- python_apps/show-recorder/recorder.py | 3 +- utils/airtime-check-system | 2 +- utils/airtime-clean-storage | 2 +- utils/airtime-import | 2 +- utils/airtime-update-db-settings | 2 +- 23 files changed, 179 insertions(+), 224 deletions(-) create mode 100755 install/airtime-uninstall create mode 100644 python_apps/create_pypo_user.py create mode 100644 python_apps/remove_pypo_user.py diff --git a/install/airtime-install b/install/airtime-install index 6e90a16c9..f83510f90 100755 --- a/install/airtime-install +++ b/install/airtime-install @@ -4,20 +4,29 @@ #return with a non-zero return value. set -e -echo -e "\n******************************** Install Begin *********************************"; +# Absolute path to this script +SCRIPT=`readlink -f $0` +# Absolute directory this script is in +SCRIPTPATH=`dirname $SCRIPT` -php airtime-install.php $@ +echo -e "\n******************************** Install Begin *********************************" -echo "*** Pypo Installation ***" -#python ".__DIR__."/../python_apps/pypo/install/pypo-install.py -python ../python_apps/pypo/install/pypo-install.py +php ${SCRIPTPATH}/airtime-install.php $@ + +echo -e "\n*** Creating Pypo User ***" +python ${SCRIPTPATH}/../python_apps/create-pypo-user.py + +echo -e "\n*** Pypo Installation ***" +python ${SCRIPTPATH}/../python_apps/pypo/install/pypo-install.py + +#echo -e "\n*** Recorder Installation ***" +#python ${SCRIPTPATH}/../python_apps/show-recorder/install/recorder-install.py + +#echo -e "\n*** Media Monitor Installation ***" +#python ${SCRIPTPATH}/../python_apps/pytag-fs/install/media-monitor-install.py -#echo "*** Recorder Installation ***" -#python ".__DIR__."/../python_apps/show-recorder/install/recorder-install.py -#python ../python_apps/show-recorder/install/recorder-install.py sleep 4 - airtime-check-system -echo -e "\n******************************* Install Complete *******************************"; +echo -e "\n******************************* Install Complete *******************************" diff --git a/install/airtime-install.php b/install/airtime-install.php index 68d0ee916..2e32090d5 100644 --- a/install/airtime-install.php +++ b/install/airtime-install.php @@ -123,7 +123,5 @@ AirtimeInstall::CreateSymlinksToUtils(); AirtimeInstall::CreateZendPhpLogFile(); -//wait for 1.9.0 release -//echo PHP_EOL."*** Media Monitor Installation ***".PHP_EOL; -//system("python ".__DIR__."/../python_apps/pytag-fs/install/media-monitor-install.py"); +/* FINISHED AIRTIME PHP INSTALLER */ diff --git a/install/airtime-uninstall b/install/airtime-uninstall new file mode 100755 index 000000000..6445a9965 --- /dev/null +++ b/install/airtime-uninstall @@ -0,0 +1,27 @@ +#!/bin/bash + +# Absolute path to this script +SCRIPT=`readlink -f $0` +# Absolute directory this script is in +SCRIPTPATH=`dirname $SCRIPT` + +echo -e "\n******************************* Uninstall Begin ********************************" + +php ${SCRIPTPATH}/airtime-uninstall.php + +echo -e "\n*** Uninstalling Pypo ***" +python ${SCRIPTPATH}/../python_apps/pypo/install/pypo-uninstall.py + +#echo -e "\n*** Uninstalling Show Recorder ***" +#python ${SCRIPTPATH}/../python_apps/show-recorder/install/recorder-uninstall.py + +#echo -e "\n*** Uninstalling Media Monitor ***" +#python ${SCRIPTPATH}/../python_apps/pytag-fs/install/media-monitor-uninstall.py + +echo -e "\n*** Removing Pypo User ***" +python ${SCRIPTPATH}/../python_apps/remove-pypo-user.py + +echo -e "\n****************************** Uninstall Complete ******************************\n" +echo "NOTE: To fully remove all Airtime files, you will also have to manually delete" +echo " the directories '/srv/airtime'(default storage location of media files)" +echo -e " and '/etc/airtime'(where the config files are stored).\n" diff --git a/install/airtime-uninstall.php b/install/airtime-uninstall.php index 851ca8ce3..d1489d893 100644 --- a/install/airtime-uninstall.php +++ b/install/airtime-uninstall.php @@ -19,7 +19,6 @@ require_once(AirtimeInstall::GetAirtimeSrcDir().'/application/configs/constants. require_once(AirtimeInstall::GetAirtimeSrcDir().'/application/configs/conf.php'); echo PHP_EOL; -echo "******************************* Uninstall Begin ********************************".PHP_EOL; echo "* Uninstalling Airtime ".AIRTIME_VERSION.PHP_EOL; AirtimeInstall::UninstallPhpCode(); @@ -81,18 +80,7 @@ if ($results == 0) { # Disabled as this should be a manual process #AirtimeInstall::DeleteFilesRecursive(AirtimeInstall::CONF_DIR_STORAGE); -echo PHP_EOL."*** Uninstalling Pypo ***".PHP_EOL; -$command = "python ".__DIR__."/../python_apps/pypo/install/pypo-uninstall.py"; -system($command); -echo PHP_EOL."*** Uninstalling Show Recorder ***".PHP_EOL; -$command = "python ".__DIR__."/../python_apps/show-recorder/install/recorder-uninstall.py"; -system($command); - -//wait for 1.9.0 release -//echo PHP_EOL."*** Uninstalling Media Monitor ***".PHP_EOL; -//$command = "python ".__DIR__."/../python_apps/pytag-fs/install/media-monitor-uninstall.py"; -//system($command); #Disabled as this should be a manual process #AirtimeIni::RemoveIniFiles(); @@ -101,10 +89,4 @@ AirtimeInstall::RemoveSymlinks(); AirtimeInstall::UninstallBinaries(); AirtimeInstall::RemoveLogDirectories(); -echo PHP_EOL; -echo "****************************** Uninstall Complete ******************************".PHP_EOL; -echo PHP_EOL; -echo "NOTE: To fully remove all Airtime files, you will also have to manually delete".PHP_EOL; -echo " the directories '".AirtimeInstall::CONF_DIR_STORAGE."'(where the media files are stored)".PHP_EOL; -echo " and '/etc/airtime'(where the config files are stored).".PHP_EOL; -echo PHP_EOL; +/* FINISHED AIRTIME PHP UNINSTALLER */ diff --git a/python_apps/api_clients/api_client.py b/python_apps/api_clients/api_client.py index 0dcd423c7..9ab038ffc 100644 --- a/python_apps/api_clients/api_client.py +++ b/python_apps/api_clients/api_client.py @@ -22,13 +22,13 @@ from urlparse import urlparse AIRTIME_VERSION = "1.9.0-devel" def api_client_factory(config): + logger = logging.getLogger() if config["api_client"] == "airtime": return AirTimeApiClient(config) elif config["api_client"] == "obp": return ObpApiClient(config) else: - print 'API Client "'+config["api_client"]+'" not supported. Please check your config file.' - print + logger.info('API Client "'+config["api_client"]+'" not supported. Please check your config file.\n') sys.exit() def recursive_urlencode(d): @@ -155,18 +155,18 @@ class AirTimeApiClient(ApiClientInterface): except Exception, e: if e[1] == 401: if (verbose): - print '#####################################' - print '# YOUR API KEY SEEMS TO BE INVALID:' - print '# ' + self.config["api_key"] - print '#####################################' + logger.info('#####################################') + logger.info('# YOUR API KEY SEEMS TO BE INVALID:') + logger.info('# ' + self.config["api_key"]) + logger.info('#####################################') return -1 if e[1] == 404: if (verbose): - print '#####################################' - print '# Unable to contact the Airtime-API' - print '# ' + url - print '#####################################' + logger.info('#####################################') + logger.info('# Unable to contact the Airtime-API') + logger.info('# ' + url) + logger.info('#####################################') return -1 logger.error("Unable to detect Airtime Version - %s, Response: %s", e, response) @@ -190,23 +190,21 @@ class AirTimeApiClient(ApiClientInterface): def is_server_compatible(self, verbose = True): + logger = logging.getLogger() version = self.__get_airtime_version(verbose) if (version == -1): if (verbose): - print 'Unable to get Airtime version number.' - print + logger.info('Unable to get Airtime version number.\n') return False elif (version[0:3] != AIRTIME_VERSION[0:3]): if (verbose): - print 'Airtime version found: ' + str(version) - print 'pypo is at version ' +AIRTIME_VERSION+' and is not compatible with this version of Airtime.' - print + logger.info('Airtime version found: ' + str(version)) + logger.info('pypo is at version ' +AIRTIME_VERSION+' and is not compatible with this version of Airtime.\n') return False else: if (verbose): - print 'Airtime version: ' + str(version) - print 'pypo is at version ' +AIRTIME_VERSION+' and is compatible with this version of Airtime.' - print + logger.info('Airtime version: ' + str(version)) + logger.info('pypo is at version ' +AIRTIME_VERSION+' and is compatible with this version of Airtime.') return True @@ -226,7 +224,7 @@ class AirTimeApiClient(ApiClientInterface): response = json.loads(response_json) status = response['check'] except Exception, e: - print e + logger.error(e) return status, response @@ -393,29 +391,25 @@ class ObpApiClient(): self.api_auth = urllib.urlencode({'api_key': self.config["api_key"]}) def is_server_compatible(self, verbose = True): + logger = logging.getLogger() obp_version = self.get_obp_version() if obp_version == 0: if (verbose): - print '#################################################' - print 'Unable to get OBP version. Is OBP up and running?' - print '#################################################' - print + logger.error('Unable to get OBP version. Is OBP up and running?\n') return False elif obp_version < OBP_MIN_VERSION: if (verbose): - print 'OBP version: ' + str(obp_version) - print 'OBP min-version: ' + str(OBP_MIN_VERSION) - print 'pypo not compatible with this version of OBP' - print + logger.warn('OBP version: ' + str(obp_version)) + logger.warn('OBP min-version: ' + str(OBP_MIN_VERSION)) + logger.warn('pypo not compatible with this version of OBP\n') return False else: if (verbose): - print 'OBP API: ' + str(API_BASE) - print 'OBP version: ' + str(obp_version) - print 'OBP min-version: ' + str(OBP_MIN_VERSION) - print 'pypo is compatible with this version of OBP' - print + logger.warn('OBP API: ' + str(API_BASE)) + logger.warn('OBP version: ' + str(obp_version)) + logger.warn('OBP min-version: ' + str(OBP_MIN_VERSION)) + logger.warn('pypo is compatible with this version of OBP\n') return True @@ -437,10 +431,10 @@ class ObpApiClient(): except Exception, e: try: if e[1] == 401: - print '#####################################' - print '# YOUR API KEY SEEMS TO BE INVALID' - print '# ' + self.config["api_auth"] - print '#####################################' + logger.error('#####################################') + logger.error('# YOUR API KEY SEEMS TO BE INVALID') + logger.error('# ' + self.config["api_auth"]) + logger.error('#####################################') sys.exit() except Exception, e: @@ -448,10 +442,10 @@ class ObpApiClient(): try: if e[1] == 404: - print '#####################################' - print '# Unable to contact the OBP-API' - print '# ' + url - print '#####################################' + logger.error('#####################################') + logger.error('# Unable to contact the OBP-API') + logger.error('# ' + url) + logger.error('#####################################') sys.exit() except Exception, e: @@ -502,15 +496,14 @@ class ObpApiClient(): logger.info("export status %s", response['check']) status = response['check'] except Exception, e: - print e + logger.error(e) return status, response def get_media(self, src, dest): try: - print '** urllib auth with: ', - print self.api_auth + logger.info('** urllib auth with: ' + self.api_auth) urllib.urlretrieve(src, dst, False, self.api_auth) logger.info("downloaded %s to %s", src, dst) except Exception, e: @@ -535,7 +528,6 @@ class ObpApiClient(): logger.info("API-Message %s", response['message']) except Exception, e: - print e api_status = False logger.error("Unable to connect to the OBP API - %s", e) @@ -561,7 +553,7 @@ class ObpApiClient(): url = url.replace("%%media_id%%", str(media_id)) url = url.replace("%%playlist_id%%", str(playlist_id)) url = url.replace("%%transmission_id%%", str(transmission_id)) - print url + logger.info(url) try: response = urllib.urlopen(url, self.api_auth) @@ -571,7 +563,6 @@ class ObpApiClient(): logger.info("TXT %s", response['str_dls']) except Exception, e: - print e api_status = False logger.error("Unable to connect to the OBP API - %s", e) @@ -592,7 +583,6 @@ class ObpApiClient(): logger.info("API-Message %s", response['message']) except Exception, e: - print e api_status = False logger.error("Unable to handle the OBP API request - %s", e) diff --git a/python_apps/create_pypo_user.py b/python_apps/create_pypo_user.py new file mode 100644 index 000000000..bdaf98442 --- /dev/null +++ b/python_apps/create_pypo_user.py @@ -0,0 +1,29 @@ +import os +from subprocess import Popen, PIPE, STDOUT + +def create_user(username): + print "Checking for user "+username + + p = Popen('id '+username, shell=True, stdin=PIPE, stdout=PIPE, stderr=STDOUT, close_fds=True) + output = p.stdout.read() + + if (output[0:3] != "uid"): + # Make the pypo user + print "Creating user "+username + os.system("adduser --system --quiet --group --shell /bin/bash "+username) + + #set pypo password + p = os.popen('/usr/bin/passwd pypo 1>/dev/null 2>&1', 'w') + p.write('pypo\n') + p.write('pypo\n') + p.close() + else: + print "User already exists." + #add pypo to audio group + os.system("adduser " + username + " audio 1>/dev/null 2>&1") + #add pypo to www-data group + os.system("adduser " + username + " www-data 1>/dev/null 2>&1") + + +if __name__ == "__main__": + create_user("pypo") diff --git a/python_apps/media-monitor/MediaMonitor.py b/python_apps/media-monitor/MediaMonitor.py index 38423fcc9..48d4e2035 100644 --- a/python_apps/media-monitor/MediaMonitor.py +++ b/python_apps/media-monitor/MediaMonitor.py @@ -33,7 +33,8 @@ except Exception, e: try: config = ConfigObj('/etc/airtime/MediaMonitor.cfg') except Exception, e: - print 'Error loading config file: ', e + logger = logging.getLogger(); + logger.error('Error loading config file: %s', e) sys.exit() """ diff --git a/python_apps/media-monitor/install/media-monitor-install.py b/python_apps/media-monitor/install/media-monitor-install.py index 2d6bdb542..1f94e792f 100755 --- a/python_apps/media-monitor/install/media-monitor-install.py +++ b/python_apps/media-monitor/install/media-monitor-install.py @@ -14,7 +14,7 @@ import shutil import string import platform from configobj import ConfigObj -from subprocess import Popen, PIPE, STDOUT +from subprocess import Popen if os.geteuid() != 0: print "Please run this as root." @@ -27,27 +27,6 @@ def create_path(path): print "Creating directory " + path os.makedirs(path) -def create_user(username): - print "Checking for user "+username - p = Popen('id '+username, shell=True, stdin=PIPE, stdout=PIPE, stderr=STDOUT, close_fds=True) - output = p.stdout.read() - if (output[0:3] != "uid"): - # Make the pypo user - print "Creating user "+username - os.system("adduser --system --quiet --group --shell /bin/bash "+username) - - #set pypo password - p = os.popen('/usr/bin/passwd pypo 1>/dev/null 2>&1', 'w') - p.write('pypo\n') - p.write('pypo\n') - p.close() - else: - print "User already exists." - #add pypo to audio group - os.system("adduser " + username + " audio 1>/dev/null 2>&1") - #add pypo to www-data group - os.system("adduser " + username + " www-data 1>/dev/null 2>&1") - def copy_dir(src_dir, dest_dir): if (os.path.exists(dest_dir)) and (dest_dir != "/"): print "Removing old directory "+dest_dir @@ -59,7 +38,6 @@ def copy_dir(src_dir, dest_dir): def get_current_script_dir(): current_script_dir = os.path.realpath(__file__) index = current_script_dir.rindex('/') - #print current_script_dir[0:index] return current_script_dir[0:index] @@ -69,18 +47,13 @@ try: config = ConfigObj(PATH_INI_FILE) except Exception, e: print 'Error loading config file: ', e - sys.exit() + sys.exit(1) current_script_dir = get_current_script_dir() - #print "Checking and removing any existing media monitor processes" - #os.system("python %s/media-monitor-uninstall.py 1>/dev/null 2>&1"% current_script_dir) - #time.sleep(5) + p = Popen("/etc/init.d/airtime-media-monitor stop", shell=True) sts = os.waitpid(p.pid, 0)[1] - # Create users - create_user("pypo") - print "Creating log directories" create_path(config["log_dir"]) os.system("chmod -R 755 " + config["log_dir"]) @@ -98,6 +71,9 @@ try: print "Installing media-monitor daemon" shutil.copy(config["bin_dir"]+"/airtime-media-monitor-init-d", "/etc/init.d/airtime-media-monitor") + + p = Popen("update-rc.d airtime-media-monitor defaults", shell=True) + sts = os.waitpid(p.pid, 0)[1] print "Waiting for processes to start..." p = Popen("/etc/init.d/airtime-media-monitor start", shell=True) diff --git a/python_apps/media-monitor/install/media-monitor-uninstall.py b/python_apps/media-monitor/install/media-monitor-uninstall.py index 2f90364d8..bc1fb8d4e 100755 --- a/python_apps/media-monitor/install/media-monitor-uninstall.py +++ b/python_apps/media-monitor/install/media-monitor-uninstall.py @@ -15,15 +15,6 @@ PATH_INI_FILE = '/etc/airtime/MediaMonitor.cfg' def remove_path(path): os.system("rm -rf " + path) -def remove_user(username): - os.system("killall -u %s 1>/dev/null 2>&1" % username) - - #allow all process to be completely closed before we attempt to delete user - print "Waiting for processes to close..." - time.sleep(5) - - os.system("deluser --remove-home " + username + " 1>/dev/null 2>&1") - def get_current_script_dir(): current_script_dir = os.path.realpath(__file__) index = current_script_dir.rindex('/') @@ -35,9 +26,10 @@ try: config = ConfigObj(PATH_INI_FILE) except Exception, e: print 'Error loading config file: ', e - sys.exit() + sys.exit(1) os.system("/etc/init.d/airtime-media-monitor stop") + os.system("rm -f /etc/init.d/airtime-media-monitor") print "Removing log directories" remove_path(config["log_dir"]) @@ -48,7 +40,6 @@ try: print "Removing application files" remove_path(config["bin_dir"]) - remove_user("pypo") print "Uninstall complete." except Exception, e: print "exception:" + str(e) diff --git a/python_apps/pypo/install/pypo-install.py b/python_apps/pypo/install/pypo-install.py index c6b625fd7..a84479b6e 100755 --- a/python_apps/pypo/install/pypo-install.py +++ b/python_apps/pypo/install/pypo-install.py @@ -14,7 +14,7 @@ import shutil import string import platform from configobj import ConfigObj -from subprocess import Popen, PIPE, STDOUT +from subprocess import Popen if os.geteuid() != 0: print "Please run this as root." @@ -29,27 +29,6 @@ def create_path(path): else: print "Directory already exists " + path -def create_user(username): - print "Checking for user "+username - p = Popen('id '+username, shell=True, stdin=PIPE, stdout=PIPE, stderr=STDOUT, close_fds=True) - output = p.stdout.read() - if (output[0:3] != "uid"): - # Make the pypo user - print "Creating user "+username - os.system("adduser --system --quiet --group --shell /bin/bash "+username) - - #set pypo password - p = os.popen('/usr/bin/passwd pypo 1>/dev/null 2>&1', 'w') - p.write('pypo\n') - p.write('pypo\n') - p.close() - else: - print "User already exists." - #add pypo to audio group - os.system("adduser " + username + " audio 1>/dev/null 2>&1") - #add pypo to pulse-access group - #os.system("adduser " + username + " pulse-access 1>/dev/null 2>&1") - def copy_dir(src_dir, dest_dir): if (os.path.exists(dest_dir)) and (dest_dir != "/"): #print "Removing old directory "+dest_dir @@ -61,7 +40,6 @@ def copy_dir(src_dir, dest_dir): def get_current_script_dir(): current_script_dir = os.path.realpath(__file__) index = current_script_dir.rindex('/') - #print current_script_dir[0:index] return current_script_dir[0:index] def is_natty(): @@ -86,18 +64,13 @@ try: config = ConfigObj(PATH_INI_FILE) except Exception, e: print 'Error loading config file: ', e - sys.exit() + sys.exit(1) current_script_dir = get_current_script_dir() - #print "Checking and removing any existing pypo processes" - #os.system("python %s/pypo-uninstall.py 1>/dev/null 2>&1"% current_script_dir) - #time.sleep(5) + p = Popen("/etc/init.d/airtime-playout stop", shell=True) sts = os.waitpid(p.pid, 0)[1] - # Create users - create_user("pypo") - create_path(config["pypo_log_dir"]) os.system("chmod -R 755 " + config["pypo_log_dir"]) os.system("chown -R pypo:pypo "+config["pypo_log_dir"]) @@ -148,9 +121,13 @@ try: print "Installing pypo daemon" shutil.copy(config["bin_dir"]+"/bin/airtime-playout-init-d", "/etc/init.d/airtime-playout") + p = Popen("update-rc.d airtime-playout defaults", shell=True) + sts = os.waitpid(p.pid, 0)[1] + print "Waiting for processes to start..." p = Popen("/etc/init.d/airtime-playout start", shell=True) sts = os.waitpid(p.pid, 0)[1] + except Exception, e: print "exception:" + str(e) diff --git a/python_apps/pypo/install/pypo-uninstall.py b/python_apps/pypo/install/pypo-uninstall.py index 50910b06c..00281c268 100755 --- a/python_apps/pypo/install/pypo-uninstall.py +++ b/python_apps/pypo/install/pypo-uninstall.py @@ -15,15 +15,6 @@ PATH_INI_FILE = '/etc/airtime/pypo.cfg' def remove_path(path): os.system("rm -rf " + path) -def remove_user(username): - os.system("killall -u %s 1>/dev/null 2>&1" % username) - - #allow all process to be completely closed before we attempt to delete user - print "Waiting for processes to close..." - time.sleep(5) - - os.system("deluser --remove-home " + username + " 1>/dev/null 2>&1") - def get_current_script_dir(): current_script_dir = os.path.realpath(__file__) index = current_script_dir.rindex('/') @@ -35,9 +26,10 @@ try: config = ConfigObj(PATH_INI_FILE) except Exception, e: print 'Error loading config file: ', e - sys.exit() + sys.exit(1) os.system("/etc/init.d/airtime-playout stop") + os.system("rm -f /etc/init.d/airtime-playout") print "Removing cache directories" remove_path(config["cache_base_dir"]) @@ -48,7 +40,6 @@ try: print "Removing pypo files" remove_path(config["bin_dir"]) - remove_user("pypo") print "Pypo uninstall complete." except Exception, e: print "exception:" + str(e) diff --git a/python_apps/pypo/pypo-cli.py b/python_apps/pypo/pypo-cli.py index b05bf34c2..3ac2e8f50 100755 --- a/python_apps/pypo/pypo-cli.py +++ b/python_apps/pypo/pypo-cli.py @@ -49,7 +49,8 @@ logging.config.fileConfig("logging.cfg") try: config = ConfigObj('/etc/airtime/pypo.cfg') except Exception, e: - print 'Error loading config file: ', e + logger = logging.getLogger() + logger.error('Error loading config file: %s', e) sys.exit() class Global: @@ -71,6 +72,7 @@ class Global: def test_api(self): self.api_client.test() +""" def check_schedule(self, export_source): logger = logging.getLogger() @@ -97,17 +99,20 @@ class Global: for media in playlist['medias']: print media +""" def keyboardInterruptHandler(signum, frame): - print "\nKeyboard Interrupt\n" - sys.exit(); + logger = logging.getLogger() + logger.info('\nKeyboard Interrupt\n') + sys.exit(0) if __name__ == '__main__': - print '###########################################' - print '# *** pypo *** #' - print '# Liquidsoap Scheduled Playout System #' - print '###########################################' + logger = logging.getLogger() + logger.info('###########################################') + logger.info('# *** pypo *** #') + logger.info('# Liquidsoap Scheduled Playout System #') + logger.info('###########################################') signal.signal(signal.SIGINT, keyboardInterruptHandler) @@ -120,10 +125,7 @@ if __name__ == '__main__': # initialize g = Global() - #NOTE: MUST EXIT HERE!! while not g.selfcheck(): time.sleep() - #Causes pypo to hang on system boot!!! - if not g.selfcheck(): - sys.exit() + while not g.selfcheck(): time.sleep(5) logger = logging.getLogger() diff --git a/python_apps/pypo/pypofetch.py b/python_apps/pypo/pypofetch.py index 224d256ee..616a347aa 100755 --- a/python_apps/pypo/pypofetch.py +++ b/python_apps/pypo/pypofetch.py @@ -33,7 +33,8 @@ try: POLL_INTERVAL = int(config['poll_interval']) except Exception, e: - print 'Error loading config file: ', e + logger = logging.getLogger() + logger.error('Error loading config file: %s', e) sys.exit() # Yuk - using a global, i know! @@ -242,8 +243,7 @@ class PypoFetch(Thread): #logger.debug("everything ok, adding %s to playlist", pl_entry) else: - print 'zero-file: ' + dst + ' from ' + media['uri'] - logger.warning("zero-size file - skipping %s. will not add it to playlist", dst) + logger.warning("zero-size file - skipping %s. will not add it to playlist at %s", media['uri'], dst) else: logger.warning("something went wrong. file %s not available. will not add it to playlist", dst) @@ -325,8 +325,7 @@ class PypoFetch(Thread): else: logger.info('sucessfully removed %s', os.path.join(r, dir)) except Exception, e: - print e - logger.error("%s", e) + logger.error(e) """ diff --git a/python_apps/pypo/pypopush.py b/python_apps/pypo/pypopush.py index c2b895bd5..da9e06e32 100755 --- a/python_apps/pypo/pypopush.py +++ b/python_apps/pypo/pypopush.py @@ -27,6 +27,7 @@ try: LS_PORT = config['ls_port'] PUSH_INTERVAL = 2 except Exception, e: + logger = logging.getLogger() logger.error('Error loading config file %s', e) sys.exit() diff --git a/python_apps/pypo/util/cue_file.py b/python_apps/pypo/util/cue_file.py index 7d752dd80..034515f23 100755 --- a/python_apps/pypo/util/cue_file.py +++ b/python_apps/pypo/util/cue_file.py @@ -61,12 +61,10 @@ class CueFile(): command = 'mp3cut -o %s -t %s-%s %s' % (dst + '.tmp.mp3', str_cue_in, str_cue_out, src); logger.info("command: %s", command) - print command os.system(command + ' > /dev/null 2>&1') command = 'lame -b 128 %s %s' % (dst + '.tmp.mp3', dst); logger.info("command: %s", command) - print command os.system(command + ' > /dev/null 2>&1') elif src.lower().endswith('.ogg'): audio = OggVorbis(src) diff --git a/python_apps/remove_pypo_user.py b/python_apps/remove_pypo_user.py new file mode 100644 index 000000000..eb60bd085 --- /dev/null +++ b/python_apps/remove_pypo_user.py @@ -0,0 +1,14 @@ +import os +import time + +def remove_user(username): + os.system("killall -u %s 1>/dev/null 2>&1" % username) + + #allow all process to be completely closed before we attempt to delete user + print "Waiting for processes to close..." + time.sleep(3) + + os.system("deluser --remove-home " + username + " 1>/dev/null 2>&1") + +if __name__ == "__main__": + remove_user("pypo") diff --git a/python_apps/show-recorder/install/recorder-install.py b/python_apps/show-recorder/install/recorder-install.py index af2e6ac02..6bada90f9 100755 --- a/python_apps/show-recorder/install/recorder-install.py +++ b/python_apps/show-recorder/install/recorder-install.py @@ -14,7 +14,7 @@ import shutil import string import platform from configobj import ConfigObj -from subprocess import Popen, PIPE, STDOUT +from subprocess import Popen if os.geteuid() != 0: print "Please run this as root." @@ -27,25 +27,6 @@ def create_path(path): print "Creating directory " + path os.makedirs(path) -def create_user(username): - print "Checking for user "+username - p = Popen('id '+username, shell=True, stdin=PIPE, stdout=PIPE, stderr=STDOUT, close_fds=True) - output = p.stdout.read() - if (output[0:3] != "uid"): - # Make the pypo user - print "Creating user "+username - os.system("adduser --system --quiet --group --shell /bin/bash "+username) - - #set pypo password - p = os.popen('/usr/bin/passwd pypo 1>/dev/null 2>&1', 'w') - p.write('pypo\n') - p.write('pypo\n') - p.close() - else: - print "User already exists." - #add pypo to audio group - os.system("adduser " + username + " audio 1>/dev/null 2>&1") - def copy_dir(src_dir, dest_dir): if (os.path.exists(dest_dir)) and (dest_dir != "/"): print "Removing old directory "+dest_dir @@ -57,7 +38,6 @@ def copy_dir(src_dir, dest_dir): def get_current_script_dir(): current_script_dir = os.path.realpath(__file__) index = current_script_dir.rindex('/') - #print current_script_dir[0:index] return current_script_dir[0:index] @@ -67,18 +47,13 @@ try: config = ConfigObj(PATH_INI_FILE) except Exception, e: print 'Error loading config file: ', e - sys.exit() + sys.exit(1) current_script_dir = get_current_script_dir() - #print "Checking and removing any existing recorder processes" - #os.system("python %s/recorder-uninstall.py 1>/dev/null 2>&1"% current_script_dir) - #time.sleep(5) + p = Popen("/etc/init.d/airtime-show-recorder stop", shell=True) sts = os.waitpid(p.pid, 0)[1] - # Create users - create_user("pypo") - print "Creating temporary media storage directory" create_path(config["base_recorded_files"]) os.system("chmod -R 755 "+config["base_recorded_files"]) @@ -102,6 +77,9 @@ try: print "Installing show-recorder daemon" shutil.copy(config["bin_dir"]+"/airtime-show-recorder-init-d", "/etc/init.d/airtime-show-recorder") + p = Popen("update-rc.d airtime-show-recorder defaults", shell=True) + sts = os.waitpid(p.pid, 0)[1] + print "Waiting for processes to start..." p = Popen("/etc/init.d/airtime-show-recorder start", shell=True) sts = os.waitpid(p.pid, 0)[1] diff --git a/python_apps/show-recorder/install/recorder-uninstall.py b/python_apps/show-recorder/install/recorder-uninstall.py index 3fc3514e2..4af506c9e 100755 --- a/python_apps/show-recorder/install/recorder-uninstall.py +++ b/python_apps/show-recorder/install/recorder-uninstall.py @@ -15,15 +15,6 @@ PATH_INI_FILE = '/etc/airtime/recorder.cfg' def remove_path(path): os.system("rm -rf " + path) -def remove_user(username): - os.system("killall -u %s 1>/dev/null 2>&1" % username) - - #allow all process to be completely closed before we attempt to delete user - print "Waiting for processes to close..." - time.sleep(5) - - os.system("deluser --remove-home " + username + " 1>/dev/null 2>&1") - def get_current_script_dir(): current_script_dir = os.path.realpath(__file__) index = current_script_dir.rindex('/') @@ -35,9 +26,10 @@ try: config = ConfigObj(PATH_INI_FILE) except Exception, e: print 'Error loading config file: ', e - sys.exit() + sys.exit(1) os.system("/etc/init.d/airtime-show-recorder stop") + os.system("rm -f /etc/init.d/airtime-show-recorder") print "Removing log directories" remove_path(config["log_dir"]) @@ -51,7 +43,6 @@ try: print "Removing media files" remove_path(config["base_recorded_files"]) - remove_user("pypo") print "Uninstall complete." except Exception, e: print "exception:" + str(e) diff --git a/python_apps/show-recorder/recorder.py b/python_apps/show-recorder/recorder.py index 367779a5a..783ad81e6 100644 --- a/python_apps/show-recorder/recorder.py +++ b/python_apps/show-recorder/recorder.py @@ -34,7 +34,8 @@ except Exception, e: try: config = ConfigObj('/etc/airtime/recorder.cfg') except Exception, e: - print 'Error loading config file: ', e + logger = logging.getLogger() + logger.error('Error loading config file: %s', e) sys.exit() def getDateTimeObj(time): diff --git a/utils/airtime-check-system b/utils/airtime-check-system index 45477df43..7a67e6845 100755 --- a/utils/airtime-check-system +++ b/utils/airtime-check-system @@ -25,7 +25,7 @@ # # Absolute path to this script SCRIPT=`readlink -f $0` -# Absolute path this script is in +# Absolute directory this script is in SCRIPTPATH=`dirname $SCRIPT` invokePwd=$PWD diff --git a/utils/airtime-clean-storage b/utils/airtime-clean-storage index 9f100b0ef..26625d89d 100755 --- a/utils/airtime-clean-storage +++ b/utils/airtime-clean-storage @@ -25,7 +25,7 @@ # # Absolute path to this script SCRIPT=`readlink -f $0` -# Absolute path this script is in +# Absolute directory this script is in SCRIPTPATH=`dirname $SCRIPT` invokePwd=$PWD diff --git a/utils/airtime-import b/utils/airtime-import index d2c67c12f..3480bb0fd 100755 --- a/utils/airtime-import +++ b/utils/airtime-import @@ -32,7 +32,7 @@ # Absolute path to this script SCRIPT=`readlink -f $0` -# Absolute path this script is in +# Absolute directory this script is in SCRIPTPATH=`dirname $SCRIPT` #------------------------------------------------------------------------------- diff --git a/utils/airtime-update-db-settings b/utils/airtime-update-db-settings index ae7abab19..459b6b459 100755 --- a/utils/airtime-update-db-settings +++ b/utils/airtime-update-db-settings @@ -32,7 +32,7 @@ # Absolute path to this script SCRIPT=`readlink -f $0` -# Absolute path this script is in +# Absolute directory this script is in SCRIPTPATH=`dirname $SCRIPT` #-------------------------------------------------------------------------------