comparison martini/main.py @ 21:85bbb83703fa

python3
author Jeff Hammel <k0scist@gmail.com>
date Sat, 24 Apr 2021 14:58:56 -0700
parents 4faed08eb8d8
children 112cb171b419
comparison
equal deleted inserted replaced
20:93c198d9bf84 21:85bbb83703fa
93 args = sys.argv[1:] 93 args = sys.argv[1:]
94 files, sections = parse_args(*args) 94 files, sections = parse_args(*args)
95 95
96 # display usage information 96 # display usage information
97 if not files: 97 if not files:
98 print 'Usage:' 98 print('Usage:')
99 print usage % os.path.basename(sys.argv[0]) 99 print(usage % os.path.basename(sys.argv[0]))
100 sys.exit(0) 100 sys.exit(0)
101 101
102 # process the files 102 # process the files
103 for f in files: 103 for f in files:
104 if f == '-': 104 if f == '-':
110 if section in munger.sections(): 110 if section in munger.sections():
111 if options: 111 if options:
112 for option in options: 112 for option in options:
113 value = munger.get(section, option) 113 value = munger.get(section, option)
114 if value is not None: 114 if value is not None:
115 print value 115 print(value)
116 else: 116 else:
117 config.ConfigMunger({section: munger[section]}).write() 117 config.ConfigMunger({section: munger[section]}).write()
118 118
119 def delete(args=None): 119 def delete(args=None):
120 120
125 args = sys.argv[1:] 125 args = sys.argv[1:]
126 files, sections = parse_args(*args) 126 files, sections = parse_args(*args)
127 127
128 # display usage information 128 # display usage information
129 if not files: 129 if not files:
130 print 'Usage:' 130 print('Usage:')
131 print usage % os.path.basename(sys.argv[0]) 131 print(usage % os.path.basename(sys.argv[0]))
132 sys.exit(0) 132 sys.exit(0)
133 133
134 # process the files 134 # process the files
135 for f in files: 135 for f in files:
136 if f == '-': 136 if f == '-':
148 conf.pop(section) 148 conf.pop(section)
149 if f == '-': 149 if f == '-':
150 fp = sys.stdout 150 fp = sys.stdout
151 else: 151 else:
152 fp.close() 152 fp.close()
153 fp = file(f, 'w') 153 fp = open(f, 'w')
154 config.ConfigMunger(conf).write(fp) 154 config.ConfigMunger(conf).write(fp)
155 155
156 def munge(args=None): 156 def munge(args=None):
157 157
158 usage = "%s file1 [file2] [...]" 158 usage = "%s file1 [file2] [...]"
167 options, args = parser.parse_args(args) 167 options, args = parser.parse_args(args)
168 files, sections = parse_options(*args) 168 files, sections = parse_options(*args)
169 169
170 # display usage information 170 # display usage information
171 if not files: 171 if not files:
172 print 'Usage:' 172 print('Usage:')
173 print usage % os.path.basename(sys.argv[0]) 173 print(usage % os.path.basename(sys.argv[0]))
174 sys.exit(0) 174 sys.exit(0)
175 175
176 # munge the files 176 # munge the files
177 conf = list(files) 177 conf = list(files)
178 conf.append(sections) 178 conf.append(sections)
179 munger = config.ConfigMunger(*conf) 179 munger = config.ConfigMunger(*conf)
180 if options.output: 180 if options.output:
181 fp = file(options.output, 'w') 181 fp = file(options.output, 'w')
182 else: 182 else: