• 第一次写的脚本


    #!/usr/bin/env python
    # encoding:utf-8
    #author gxcc 2016

    import os,sys,time
    install_dir = "/soft/"   #定义存放安装包的目录
    tar_dir ="/softdoc/"     #定义解压安装包存放的目录
    os.chdir(install_dir)    #切换至/soft

    print "33[32m++++++++welcome to use python install script+++++++33[0m"
    time.sleep(1)

    if os.path.exists(tar_dir):
    print "the doc %s exist" % tar_dir
    else:
    os.mkdir(tar_dir)
    print "the doc %s create sucessful" % tar_dir

    install_file = os.listdir(install_dir)   #将安装目录下的软件包以列表的形式显示

    print "=================================================================="
    for i in range(len(install_file)):
    print i,install_file[i]
    print "=================================================================="

    while True:
    j = len(install_file)   #列表的长度
    choice = raw_input("pleas enter an number:")

    if not choice.isdigit():    #定义是否输入是纯数字
    print "please enter interger"
    break

        if int(choice) > j-1:    #列表的索引最大值比长度少1
    print "the index out of range"
    break

    else:
    print "Begin to exce the file"
    time.sleep(1)
    tar_cmd = "tar zxvf %s -C %s" % (install_file[int(choice)],tar_dir)
    os.system(tar_cmd)
    print "It's ok"
    break
    在写脚本的时候,遇到很多问题。主要还是逻辑思维还不太够清晰。经过一番改良后,更加加深了对语法的印象。

  • 相关阅读:
    4.Docker Compose 部署 Nexus
    3.Docker Compose 部署 GitLab
    2.Docker Compose 部署应用程序
    1.Docker Compose
    6.Dockerfile 指令
    5.Dockerfile 定制镜像
    4.Docker 操作容器
    3.Docker 操作镜像
    2.Ubuntu安装 Docker
    windows快捷键
  • 原文地址:https://www.cnblogs.com/glxsc/p/5136272.html
Copyright © 2020-2023  润新知