Пример #1
0
    def copy(self, args):
        self.parser.add_option('-f', '--force', help='Force Delete without yes/no option (default=False)', default=False, dest='force_flag', action='store_true')
        options, argv = self.parse_args(args[:])
        verbose = options.verbose_flag
        force = options.force_flag
        package = admin.package.get_package_from_path(os.getcwd(), verbose=verbose)
        wasanbon.arg_check(argv, 5)
        srcfile = argv[3]
        dstfile = argv[4]
        srcfile_relpath = os.path.join(package.get_systempath(fullpath=False), srcfile)
        srcfile_fullpath = os.path.join(package.get_systempath(), srcfile)
        if not os.path.isfile(srcfile_fullpath):
            sys.stdout.write('## No System File exists.\n')
            return -1

        dstfile_fullpath = os.path.join(package.get_systempath(), dstfile)
        if os.path.isfile(dstfile_fullpath):
            if not force:
                from wasanbon import util
                if util.no_yes('# Overwrite? (%s):' % systemfile_relpath) == 'no':
                    sys.stdout.write('## Aborted.\n')
                    return 0
            newfile = dstfile_fullpath + wasanbon.timestampstr()
            os.rename(dstfile_fullpath, newfile)
        
        import shutil
        shutil.copyfile(srcfile_fullpath, dstfile_fullpath)
        sys.stdout.write('## Success\n')
        return 0
Пример #2
0
    def delete(self, args):
        self.parser.add_option(
            '-f',
            '--force',
            help='Force Delete without yes/no option (default=False)',
            default=False,
            dest='force_flag',
            action='store_true')
        options, argv = self.parse_args(args[:])
        verbose = options.verbose_flag
        force = options.force_flag
        package = admin.package.get_package_from_path(os.getcwd(),
                                                      verbose=verbose)
        systemfile = argv[3]
        systemfile_relpath = os.path.join(
            package.get_systempath(fullpath=False), systemfile)
        systemfile_fullpath = os.path.join(package.get_systempath(),
                                           systemfile)
        if not os.path.isfile(systemfile_fullpath):
            sys.stdout.write('## No System File exists.\n')
            return -1

        if not force:
            from wasanbon import util
            if util.no_yes('# Delete? (%s):' % systemfile_relpath) == 'no':
                sys.stdout.write('## Aborted.\n')
                return 0

        newfile = systemfile_fullpath + wasanbon.timestampstr()
        os.rename(systemfile_fullpath, newfile)

        sys.stdout.write('## Success\n')
        return 0
Пример #3
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
Пример #4
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.')
Пример #5
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
Пример #6
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.')