7 class plc_configure(Test):
9 Configure the myplc from config options in config file
12 def call(self, plc_config_option=None, plc_config_value=None):
14 services = ['API', 'DB', 'WWW', 'BOOT']
16 # Get plc configuration variables
17 if plc_config_option is not None and \
18 plc_config_value is not None:
19 # Set option passed in from user
20 plc_options.append((plc_config_option, plc_config_value))
22 # Use hostname and ip of host we are running on
23 for service in services:
24 host_option = 'PLC_%(service)s_HOST' % locals()
25 ip_option = 'PLC_%(service)s_IP' % locals()
26 plc_options.append((host_option, self.config.hostname))
27 plc_options.append((ip_option, self.config.ip))
28 # Load any other options found in config file
29 for attr in dir(self.config):
30 if attr.startswith('PLC'):
31 plc_options.append((attr, getattr(self.config, attr)))
33 # Write temporary plc-config file
34 tmpname = '/tmp/plc-config-tty-%d' % os.getpid()
35 fileconf = open(tmpname, 'w')
36 for (option, value) in plc_options:
37 fileconf.write('e %s\n%s\n' % (option, value) )
38 fileconf.write('w\nq\n')
41 # Update plc config file
42 command = "plc-config-tty < %(tmpname)s" % locals()
43 if self.config.verbose:
45 (stdout, stderr) = utils.popen(command)
46 (stdout, stderr) = utils.popen("rm %s" % tmpname)
50 if __name__ == '__main__':
51 args = tuple(sys.argv[1:])
52 plc_configure()(*args)