Ejemplo n.º 1
0
 def val_channels(self, value):
     if type(value) != str:
         raise TypeError('channels')
     try:
         values = sorted(QTools.expand_int_list_set(value))
     except ValueError:
         raise ValueError('channels')
     value = []
     for v in values:
         if 1 > v > 6:
             raise ValueError('channels')
         value.append(v)
     return value
Ejemplo n.º 2
0
 def val_cal_monitor(self, value):
     if type(value) != str:
         raise TypeError('cal_monitor')
     try:
         values = sorted(QTools.expand_int_list_set(value))
     except:
         raise ValueError('cal_monitor')
     value = []
     for v in values:
         if 0 > v > 6:
             raise ValueError('cal_monitor')
         if v != 0:
             value.append(v)
     return value
Ejemplo n.º 3
0
 def val_channels(self, value):
     if type(value) != str:
         raise TypeError('channels')
     try:
         channels = QTools.expand_int_list_set(value)
     except ValueError:
         raise ValueError('channels')
     value = int(0)
     for channel in channels:
         if 1 > channel > 6:
             raise ValueError('channels')
         value |= 1 << (channel - 1)
     if 1 > value > 63:
         raise ValueError('channels')
     return value
Ejemplo n.º 4
0
    def _run(self):
        QTools.assert_arg_count(self.args, 'gte', 1)

        arg_count = 3
        if self.args[0] == 'indices':
            print "Section Indices:"
            for value in sorted(Profile.section_map.values()):
                index,_,description,_,_ = value
                print "  % 3d : %s" % (index, description)
            return
        elif self.args[0] == 'list':
            QTools.assert_arg_count(self.args, 'eq', 2)
            config_file = self.args[1]
            print "Reading clone from %s ..." % os.path.abspath(config_file)
            profile = Profile.getProfileFromFile(config_file)
            profile.listFileContents()
            return
        elif self.args[0] == 'diff':
            QTools.assert_arg_count(self.args, 'eq', 3)
            file1 = self.args[1]
            file2 = self.args[2]

            print "Reading configuration from %s..." % file1,
            sys.stdout.flush()
            try:
                profile1 = Profile.getProfileFromFile(file1)
            except:
                print "Failed!"
                return
            print "Done."

            print "Reading configuration from %s..." % file2,
            sys.stdout.flush()
            try:
                profile2 = Profile.getProfileFromFile(file2)
            except:
                print "Failed!"
                return
            print "Done."
            profile1.diff(profile2)
            return

        if (len(self.args) > 1) and (self.args[1] == 'edit'):
            arg_count = 2

        QTools.assert_arg_count(self.args, 'eq', arg_count)
        arg_device_id = self.args[0]
        try:
            int(arg_device_id)
        except:
            raise QTools.QExArgs("invalid type for argument 'device'")
        if not self.comm.set_from_file(arg_device_id, self.options.reg_file):
            raise QTools.QExArgs("invalid entry for Q330 #%d in configuration" % int(arg_device_id))

        config_count   = 0
        config_type    = ''
        config_subset  = None
        mysql_password = ''
        if self.options.subset and len(self.options.subset):
            try:
                config_subset = QTools.expand_int_list_set(self.options.subset)
            except ValueError:
                raise QTools.QExArgs("invalid value(s) for option '--subset'")
        if self.options.config_file:
            config_info = self.options.config_file
            config_type = 'file'
            config_count += 1
        if self.options.config_sqlite:
            if not Store.SQLITE:
                raise QTools.QExMessage("SQLite support is not included with this python install")
            config_info = self.options.config_sqlite
            config_type = 'sqlite'
            config_count += 1
        if self.options.config_mysql:
            if not Store.MYSQL:
                raise QTools.QExMessage("MySQL support is not included with this python install")
            config_info = self.options.config_mysql
            config_type = 'mysql'
            config_count += 1
        if self.options.config_text:
            config_info = self.options.config_text
            config_type = 'text'
            config_count += 1
        if self.options.mysql_passwd:
            mysql_password = self.options.mysql_passwd

        try:
            action = QClone.QClone()
            action.action = self.args[1]
            if action.action != "edit":
                action.file = self.args[2]
            action.subset    = config_subset
            action.verbosity = self.options.verbosity
            action.mysql_password = mysql_password
            if self.options.max_tries:
                action.tries = self.options.max_tries
            if self.options.force:
                action.confirm = False
            if config_count > 1:
                raise QTools.QExArgs("You may only select one of --config-[file|sqlite|mysql|text]")
            elif config_count == 1:
                action.config = (config_type, config_info)
            if self.options.write_base_port:
                action.write_base_port = True
            if self.options.write_ethernet_ip_address:
                action.write_ethernet_ip_address = True
            if self.options.write_ethernet_mac_address:
                action.write_ethernet_mac_address = True
            if self.options.write_slave_processor_parameters:
                action.write_slave_processor_parameters = True
            if self.options.write_web_page:
                action.write_web_page = True
        except TypeError, msg:
            raise QTools.QExArgs("invalid type for argument '%s'" % msg.__str__())