Exemple #1
0
    def image(self, args):
        """ Create image from RTSProfile. This will saved to ${path_to_package}/images/[RTSP_NAME].jpg
        $ mgr.py rtsprofile image [RTSP_NAME] """
        options, argv = self.parse_args(args[:], self._print_system_profiles)
        verbose = options.verbose_flag  # This is default option
        wasanbon.arg_check(argv, 4)
        package = admin.package.get_package_from_path(os.getcwd())
        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

        image_path = os.path.join(package.path, 'image')
        if not os.path.isdir(image_path):
            os.mkdir(image_path)

        from rtsprofile.rts_profile import RtsProfile
        rtsp = RtsProfile(open(systemfile_fullpath, 'r').read())

        im = mgr.imaging.get_rtsp_image(package,
                                        rtsp,
                                        port_height=10,
                                        port_text_font=10)
        filepath = os.path.join(image_path, argv[3][:-4] + '.png')
        #im = self.get_image()
        im.save(filepath)
        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
Exemple #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
Exemple #4
0
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
Exemple #5
0
def main(argv):
    input_name = argv[1]
    type = os.path.splitext(input_name)[1][1:]
    f = open(input_name)
    if type == 'xml':
        prof = RtsProfile(xml_spec=f)
    elif type == 'yaml':
        prof = RtsProfile(yaml_spec=f)
    else:
        print >> sys.stderr, 'Unknown input type: {0}'.format(type)
        return 1
    f.close()

    compdict = {}
    for comp in prof.components:
        sem = semantics().parse(comp.path_uri)
        compdict[comp.instance_name] = (comp, sem)

    upstreamlist = {}
    downstreamlist = {}
    for con in prof.data_port_connectors:
        src = compdict[con.source_data_port.instance_name][0]
        tgt = compdict[con.target_data_port.instance_name][0]
        try:
            upstreamlist[tgt].append(src)
        except KeyError:
            upstreamlist[tgt] = (src, )
        try:
            downstreamlist[src].append(tgt)
        except KeyError:
            downstreamlist[src] = (tgt, )

    systemvalid = True
    for (comp, sem) in compdict.values():
        print "validation for component %s" % (comp.instance_name, )
        compvalid = False
        for i in sem._items:
            resvalid = False
            if i._restrictions:
                for r in i._restrictions:
                    rulevalid = False
                    if r._scope == "this":
                        if r.eval(comp) == True:
                            rulevalid = True
                    elif r._scope.endswith(".allupstream"):
                        try:
                            if listvalidate(upstreamlist[comp], r) == True:
                                rulevalid = True
                        except KeyError:
                            rulevalid = False
                    elif r._scope.endswith(".alldownstream"):
                        try:
                            if listvalidate(downstreamlist[comp], r) == True:
                                rulevalid = True
                        except KeyError:
                            rulevalid = False
                    if rulevalid == True:
                        resvalid = True
            else:
                resvalid = False
            reqvalid = True
            if i._requirements:
                for r in i._requirements:
                    rulevalid = False
                    if r._scope == "this":
                        if r.eval(comp) == True:
                            rulevalid = True
                    elif r._scope.endswith(".allupstream"):
                        try:
                            if listvalidate(upstreamlist[comp], r) == True:
                                rulevalid = True
                        except KeyError:
                            rulevalid = False
                    elif r._scope.endswith(".alldownstream"):
                        try:
                            if listvalidate(downstreamlist[comp], r) == True:
                                rulevalid = True
                        except KeyError:
                            rulevalid = False
                    if rulevalid == False:
                        reqvalid = False
            else:
                reqvalid = True
            if resvalid == False and reqvalid == True:
                compvalid = True
                print "component is valid in semantics {%s}" % (i._name, )
        if compvalid == False:
            print "no valid semantics"
        if compvalid == False:
            systemvalid = False
    if systemvalid == True:
        print "system is valid"
    else:
        print "system is invalid"
Exemple #6
0
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