Esempio n. 1
0
   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')
Esempio n. 2
0
    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')