# npackage example https://svn.lliurex.net/pandora/n4d-ldap/trunk # jinja2 http://jinja.pocoo.org/docs/templates from jinja2 import Environment from jinja2.loaders import FileSystemLoader from jinja2 import Template import tempfile import shutil import os import subprocess class N4dProxyLite : def __init__(self): #Load template file self.tpl_env = Environment(loader=FileSystemLoader('/usr/share/n4d/templates/polipo')) pass #def init def startup(self,options): # executed when launching n4d pass #def startup def apt(self): # executed after apt operations pass #def apt # service test and backup functions # def test(self): pass #def test def backup(self): pass #def test def restore(self): pass #def test def load_exports(self): #Get template template = self.tpl_env.get_template("polipo.conf") list_variables = {} ########################### #Setting VARS ########################### #Set PROXY_HTTP_PORT list_variables['PROXY_HTTP_PORT'] = objects['VariablesManager'].get_variable('PROXY_HTTP_PORT') #If variable PROXY_HTTP_PORT is not defined calculate it with args values if list_variables['PROXY_HTTP_PORT'] == None: status,list_variables['PROXY_HTTP_PORT'] = objects['VariablesManager'].init_variable('PROXY_HTTP_PORT',{'PORT':3128}) #Set PROXY_HOST list_variables['PROXY_HOST'] = objects['VariablesManager'].get_variable('PROXY_HOST') #If variable PROXY_HOST is not defined calculate it with args values if list_variables['PROXY_HOST'] == None: status,list_variables['PROXY_HOST'] = objects['VariablesManager'].init_variable('PROXY_HOST',{'HOST':"proxy"}) #Encode vars to UTF-8 string_template = template.render(list_variables).encode('UTF-8') #Open template file fd, tmpfilepath = tempfile.mkstemp() new_export_file = open(tmpfilepath,'w') new_export_file.write(string_template) new_export_file.close() os.close(fd) #Write template values shutils.move(tmpfilepath,'/etc/polipo/config') return {'status':True,'msg':'Exports written'} #def load_exports def reboot_polipo(self): #Restart nfs service subprocess.Popen(['service', 'polipo','restart'],stdout=subprocess.PIPE).communicate() return {'status':True,'msg':'POLIPO restarted'} #def reboot_squid # ######################### # #class N4dProxyLite