import platform import shutil from subprocess import Popen, PIPE import subprocess import sys import os sys.path.append('/usr/lib/airtime/') from api_clients import api_client from configobj import ConfigObj import logging if os.geteuid() != 0: print "Please run this as root." sys.exit(1) """ 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 > /dev/null", 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) codename = p.communicate()[0].strip('\r\n') p = Popen("lsb_release -sd", shell=True, stdout=PIPE) fullname = p.communicate()[0].strip('\r\n') return (codename, fullname) except Exception, e: pass return ("unknown", "unknown") 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'] buffer += '"%s"' % temp else: temp = d[u'value'] if(temp == ""): temp = "0" buffer += temp buffer += "\n" fh.write(api_client.encode_to(buffer)) fh.write('log_file = "/var/log/airtime/pypo-liquidsoap/