📄 config.py
字号:
import ConfigParser, os, md5, rotor
KEY='pyljclient'
CONFIG_FILE = 'pyljclient.conf'
ITEMS = {'item_a':'client_name',
'item_b':'client_version'}
R_ITEMS = {'client_name':'item_a',
'client_version':'item_b'}
def initialize():
clientParser = ConfigParser.ConfigParser()
clientParser.add_section('GLOBAL')
clientParser.set('GLOBAL',R_ITEMS['client_name'],encrypt('pyljclient'))
clientParser.set('GLOBAL',R_ITEMS['client_version'],encrypt('0.3.0'))
fd = open(os.path.join(os.getcwd(),CONFIG_FILE), 'w')
clientParser.write(fd)
fd.close()
def encrypt(item):
return rotor.newrotor(KEY).encrypt(item)
def decrypt(item):
return rotor.newrotor(KEY).decrypt(item)
def update(option, value, section='GLOBAL'):
clientParser = readConfig()
if option not in R_ITEMS.keys():
raise "no such option exists"
else:
option_key = R_ITEMS[option]
clientParser.set(section, option_key, encrypt(value))
fd = open(os.path.join(os.getcwd(),CONFIG_FILE), 'w')
clientParser.write(fd)
fd.close()
def readConfig():
clientParser = ConfigParser.ConfigParser()
config_file = os.path.join(os.getcwd(),CONFIG_FILE)
if not os.path.exists(config_file):
initialize()
clientParser.read(config_file)
return clientParser
def getOption(option, section='GLOBAL'):
clientParser = readConfig()
item = clientParser.get(section, R_ITEMS[option])
decrypted_item = decrypt(item)
print "getOption decrypted item...:",decrypted_item
return decrypted_item
def printGlobals():
config = readConfig()
print "Name -->", getClientName()
print "Version -->", getClientVersion()
#-----------------
def getClientName():
return getOption('client_name')
def getClientVersion():
return getOption('client_version')
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -