zoukankan      html  css  js  c++  java
  • 第一次写的脚本

    #!/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
    在写脚本的时候,遇到很多问题。主要还是逻辑思维还不太够清晰。经过一番改良后,更加加深了对语法的印象。

  • 相关阅读:
    zookeeper java调用及权限控制
    走进C++程序世界------IO标准库介绍
    Unity3d 镜面折射 vertex and frag Shader源代码
    servlet上传文件报错(二)
    模仿linux内核定时器代码,用python语言实现定时器
    6.12交流
    python学习(三) 使用字符串
    JAVA面试(四)
    python学习(二) 列表和元组
    C++面试题(三)
  • 原文地址:https://www.cnblogs.com/glxsc/p/5136272.html
Copyright © 2011-2022 走看看