import platform import shutil from subprocess import Popen, PIPE import sys import os sys.path.append('/usr/lib/airtime/api_clients/') import api_client from configobj import ConfigObj if os.geteuid() != 0: print "Please run this as root." sys.exit(1) """ def is_natty(): try: f = open('/etc/lsb-release') except IOError as e: #File doesn't exist, so we're not even dealing with Ubuntu return False for line in f: split = line.split("=") split[0] = split[0].strip(" \r\n") split[1] = split[1].strip(" \r\n") if split[0] == "DISTRIB_CODENAME" and (split[1] == "natty" or split[1] == "oneiric"): return True return False """ """ This function returns the codename of the host OS by querying lsb_release. If lsb_release does not exist, or an exception occurs the codename returned is 'unknown' """ def get_os_codename(): try: p = Popen("which lsb_release", shell=True) sts = os.waitpid(p.pid, 0)[1] if (sts == 0): #lsb_release is available on this system. Let's get the os codename p = Popen("lsb_release -sc", shell=True, stdout=PIPE) return p.communicate()[0].strip('\r\n') except Exception, e: pass return "unknown" def get_current_script_dir(): current_script_dir = os.path.realpath(__file__) index = current_script_dir.rindex('/') return current_script_dir[0:index] def generate_liquidsoap_config(ss): data = ss['msg'] fh = open('/etc/airtime/liquidsoap.cfg', 'w') fh.write("################################################\n") fh.write("# THIS FILE IS AUTO GENERATED. DO NOT CHANGE!! #\n") fh.write("################################################\n") for d in data: buffer = d[u'keyname'] + " = " if(d[u'type'] == 'string'): temp = d[u'value'] if(temp == ""): temp = "" buffer += "\"" + temp + "\"" else: temp = d[u'value'] if(temp == ""): temp = "0" buffer += temp buffer += "\n" fh.write(buffer) fh.write("log_file = \"/var/log/airtime/pypo-liquidsoap/