|
#!/usr/bin/python
##coding:utf-8##
#-------------------------------------------------------------------------------
# Name: LAMP-Auto-Install.py
#
# Author: LiuSha
#
# Created: 9/07/2014
# Copyright: (c) http://www.ipython.me/ 2014
#-------------------------------------------------------------------------------
import os
import sys
import time
import getopt
import logging
import commands
from Dict import Global
from platform import machine
#Define Log Output#
logging.basicConfig(filename = os.path.join(os.getcwd(), 'log.txt'),
filemode = 'w',
level = logging.DEBUG,
format = '%(asctime)s %(filename)s %(levelname)s %(message)s',
datefmt = '%a,%d %b %Y %H:%M',)
#Define Main Funtion Class#
class funcTion():
def main(self):
"""define global main config. get global build param"""
try:
longargs = ["prefix=","debug=","webservice=","jobdir=","add-vhost=","add-func=","howto="]
opts,args = getopt.getopt(sys.argv[1:],"h",longargs)
Global.Mainargs = dict(opts)
except getopt.GetoptError,err:
print str(err)
sys.exit(2)
def echo(self,output,color = '32'):
"""define calor Output funtion"""
return '\033[1;{1};40m{0}\033[0m'.format(output,color)
def exec_commands(self,cmd,cmdAlias,istName = ''):
"""define commands exec function"""
status,output = commands.getstatusoutput("{0}".format(cmd))
if int(status) == 0:
logging.info('{0} execution successful -->\n ####---{1}---####'.format(cmdAlias,istName))
else:
logging.debug('{0} execution exception -->\n ####---{1}---####\n\n{2}\n\n'.format(cmdAlias,istName,output))
def Unpack(self,istName,jobdir,tarname,tardir):
"""define unpack function"""
print self.echo("%s Starting Install".ljust(80)%istName)
if tarname[-3:] == 'bz2':
os.chdir("%s"%jobdir)
os.system("tar jxf %s"%tarname)
os.chdir("%s"%tardir)
else:
print self.echo('[Error1]:Unpark format Error','31')
def command_Check(self,command,istCommand):
"""define Command check via Yum"""
if os.path.exists("/usr/bin/%s"%command) == False:
self.exec_commands("yum -y install {0} {1}".format(istCommand,Global.workMode['OutPut']),"yum install {0}".format(command),"command_Check[function]")
else:
pass |
|
|