예제 #1
0
    def switch(self, args):
        """ Switch RT-System 
        $ mgr.py system switch [SYSTEM_FILENAME] 
        The SYSTEM_FILENAME file must be included in RTS_DIR (defined in setting.yaml) """
        options, argv = self.parse_args(args[:])
        verbose = options.verbose_flag

        package = admin.package.get_package_from_path(os.getcwd())
        filenames = [
            file for file in os.listdir(package.get_systempath())
            if file.endswith('.xml')
        ]
        from wasanbon import util

        def filter_func(ans):
            file = filenames[ans]
            import yaml
            dict = yaml.load(open(package.setting_file_path, 'r'))
            setting_file_path = package.setting_file_path
            archive_path = os.path.join(package.path, 'backup')
            if not os.path.isdir(archive_path):
                os.mkdir(archive_path)
            archived_file_path = os.path.join(
                archive_path, 'setting.yaml' + wasanbon.timestampstr())
            os.rename(setting_file_path, archived_file_path)
            dict['application']['system'] = file
            open(setting_file_path, 'w').write(
                yaml.dump(dict,
                          encoding='utf8',
                          allow_unicode=True,
                          default_flow_style=False))
            return False

        util.choice(filenames, filter_func, msg='# Select System File')
        return 0
예제 #2
0
    def switch(self, args):
        """ Switch RT-System 
        $ mgr.py system switch [SYSTEM_FILENAME] 
        The SYSTEM_FILENAME file must be included in RTS_DIR (defined in setting.yaml) """
        options, argv = self.parse_args(args[:])
        verbose = options.verbose_flag
        
        package = admin.package.get_package_from_path(os.getcwd())
        filenames = [file for file in os.listdir(package.get_systempath()) if file.endswith('.xml')]
        from wasanbon import util
        def filter_func(ans):
            file = filenames[ans]
            import yaml
            dict = yaml.load(open(package.setting_file_path, 'r'))
            setting_file_path = package.setting_file_path
            archive_path = os.path.join(package.path, 'backup')
            if not os.path.isdir(archive_path):
                os.mkdir(archive_path)
            archived_file_path = os.path.join(archive_path, 'setting.yaml' + wasanbon.timestampstr())
            os.rename(setting_file_path, archived_file_path)
            dict['application']['system'] = file
            open(setting_file_path, 'w').write(yaml.dump(dict, encoding='utf8', allow_unicode=True, default_flow_style=False))
            return False

        util.choice(filenames, filter_func, msg='# Select System File')
        return 0
예제 #3
0
    def add_rtc(self, argv):
        """ Add RTC information to binder
        $ mgr.py binder add_rtc $BINDER_NAME $RTC_NAME
        """
        self.parser.add_option('-f', '--force', help='Force option (default=False)', default=False, action='store_true', dest='force_flag')
        options, argv = self.parse_args(argv[:], self._print_alternatives)
        verbose = options.verbose_flag # This is default option

        wasanbon.arg_check(argv, 5)
        binder_name = argv[3]
        rtc_name = argv[4]
        sys.stdout.write('# Information of RTC (%s) will be added to %s binder\n' % (rtc_name, binder_name))
        
        binder = admin.binder.get_binder(binder_name, verbose=verbose)
        package = admin.package.get_package_from_path(os.getcwd(), verbose=verbose)
        rtc = admin.rtc.get_rtc_from_package(package, rtc_name, verbose=verbose)
        repo = admin.repository.get_repository_from_rtc(rtc, verbose=verbose)
        global filename
        filename= None
        rtcs = [rtc_.name for rtc_ in binder.rtcs]
        if rtc_name in rtcs:
            sys.stdout.write('# This binder have the same RTC information.\n')

        else:
            if filename is None:
                def choice_command(ans):
                    global filename
                    filename = os.path.join(binder.rtcs_path, binder.rtc_files[ans])
                    return -1
                util.choice(binder.rtc_files, choice_command, 'Select RTC repository file')
            else:
                if not filename in binder.rtcs_files:
                    sys.stdout.write('# File %s is not found.\n' % filenmae)
                    filename = os.path.join(binder.rtcs_path, filename)
                    return -1
            print filename
            text = open(filename, 'r').read()
            #os.rename(filename, filename + wasanbon.timestampstr())
            #import yaml
            #repo_dic = yaml.load(open(filename, 'w'))

            text = text + """
%s :
  description : "%s"
  type : git
  url : '%s'
  platform : [%s]
""" % (repo.name, rtc.rtcprofile.basicInfo.doc.description, repo.url.strip(), wasanbon.platform())
            print text
            os.rename(filename, filename + wasanbon.timestampstr())
            open(filename, 'w').write(text)
            
            
        return 0
예제 #4
0
     def select_rtc(ans):
         confs = admin.systemeditor.get_active_configuration_data(rtcs[ans])
         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':
                 admin.systembuilder.set_active_configuration_data(rtcs[ans], key, val)
                 return True
             return False
         util.choice(conf_names, select_conf, msg='Select Configuration')
         return False
예제 #5
0
            def select_rtc(ans):
                confs = admin.systemeditor.get_active_configuration_data(
                    rtcs[ans])
                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':
                        admin.systembuilder.set_active_configuration_data(
                            rtcs[ans], key, val)
                        return True
                    return False

                util.choice(conf_names,
                            select_conf,
                            msg='Select Configuration')
                return False
예제 #6
0
 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
예제 #7
0
        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
예제 #8
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
예제 #9
0
    def build(self, args):
        """ Build System in Console interactively 
        $ mgr.py system build """
        self.parser.add_option('-b', '--background', help='Launch in background(default=False)', default=False, action='store_true', dest='background_flag')
        self.parser.add_option('-w', '--wakeuptimeout', help='Timeout of Sleep Function when waiting for the wakeup of RTC-Daemons', default=5, dest='wakeuptimeout', action='store', type='float')
        options, argv = self.parse_args(args[:])
        verbose = options.verbose_flag
        background = options.background_flag
        wakeuptimeout = options.wakeuptimeout
        #force  = options.force_flag

        package = admin.package.get_package_from_path(os.getcwd(), verbose=verbose)
        global endflag
        endflag = False
        try:
            processes = admin.systemlauncher.launch_system(package, verbose=verbose)
            time.sleep(wakeuptimeout)


            package = admin.package.get_package_from_path(os.getcwd())
            nss = admin.nameserver.get_nameservers_from_package(package, verbose=verbose)

            for ns in nss:
                ns.refresh(verbose=verbose)
            # Interactive Connect
            pairs = admin.systemeditor.get_connectable_pairs(nss, verbose=verbose)
            from wasanbon import util
            for pair in pairs:
                if util.no_yes('# Connect? (%s->%s)\n' % (admin.systembuilder.get_port_full_path(pair[0]),
                                                          admin.systembuilder.get_port_full_path(pair[1]))) == 'yes':
                    while True:
                        try:
                            admin.systembuilder.connect_ports(pair[0], pair[1], verbose=verbose)
                            sys.stdout.write('## Connected.\n')
                            break
                        except Exception, ex:
                            if verbose:
                                traceback.print_exc()
                                pass
                            sys.stdout.write('## Failed. \n')
                            if util.yes_no('### Retry?') == 'no':
                                break
                pass

            rtc_names = []
            rtcs = []
            for ns in nss:
                rtc_names = rtc_names + [admin.systembuilder.get_component_full_path(rtc) for rtc in ns.rtcs]
                rtcs = rtcs + ns.rtcs

            # Interactive Configure
            def select_rtc(ans):
                confs = admin.systemeditor.get_active_configuration_data(rtcs[ans])
                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':
                        admin.systembuilder.set_active_configuration_data(rtcs[ans], key, 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')


            #Save Running System
            if util.yes_no('# Save System ?') == 'yes':
                filename = os.path.basename(package.default_system_filepath)
                while True:
                    if util.yes_no('# Rename filename? (default:%s)' % filename) == 'yes':
                        while True:
                            sys.stdout.write('# Input:')
                            val = raw_input()
                            if util.yes_no('# New Filename = %s. Okay?' % val) == 'yes':
                                filename = val
                                break
                            pass
                        pass
                    # File check
                    filepath = os.path.join(package.get_systempath(fullpath=True), filename)
                    sys.stdout.write('## Saving to %s\n' % filepath)
                    if os.path.isfile(filepath):
                        if util.yes_no('## Overwrite?') == 'yes':
                            newfilename = filepath + wasanbon.timestampstr()
                            sys.stdout.write('## Rename existing file to %s\n' % os.path.basename(newfilename))
                            os.rename(filepath, newfilename)
                            break
                    else:
                        break

                while True:
                    sys.stdout.write('# Input Vendor Name:')
                    vendorName = raw_input()
                    sys.stdout.write('# Input Version:')
                    version = raw_input()
                    sys.stdout.write('# Input System Name (%s):' % package.name)
                    systemName = raw_input()
                    if len(systemName) == 0:
                        systemName = package.name
                    sys.stdout.write('# Input Description of System (abstract):')
                    abstract = raw_input()
                    
                    sys.stdout.write('## Vendor Name = %s\n' % vendorName)
                    sys.stdout.write('## Version     = %s\n' % version)
                    sys.stdout.write('## System Name = %s\n' % systemName)
                    sys.stdout.write('## Abstract    = %s\n' % abstract)
                    if util.yes_no('# Okay?') == 'yes':
                        break
                    else:
                        sys.stdout.write('# Retry')

                for i in range(5):
                    try:
                        sys.stdout.write('# Saving to %s\n' % filepath)
                        admin.systemeditor.save_to_file(nss, filepath, 
                                                        system_name=systemName,
                                                        abstract=abstract,
                                                        version=version,
                                                        vendor=vendorName,
                                                        verbose=verbose)
                        break
                    except:
                        traceback.print_exc()
                        time.sleep(1.0)                        
                        pass
                pass
            else:
                sys.stdout.write('## Aborted.')
예제 #10
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
예제 #11
0
    def build(self, args):
        """ Build System in Console interactively 
        $ mgr.py system build """
        self.parser.add_option('-b',
                               '--background',
                               help='Launch in background(default=False)',
                               default=False,
                               action='store_true',
                               dest='background_flag')
        self.parser.add_option(
            '-w',
            '--wakeuptimeout',
            help=
            'Timeout of Sleep Function when waiting for the wakeup of RTC-Daemons',
            default=5,
            dest='wakeuptimeout',
            action='store',
            type='float')
        options, argv = self.parse_args(args[:])
        verbose = options.verbose_flag
        background = options.background_flag
        wakeuptimeout = options.wakeuptimeout
        #force  = options.force_flag

        package = admin.package.get_package_from_path(os.getcwd(),
                                                      verbose=verbose)
        global endflag
        endflag = False
        try:
            processes = admin.systemlauncher.launch_system(package,
                                                           verbose=verbose)
            time.sleep(wakeuptimeout)

            package = admin.package.get_package_from_path(os.getcwd())
            nss = admin.nameserver.get_nameservers_from_package(
                package, verbose=verbose)

            for ns in nss:
                ns.refresh(verbose=verbose)
            # Interactive Connect
            pairs = admin.systemeditor.get_connectable_pairs(nss,
                                                             verbose=verbose)
            from wasanbon import util
            for pair in pairs:
                if util.no_yes(
                        '# Connect? (%s->%s)\n' %
                    (admin.systembuilder.get_port_full_path(pair[0]),
                     admin.systembuilder.get_port_full_path(
                         pair[1]))) == 'yes':
                    while True:
                        try:
                            admin.systembuilder.connect_ports(pair[0],
                                                              pair[1],
                                                              verbose=verbose)
                            sys.stdout.write('## Connected.\n')
                            break
                        except Exception, ex:
                            if verbose:
                                traceback.print_exc()
                                pass
                            sys.stdout.write('## Failed. \n')
                            if util.yes_no('### Retry?') == 'no':
                                break
                pass

            rtc_names = []
            rtcs = []
            for ns in nss:
                rtc_names = rtc_names + [
                    admin.systembuilder.get_component_full_path(rtc)
                    for rtc in ns.rtcs
                ]
                rtcs = rtcs + ns.rtcs

            # Interactive Configure
            def select_rtc(ans):
                confs = admin.systemeditor.get_active_configuration_data(
                    rtcs[ans])
                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':
                        admin.systembuilder.set_active_configuration_data(
                            rtcs[ans], key, 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')

            #Save Running System
            if util.yes_no('# Save System ?') == 'yes':
                filename = os.path.basename(package.default_system_filepath)
                while True:
                    if util.yes_no('# Rename filename? (default:%s)' %
                                   filename) == 'yes':
                        while True:
                            sys.stdout.write('# Input:')
                            val = raw_input()
                            if util.yes_no('# New Filename = %s. Okay?' %
                                           val) == 'yes':
                                filename = val
                                break
                            pass
                        pass
                    # File check
                    filepath = os.path.join(
                        package.get_systempath(fullpath=True), filename)
                    sys.stdout.write('## Saving to %s\n' % filepath)
                    if os.path.isfile(filepath):
                        if util.yes_no('## Overwrite?') == 'yes':
                            newfilename = filepath + wasanbon.timestampstr()
                            sys.stdout.write(
                                '## Rename existing file to %s\n' %
                                os.path.basename(newfilename))
                            os.rename(filepath, newfilename)
                            break
                    else:
                        break

                while True:
                    sys.stdout.write('# Input Vendor Name:')
                    vendorName = raw_input()
                    sys.stdout.write('# Input Version:')
                    version = raw_input()
                    sys.stdout.write('# Input System Name (%s):' %
                                     package.name)
                    systemName = raw_input()
                    if len(systemName) == 0:
                        systemName = package.name
                    sys.stdout.write(
                        '# Input Description of System (abstract):')
                    abstract = raw_input()

                    sys.stdout.write('## Vendor Name = %s\n' % vendorName)
                    sys.stdout.write('## Version     = %s\n' % version)
                    sys.stdout.write('## System Name = %s\n' % systemName)
                    sys.stdout.write('## Abstract    = %s\n' % abstract)
                    if util.yes_no('# Okay?') == 'yes':
                        break
                    else:
                        sys.stdout.write('# Retry')

                for i in range(5):
                    try:
                        sys.stdout.write('# Saving to %s\n' % filepath)
                        admin.systemeditor.save_to_file(nss,
                                                        filepath,
                                                        system_name=systemName,
                                                        abstract=abstract,
                                                        version=version,
                                                        vendor=vendorName,
                                                        verbose=verbose)
                        break
                    except:
                        traceback.print_exc()
                        time.sleep(1.0)
                        pass
                pass
            else:
                sys.stdout.write('## Aborted.')
예제 #12
0
    def add_rtc(self, argv):
        """ Add RTC information to binder
        $ mgr.py binder add_rtc $BINDER_NAME $RTC_NAME
        """
        self.parser.add_option('-f',
                               '--force',
                               help='Force option (default=False)',
                               default=False,
                               action='store_true',
                               dest='force_flag')
        options, argv = self.parse_args(argv[:], self._print_alternatives)
        verbose = options.verbose_flag  # This is default option

        wasanbon.arg_check(argv, 5)
        binder_name = argv[3]
        rtc_name = argv[4]
        sys.stdout.write(
            '# Information of RTC (%s) will be added to %s binder\n' %
            (rtc_name, binder_name))

        binder = admin.binder.get_binder(binder_name, verbose=verbose)
        package = admin.package.get_package_from_path(os.getcwd(),
                                                      verbose=verbose)
        rtc = admin.rtc.get_rtc_from_package(package,
                                             rtc_name,
                                             verbose=verbose)
        repo = admin.repository.get_repository_from_rtc(rtc, verbose=verbose)
        global filename
        filename = None
        rtcs = [rtc_.name for rtc_ in binder.rtcs]
        if rtc_name in rtcs:
            sys.stdout.write('# This binder have the same RTC information.\n')

        else:
            if filename is None:

                def choice_command(ans):
                    global filename
                    filename = os.path.join(binder.rtcs_path,
                                            binder.rtc_files[ans])
                    return -1

                util.choice(binder.rtc_files, choice_command,
                            'Select RTC repository file')
            else:
                if not filename in binder.rtcs_files:
                    sys.stdout.write('# File %s is not found.\n' % filenmae)
                    filename = os.path.join(binder.rtcs_path, filename)
                    return -1
            print filename
            text = open(filename, 'r').read()
            #os.rename(filename, filename + wasanbon.timestampstr())
            #import yaml
            #repo_dic = yaml.load(open(filename, 'w'))

            text = text + """
%s :
  description : "%s"
  type : git
  url : '%s'
  platform : [%s]
""" % (repo.name, rtc.rtcprofile.basicInfo.doc.description, repo.url.strip(),
            wasanbon.platform())
            print text
            os.rename(filename, filename + wasanbon.timestampstr())
            open(filename, 'w').write(text)

        return 0