def configure(self, args): """ Configure system interactively in console. $ mgr.py system configure """ self.parser.add_option('-f', '--file', help='Configure with Specific RTSProfile (must be placed in system_dir', default=None, dest='systemfile', action='store', type='string') options, argv = self.parse_args(args[:]) verbose = options.verbose_flag package = admin.package.get_package_from_path(os.getcwd()) if options.systemfile: filename = os.path.join(package.get_systempath(), options.systemfile) else: filename = package.default_system_filepath from rtsprofile.rts_profile import RtsProfile file = open(filename, 'r') rtsprofile = RtsProfile(xml_spec = file) del(file) rtc_names = [rtc.instance_name for rtc in rtsprofile.components] from wasanbon import util def select_rtc(ans): rtc = rtsprofile.components[ans] confs = [] active_conf_index = -1 if len(rtc.configuration_sets) != 0: for i, conf in enumerate(rtc.configuration_sets): if conf.id == rtc.active_configuration_set: active_conf_index = i confs = conf.configuration_data conf_names = [conf.name +':' + conf.data for conf in confs] def select_conf(ans2): key = confs[ans2].name sys.stdout.write('## INPUT (%s):' % key) val = raw_input() if util.yes_no('# %s = %s. Okay?' % (key, val)) == 'yes': rtc.configuration_sets[active_conf_index].configuration_data[ans2].data = val return True return False util.choice(conf_names, select_conf, msg='# Select Configuration') return False util.choice(rtc_names, select_rtc, msg='# Select RTC') if util.yes_no("Save System?") != 'yes': sys.stdout.write('# Aborted \n') return 0 while True: if util.no_yes('Rename Filename?') == 'yes': filepath = os.path.join(package.get_systempath(), raw_input('Filename:')) else: filepath = filename newfile = filepath + wasanbon.timestampstr() try: os.rename(filepath, newfile) except Exception, e: sys.stdout.write('## Exception occurred when renaming file.\n') traceback.print_exc() continue try: fout = open(filepath, 'w') fout.write(rtsprofile.save_to_xml()) fout.close() except: sys.stdout.write('## Exception occurred when saving file.\n') traceback.print_exc() continue break
def main(argv): print \ '''This test loads a given XML or YAML file (type determined by the extension) into an RtsProfile object. The object is printed to a string, which is stored. It then attempts to save the object using the XML output. This output is loaded back in, printed to a string, and that string compared to the original. They should be the same. This save-load-check process is then repeated for the YAML output. ''' # Load the input input_name = argv[1] type = os.path.splitext(input_name)[1][1:] f = open(input_name) if type == 'xml': orig_prof = RtsProfile(xml_spec=f) elif type == 'yaml': orig_prof = RtsProfile(yaml_spec=f) else: print >>sys.stderr, 'Unknown input type: {0}'.format(type) return 1 f.close() orig_prof_str = str(orig_prof) print 'Loaded original.' print # Test XML output failed = False xml_output = '' xml_prof_str = '' try: xml_output = orig_prof.save_to_xml() print 'Saved as XML.' xml_prof = RtsProfile(xml_spec=xml_output) print 'Loaded XML.' xml_prof_str = str(xml_prof) print 'Printed XML.' print except: print_exc() print failed = True if xml_prof_str != orig_prof_str: print 'XML profile does not equal original profile.' failed = True if failed: print >>sys.stderr, 'XML test failed.' f = open('original_prof.dump', 'w') f.write(orig_prof_str) f.close() f = open('xml_prof.dump', 'w') f.write(xml_prof_str) f.close() f = open('xml_raw.dump', 'w') f.write(xml_output) f.close() return 1 # Test YAML output failed = False yaml_output = '' yaml_prof_str = '' try: yaml_output = orig_prof.save_to_yaml() print 'Saved as YAML.' yaml_prof = RtsProfile(yaml_spec=yaml_output) print 'Loaded YAML.' yaml_prof_str = str(yaml_prof) print 'Printed YAML.' print except: print_exc() print failed = True if yaml_prof_str != orig_prof_str: print 'YAML profile does not equal original profile.' failed = True if failed: print >>sys.stderr, 'YAML test failed.' f = open('original_prof.dump', 'w') f.write(orig_prof_str) f.close() f = open('yaml_prof.dump', 'w') f.write(yaml_prof_str) f.close() f = open('yaml_raw.dump', 'w') f.write(yaml_output) f.close() return 1 print >>sys.stderr, 'Tests passed.' return 0
def configure(self, args): """ Configure system interactively in console. $ mgr.py system configure """ self.parser.add_option( '-f', '--file', help= 'Configure with Specific RTSProfile (must be placed in system_dir', default=None, dest='systemfile', action='store', type='string') options, argv = self.parse_args(args[:]) verbose = options.verbose_flag package = admin.package.get_package_from_path(os.getcwd()) if options.systemfile: filename = os.path.join(package.get_systempath(), options.systemfile) else: filename = package.default_system_filepath from rtsprofile.rts_profile import RtsProfile file = open(filename, 'r') rtsprofile = RtsProfile(xml_spec=file) del (file) rtc_names = [rtc.instance_name for rtc in rtsprofile.components] from wasanbon import util def select_rtc(ans): rtc = rtsprofile.components[ans] confs = [] active_conf_index = -1 if len(rtc.configuration_sets) != 0: for i, conf in enumerate(rtc.configuration_sets): if conf.id == rtc.active_configuration_set: active_conf_index = i confs = conf.configuration_data conf_names = [conf.name + ':' + conf.data for conf in confs] def select_conf(ans2): key = confs[ans2].name sys.stdout.write('## INPUT (%s):' % key) val = raw_input() if util.yes_no('# %s = %s. Okay?' % (key, val)) == 'yes': rtc.configuration_sets[ active_conf_index].configuration_data[ans2].data = val return True return False util.choice(conf_names, select_conf, msg='# Select Configuration') return False util.choice(rtc_names, select_rtc, msg='# Select RTC') if util.yes_no("Save System?") != 'yes': sys.stdout.write('# Aborted \n') return 0 while True: if util.no_yes('Rename Filename?') == 'yes': filepath = os.path.join(package.get_systempath(), raw_input('Filename:')) else: filepath = filename newfile = filepath + wasanbon.timestampstr() try: os.rename(filepath, newfile) except Exception, e: sys.stdout.write( '## Exception occurred when renaming file.\n') traceback.print_exc() continue try: fout = open(filepath, 'w') fout.write(rtsprofile.save_to_xml()) fout.close() except: sys.stdout.write('## Exception occurred when saving file.\n') traceback.print_exc() continue break
def main(argv): print \ '''This test loads a given XML or YAML file (type determined by the extension) into an RtsProfile object. The object is printed to a string, which is stored. It then attempts to save the object using the XML output. This output is loaded back in, printed to a string, and that string compared to the original. They should be the same. This save-load-check process is then repeated for the YAML output. ''' # Load the input input_name = argv[1] type = os.path.splitext(input_name)[1][1:] f = open(input_name) if type == 'xml': orig_prof = RtsProfile(xml_spec=f) elif type == 'yaml': orig_prof = RtsProfile(yaml_spec=f) else: print >> sys.stderr, 'Unknown input type: {0}'.format(type) return 1 f.close() orig_prof_str = str(orig_prof) print 'Loaded original.' print # Test XML output failed = False xml_output = '' xml_prof_str = '' try: xml_output = orig_prof.save_to_xml() print 'Saved as XML.' xml_prof = RtsProfile(xml_spec=xml_output) print 'Loaded XML.' xml_prof_str = str(xml_prof) print 'Printed XML.' print except: print_exc() print failed = True if xml_prof_str != orig_prof_str: print 'XML profile does not equal original profile.' failed = True if failed: print >> sys.stderr, 'XML test failed.' f = open('original_prof.dump', 'w') f.write(orig_prof_str) f.close() f = open('xml_prof.dump', 'w') f.write(xml_prof_str) f.close() f = open('xml_raw.dump', 'w') f.write(xml_output) f.close() return 1 # Test YAML output failed = False yaml_output = '' yaml_prof_str = '' try: yaml_output = orig_prof.save_to_yaml() print 'Saved as YAML.' yaml_prof = RtsProfile(yaml_spec=yaml_output) print 'Loaded YAML.' yaml_prof_str = str(yaml_prof) print 'Printed YAML.' print except: print_exc() print failed = True if yaml_prof_str != orig_prof_str: print 'YAML profile does not equal original profile.' failed = True if failed: print >> sys.stderr, 'YAML test failed.' f = open('original_prof.dump', 'w') f.write(orig_prof_str) f.close() f = open('yaml_prof.dump', 'w') f.write(yaml_prof_str) f.close() f = open('yaml_raw.dump', 'w') f.write(yaml_output) f.close() return 1 print >> sys.stderr, 'Tests passed.' return 0