#!/usr/bin/env python import sys import os import stat import shutil import ConfigParser import subprocess class MonoInstall(): def __init__(self): self.debug=True self.exe_skel="/usr/share/lliurex-mono-devhelper/skel/exec-file" self.config_skel="/usr/share/lliurex-mono-devhelper/skel/mono-install" self.rules_skel="/usr/share/lliurex-mono-devhelper/skel/rules" self.makefile_skel="/usr/share/lliurex-mono-devhelper/skel/Makefile" self.build_area="llx-mono-install-build-area/" self.use_parameters=False self.currdir="" #def __init__ def read_conf(self): self.dprint("Reading configuration file...") self.config=ConfigParser.ConfigParser() if not os.path.exists("mono-install"): print "[!] mono-install file not found" print "You can create a skel by using llx-mono-install create-mono-install" sys.exit(1) self.check_conf() self.config.read("mono-install") self.package_name=self.config.get('mono-install',"package_name") self.root_dir=self.config.get('mono-install',"root_dir") if self.root_dir.rfind('/')+1!=len(self.root_dir): self.root_dir=self.root_dir+"/" self.project_dir=self.config.get('mono-install',"project_dir") if self.project_dir.rfind('/')+1!=len(self.project_dir): self.project_dir=self.project_dir+"/" self.translation_project_dir=self.config.get('mono-install',"translation_project_dir") if self.translation_project_dir.rfind('/')+1!=len(self.translation_project_dir): self.translation_project_dir=self.translation_project_dir+"/" self.executable=self.config.get('executable-options',"executable_name") if self.use_parameters: self.parameters=self.config.get('executable-options','parameters') else: self.parameters="" #def read_conf def print_conf(self): self.dprint("\t\tpackage_name = " + self.package_name) self.dprint("\t\tproject_dir = " + self.project_dir) self.dprint("\t\ttranslation_project_dir = " + self.translation_project_dir) self.dprint("\t\tinstall_dir = " + self.install_dir) self.dprint("\t\texecutable_name = " + self.executable) if self.use_parameters: self.dprint("\t\tparameters = " + self.parameters) #def print_conf def check_conf(self): raw=ConfigParser.RawConfigParser() raw.read("mono-install") if not raw.has_section("mono-install"): print "[!] 'package-name' option missing in mono-install section" print "You can create a skel for mono-install file by using llx-mono-install create-mono-install" sys.exit(1) if not raw.has_option("mono-install","package_name"): print "[!] 'package-name' option missing in mono-install section" print "You can create a skel for mono-install file by using llx-mono-install create-mono-install" sys.exit(1) if not raw.has_option("mono-install","root_dir"): print "[!] 'root_dir' option missing in mono-install section" print "You can create a skel for mono-install file by using llx-mono-install create-mono-install" sys.exit(1) if not raw.has_option("mono-install","project_dir"): print "[!] 'project_dir' option missing in mono-install section" print "You can create a skel for mono-install file by using llx-mono-install create-mono-install" sys.exit(1) if not raw.has_option("mono-install","translation_project_dir"): print "[!] 'translation_project_dir' option missing in mono-install section" print "You can create a skel for mono-install file by using llx-mono-install create-mono-install" sys.exit(1) if not raw.has_section("executable-options"): print "[!] 'executable-options' section missing." print "You can create a skel for mono-install file by using llx-mono-install create-mono-install" sys.exit(1) if not raw.has_option("executable-options","executable_name"): print "[*] 'executable_name' option is missing in executable-options section" print "You can create a skel for mono-install file by using llx-mono-install create-mono-install" sys.exit(1) if not raw.has_option("executable-options","parameters"): self.use_parameters=False else: self.use_parameters=True #def check_conf def build(self): if not os.path.exists("Makefile"): print "[!] Makefile is missing" sys.exit(1) if os.path.exists(self.build_area): self.clean() self.dprint("Building...") p = subprocess.Popen(["make","release"],stdout=subprocess.PIPE,stderr=subprocess.PIPE).communicate() if len(p[1])>0: print "[!] Error compiling..." print p[1] sys.exit(1) #def build def prepare_executable(self): file_input=open(self.exe_skel,'r') usr_bin_dir=self.build_area + "usr/bin/"; os.makedirs(usr_bin_dir) file_output=open(usr_bin_dir + self.executable,'w') for line in file_input: if line.find("%PACKAGE%")!=-1: line=line.replace("%PACKAGE%",self.package_name) line=line.replace("%EXEC_FILE%",self.executable) line=line.replace("%PARAMETERS%",self.parameters) file_output.write(line) file_input.close() file_output.close() os.chmod(usr_bin_dir + self.executable,0755) #def prepare_executable def copy_lib_file(self): for file in os.listdir(self.project_dir+"bin/Release"): if not os.path.exists(self.build_area+"usr/lib/" + self.package_name): os.makedirs(self.build_area+"usr/lib/" + self.package_name) shutil.copy(self.project_dir+"bin/Release/" + file,self.build_area+"usr/lib/" + self.package_name) #def copy_install_files def install(self,dir): self.currdir=dir self.dprint("Installing...") os.mkdir(self.build_area) self.copy_lib_file() self.prepare_executable() self.copy_to_deb_build_area() self.lliurex_po() #def install def copy_to_deb_build_area(self): for dir in os.listdir(self.build_area): shutil.copytree(self.build_area + dir,self.currdir+"/debian/" + self.package_name + "/" +dir) #def copy_to_deb_build_area def lliurex_po(self): os.makedirs(self.root_dir+"lliurex-po/" + self.package_name) if not os.path.exists(self.translation_project_dir+"es.po"): print "[*] Spanish (es) translation missing..." else: shutil.copy(self.translation_project_dir+"es.po",self.root_dir+"lliurex-po/" + self.package_name) if not os.path.exists(self.translation_project_dir+"qcv.po"): print "[*] Valencian (qcv) translation missing..." else: shutil.copy(self.translation_project_dir+"qcv.po",self.root_dir+"lliurex-po/" + self.package_name) shutil.copy(self.translation_project_dir+"messages.po",self.root_dir+"lliurex-po/"+self.package_name + "/" + self.package_name +".pot") #def lliurex_po def clean(self): if os.path.exists(self.build_area): self.dprint("Cleaning..."); p = subprocess.Popen(["make","clean"],stdout=subprocess.PIPE,stderr=subprocess.PIPE).communicate() shutil.rmtree(self.build_area) if os.path.exists(self.root_dir+"lliurex-po/" + self.package_name): shutil.rmtree(self.root_dir+"lliurex-po") #def clean def create_conf(self): shutil.copy(self.config_skel,os.getcwd()) #def create_conf def create_rules(self): shutil.copy(self.rules_skel,os.getcwd()) #def create_rules def create_makefile(self): shutil.copy(self.makefile_skel,os.getcwd()) #def create_makefile def usage(self): print "USAGE:" print "\t llx-mono-install [PARAMETER]" print "" print "AVAILABLE PARAMETERS:" print "" print "\tbuild\t\t\tBuilds project" print "\tinstall\t\t\tInstalls project in a debian structured package." print "\tclean\t\t\tCleans llx-mono-install build area" print "\tcreate-mono-install\tCreates a clean mono-install configuration file" print "\tcreate-rules\t\tCreates a rules file with llx-mono-install functions enabled" print "\tcreate-makefile\t\tCreates a makefile ready to be edited" print "" #def usage def dprint(self,data): if self.debug: print ("[MonoInstall] " + data) #dprint #class MonoInstall mi=MonoInstall() if len(sys.argv)>1: if sys.argv[1]=="build": mi.read_conf() mi.build() elif sys.argv[1]=="install": mi.read_conf() mi.install(os.getcwd()) elif sys.argv[1]=="clean": mi.read_conf() mi.clean() elif sys.argv[1]=="create-mono-install": mi.create_conf() elif sys.argv[1]=="create-rules": mi.create_rules() elif sys.argv[1]=="create-makefile": mi.create_makefile() else: mi.usage() sys.exit(1) else: mi.usage() sys.exit(1)