コード例 #1
0
ファイル: System.py プロジェクト: fquivira/cos
    def load(self, desc=''):
        db = Configurable.__db__

        conf = db.open(type='configuration', mode='r')
        db.close('configuration')

        if not desc in conf:
            error(
                self, 'A configuration with the description \'' + desc +
                '\' does not exist')
            raise Exception('')
            return

#      id = self.getConfId(desc, conf)
#      if id != None:
#         self.__id__ = id
#      else:
#         error(self, 'A configuration with the description \''+desc+'\' does not exist')

# Remove the date and description
        conf[desc].pop('date')
        conf[desc].pop('desc')

        # Open the database
        db_root = db.open(type='system', mode='a')

        # Let the fun begin getattr(db_root,'i%d'%self.__id__)
        Configurable.__load__(self, db_root, conf[desc]['s'])

        # Close the database
        db.close()

        Configurable.__refreshEclipse__(self)
コード例 #2
0
ファイル: System.py プロジェクト: jpaasen/cos
   def load(self, desc=''):
      db = Configurable.__db__
      
      conf = db.open(type='configuration', mode='r')
      db.close('configuration')
      
      if not desc in conf:
         error(self, 'A configuration with the description \''+desc+'\' does not exist')
         raise Exception('')
         return

#      id = self.getConfId(desc, conf)
#      if id != None:
#         self.__id__ = id
#      else:
#         error(self, 'A configuration with the description \''+desc+'\' does not exist')
               
      # Remove the date and description
      conf[desc].pop('date')
      conf[desc].pop('desc')

      # Open the database
      db_root = db.open(type='system', mode='a')
      
      # Let the fun begin getattr(db_root,'i%d'%self.__id__)
      Configurable.__load__(self, db_root, conf[desc]['s'])
            
      # Close the database
      db.close() 

      Configurable.__refreshEclipse__(self)
コード例 #3
0
ファイル: System.py プロジェクト: fquivira/cos
 def __getitem__(self, *keys):
     no_keys = keys.__len__()
     if no_keys == 0:
         return
     elif no_keys == 1:
         return Configurable.findAttr(self, keys[0])
     else:
         vals = []
         for key in keys:
             vals.append(Configurable.findAttr(self, key))
         return vals
コード例 #4
0
ファイル: System.py プロジェクト: jpaasen/cos
 def __getitem__(self, *keys):
    no_keys = keys.__len__()
    if no_keys == 0:
       return
    elif no_keys == 1:
       return Configurable.findAttr(self, keys[0])
    else:
       vals = []
       for key in keys:
          vals.append(Configurable.findAttr(self, key))
       return vals
コード例 #5
0
ファイル: System.py プロジェクト: jpaasen/cos
   def save(self, desc=''):

      if desc == '':
         if 'desc' in self.__dict__:
            desc = self.desc
      else:
         self.desc = desc

      
      # Save data to DB
      # Save configuration to Conf
      db = Configurable.__db__
             
      # Select the slot with the given description, or make it if it does not exist
      full_conf = db.open(type='configuration', mode='r')
      db.close('configuration')
      
      if desc in full_conf:
         conf = full_conf[desc]
      else:
         conf = None

      # Let the recursive fun begin..
      # Read the current configuration
      db_root = db.open(type='system', mode='a')
      new_conf = {}
      Configurable.__save__(self, db_root, 's', conf, new_conf)
      
      # Save and close the database
      db.flush()
      db.close()
      
      # Now, let us save the corresponding configuration
#      new_conf = new_conf.pop('%d'%self.__id__)
#      new_conf = new_conf.pop('class_attr')
      
      # Add the time of modification
      dt = datetime.today()
      new_conf['date'] = dt.strftime("%y.%m.%d - %H:%M:%S")
#      conf['id']   = int(time.mktime(dt.timetuple()))
      new_conf['desc'] = desc
            
      # Add the new contents
      full_conf[desc] = new_conf
        
      # Save the configuration back
      db.open(type='configuration', mode='w')
      db.dump(full_conf)
      db.close('configuration')
コード例 #6
0
ファイル: System.py プロジェクト: fquivira/cos
    def save(self, desc=''):

        if desc == '':
            if 'desc' in self.__dict__:
                desc = self.desc
        else:
            self.desc = desc

        # Save data to DB
        # Save configuration to Conf
        db = Configurable.__db__

        # Select the slot with the given description, or make it if it does not exist
        full_conf = db.open(type='configuration', mode='r')
        db.close('configuration')

        if desc in full_conf:
            conf = full_conf[desc]
        else:
            conf = None

        # Let the recursive fun begin..
        # Read the current configuration
        db_root = db.open(type='system', mode='a')
        new_conf = {}
        Configurable.__save__(self, db_root, 's', conf, new_conf)

        # Save and close the database
        db.flush()
        db.close()

        # Now, let us save the corresponding configuration
        #      new_conf = new_conf.pop('%d'%self.__id__)
        #      new_conf = new_conf.pop('class_attr')

        # Add the time of modification
        dt = datetime.today()
        new_conf['date'] = dt.strftime("%y.%m.%d - %H:%M:%S")
        #      conf['id']   = int(time.mktime(dt.timetuple()))
        new_conf['desc'] = desc

        # Add the new contents
        full_conf[desc] = new_conf

        # Save the configuration back
        db.open(type='configuration', mode='w')
        db.dump(full_conf)
        db.close('configuration')
コード例 #7
0
ファイル: KeyStore.py プロジェクト: atlas-control/control
    def __str__( self, indent = 0,
                 headerLastIndentUnit=Configurable.indentUnit ):
        global msg  # to print some info depending on output level
        indentStr = indent * Configurable.indentUnit
        # print header
        title = "%s/%s" % ( self.__class__.__name__, self._name )

        # print line to easily see start-of-configurable
        if indent > 0:
            headerIndent = (indent-1)*Configurable.indentUnit \
                           + headerLastIndentUnit
        else:
            headerIndent = ''

        rep = Configurable._printHeader( headerIndent, title )
        rep += os.linesep

        # print own properties
        props = self.getProperties()
        if not props:
            #rep += indentStr + '|-<no output-item-list>' + os.linesep
            rep += indentStr + '| ' + os.linesep
        else:
            # get property name with
            nameWidth = 0
            for p in props.keys():
                nameWidth=max(nameWidth,len(p))
            for p, v in props.items():
                # start with indent and property name
                prefix = indentStr + '|-%-*s' % (nameWidth,p)
                # add memory address for debugging (not for defaults)
                if msg.isEnabledFor( logging.DEBUG ):
                    address = ' @%11s' % hex(id(v))
                    prefix += address
                # add value and default
                strVal = repr(v)
                # add the value
                line = prefix + ' = ' + strVal
                # add the line to the total string
                rep += line + os.linesep
        # print configurables + their properties, or loop over sequence
        for cfg in self.allChildren():
            rep += cfg.__str__( indent + 1, '|=' ) + os.linesep

        # print line to easily see end-of-configurable. Note: No linesep!
        rep += Configurable._printFooter( indentStr, title )
        return rep
コード例 #8
0
    def __str__( self, indent = 0,
                 headerLastIndentUnit=Configurable.indentUnit ):
        global msg  # to print some info depending on output level
        indentStr = indent * Configurable.indentUnit
        # print header
        title = "%s/%s" % ( self.__class__.__name__, self._name )

        # print line to easily see start-of-configurable
        if indent > 0:
            headerIndent = (indent-1)*Configurable.indentUnit \
                           + headerLastIndentUnit
        else:
            headerIndent = ''

        rep = Configurable._printHeader( headerIndent, title )
        rep += os.linesep

        # print own properties
        props = self.getProperties()
        if not props:
            #rep += indentStr + '|-<no output-item-list>' + os.linesep
            rep += indentStr + '| ' + os.linesep
        else:
            # get property name with
            nameWidth = 0
            for p in props.keys():
                nameWidth=max(nameWidth,len(p))
            for p, v in props.items():
                # start with indent and property name
                prefix = indentStr + '|-%-*s' % (nameWidth,p)
                # add memory address for debugging (not for defaults)
                if msg.isEnabledFor( logging.DEBUG ):
                    address = ' @%11s' % hex(id(v))
                    prefix += address
                # add value and default
                strVal = repr(v)
                # add the value
                line = prefix + ' = ' + strVal
                # add the line to the total string
                rep += line + os.linesep
        # print configurables + their properties, or loop over sequence
        for cfg in self.allChildren():
            rep += cfg.__str__( indent + 1, '|=' ) + os.linesep

        # print line to easily see end-of-configurable. Note: No linesep!
        rep += Configurable._printFooter( indentStr, title )
        return rep
コード例 #9
0
ファイル: KeyStore.py プロジェクト: atlas-control/control
    def __str__( self, indent = 0,
                 headerLastIndentUnit=Configurable.indentUnit ):
        
        global msg  # to print some info depending on output level
        indentStr = indent * Configurable.indentUnit
        # print header
        title = "%s/%s" % ( self.__class__.__name__, self._name )

        # print line to easily see start-of-configurable
        if indent > 0:
            headerIndent = (indent-1)*Configurable.indentUnit \
                           + headerLastIndentUnit
        else:
            headerIndent = ''

        rep = Configurable._printHeader( headerIndent, title )
        rep += os.linesep

        rep += self._items.__str__( indent + 1, '|=' ) + os.linesep
        # print line to easily see end-of-configurable. Note: No linesep!
        rep += Configurable._printFooter( indentStr, title )
        return rep
コード例 #10
0
    def __str__( self, indent = 0,
                 headerLastIndentUnit=Configurable.indentUnit ):
        
        global msg  # to print some info depending on output level
        indentStr = indent * Configurable.indentUnit
        # print header
        title = "%s/%s" % ( self.__class__.__name__, self._name )

        # print line to easily see start-of-configurable
        if indent > 0:
            headerIndent = (indent-1)*Configurable.indentUnit \
                           + headerLastIndentUnit
        else:
            headerIndent = ''

        rep = Configurable._printHeader( headerIndent, title )
        rep += os.linesep

        rep += self._items.__str__( indent + 1, '|=' ) + os.linesep
        # print line to easily see end-of-configurable. Note: No linesep!
        rep += Configurable._printFooter( indentStr, title )
        return rep