#!/usr/bin/python
# -*- coding: UTF-8 -*-
import sys,getopt
import os
def add(argv):
hostip = ''
username = ''
password = ''
try:
opts, args = getopt.getopt(argv,"h:u:p:")
except getopt.GetoptError:
print 'ERROR: server.py add -h <hostip> -u <username> -p <password>'
sys.exit(2)
for opt, arg in opts:
if opt == "-h":
hostip = arg
elif opt == "-u":
username = arg
elif opt == "-p":
password = arg
writeInfo(hostip,username,password)
def delete(argv):
hostip = ''
try:
opts, args = getopt.getopt(argv,"h:")
except getopt.GetoptError:
print 'ERROR: server.py delete -h <hostip>'
sys.exit(2)
for opt, arg in opts:
if opt == "-h":
hostip = arg
deleteInfo(hostip)
def listInfo():
inputfile = open('/Users/ibunny/serverinfo','r')
for line in inputfile:
if line == '\n': pass
else: print line.strip()
inputfile.close()
def writeInfo(hostip, username, password):
outputfile = open('/Users/ibunny/serverinfo','a')
outputfile.write(hostip + ' ' + username + ' ' + password + '\n')
outputfile.close()
def deleteInfo(hostip):
inputfile = open('/Users/ibunny/serverinfo','r')
outputfile = open('/Users/ibunny/serverinfo_new','w')
for line in inputfile:
if line.strip().split(" ")[0] == hostip:
pass
else:
outputfile.write(line)
inputfile.close()
outputfile.close()
os.remove('/Users/ibunny/serverinfo')
os.rename('/Users/ibunny/serverinfo_new', '/Users/ibunny/serverinfo')
if __name__ == "__main__":
option = sys.argv[1]
if (option == 'add'):
add(sys.argv[2:])
elif (option == 'delete'):
delete(sys.argv[2:])
elif (option == 'list'):
listInfo()
else:
print 'ERROR: only add/delete'
功能模块
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- 15.2.5实体类模块设计 实体类是现实实体在计算机中的表示。它贯穿于整个架构,负担着在各层次及模块间传递数据的职...