Python脚本-自动下载安装

#coding=utf-8
import os
import sys
if os.getuid() == 0:
        pass
else:
        print 'no'
        sys.exit(1)

version = raw_input("input")
if version == '2.7':
        url = 'https://www.python.org/ftp/python/2.7.12/Python-2.7.12.tgz'
elif version == '3.6':
        url = 'https://www.python.org/ftp/python/3.6.3/Python-3.6.3.tgz'
else:
        print '网络url失败'
        sys.exit(1)

cmd = 'wget '+url
res = os.system(cmd)
if res != 0:
        print '下载失败'
        sys.exit(1)


if version == '2.7':
        package ='Python-2.7.12'
else:
        package = 'Python-3.6.3'
cmd = 'tar -zxf ' + package + '.tgz'
res = os.system(cmd)
if res != 0:
        print("失败")
        sys.exit(1)
else:
        os.chdir("/home/feiji/"+package)
install = './config --prefix=/usr/local/python && make && make install'res = os.system(install)if res != 0:          print 'shibai'          sys.exit(1)

 

你可能感兴趣的