-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit_op.py
82 lines (70 loc) · 1.91 KB
/
init_op.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# -*- coding: utf-8 -*-
'''
Created on 2015-12-9
@author: Administrator
'''
#!/usr/bin/python
# -*- coding:utf-8 -*-
#author: lingyue.wkl
#desc: use to read ini
#---------------------
#2012-02-18 created
#---------------------
import sys
import ConfigParser
class Config:
def __init__(self, path):
self.path = path
self.cf = ConfigParser.ConfigParser()
self.cf.read(self.path)
def get(self, field, key):
result = ""
try:
result = self.cf.get(field, key)
except:
result = ""
return result
def set(self, filed, key, value):
try:
self.cf.set(field, key, value)
self.cf.write(open(self.path, 'w'))
except:
return False
return True
def read_config(config_file_path, field, key):
cf = ConfigParser.ConfigParser()
try:
cf.read(config_file_path)
result = cf.get(field, key)
except Exception,e:
print "error:",e,config_file_path
result = 0
return result
def write_config(config_file_path, field, key, value):
if value == "":
value = '0'
cf = ConfigParser.ConfigParser()
try:
cf.read(config_file_path)
cf.set(field, key, value)
cf.write(open(config_file_path, 'w'))
except Exception, e:
print e
# sys.exit(1)
return True
if __name__ == "__main__":
# if len(sys.argv) < 4:
# sys.exit(1)
#
# config_file_path = sys.argv[1]
# field = sys.argv[2]
# key = sys.argv[3]
# if len(sys.argv) == 4:
# print read_config(config_file_path, field, key)
# else:
# value = sys.argv[4]
# write_config(config_file_path, field, key, value)
config_file_path = "conf/ST_CONF.ini"
SYS_CONF_PATH = "conf/SYS_CONF.ini"
write_config(SYS_CONF_PATH, "AI518P", "meas_times", 10)
# print read_config(config_file_path, 'INST', 'meas_mode')