[Erp5-report] r36137 luke - /erp5/trunk/utils/erp5.timmy/src/erp5/timmy/timmy.py

nobody at svn.erp5.org nobody at svn.erp5.org
Wed Jun 9 10:54:17 CEST 2010


Author: luke
Date: Wed Jun  9 10:54:16 2010
New Revision: 36137

URL: http://svn.erp5.org?rev=36137&view=rev
Log:
 - more class like methods
 - rename startAllSupervisor to startAllSupervisored to reflect real usage of method

Modified:
    erp5/trunk/utils/erp5.timmy/src/erp5/timmy/timmy.py

Modified: erp5/trunk/utils/erp5.timmy/src/erp5/timmy/timmy.py
URL: http://svn.erp5.org/erp5/trunk/utils/erp5.timmy/src/erp5/timmy/timmy.py?rev=36137&r1=36136&r2=36137&view=diff
==============================================================================
--- erp5/trunk/utils/erp5.timmy/src/erp5/timmy/timmy.py [utf8] (original)
+++ erp5/trunk/utils/erp5.timmy/src/erp5/timmy/timmy.py [utf8] Wed Jun  9 10:54:16 2010
@@ -451,7 +451,7 @@
         try:
           self.server = XMLRPCServer(self.options.server_url,
               getServerKey(self.options.key_file))
-          partition_dict_list = self.server.call('getComputerConfigurationDictList')
+          self.partition_dict_list = self.server.call('getComputerConfigurationDictList')
         except socket.error, e:
           logging.error('Unable to connect to remote server, verify if the URL is'
               ' accessible.')
@@ -465,7 +465,7 @@
         self.server.call('updatePartitionState', self.computer_id, 'reportStarted',
             'timmy is running on computer')
         self.supervisor_id = self.computer_id
-        supervisor_list = [q for q in partition_dict_list if q['TYPE'] == \
+        supervisor_list = [q for q in self.partition_dict_list if q['TYPE'] == \
             'Supervisor Server']
         if len(supervisor_list) > 0:
           self.supervisor_id = supervisor_list[0]['PARTITION_ID']
@@ -499,34 +499,19 @@
             logging.info(log_message)
 
         # 1a pass - instance profiles
-        try:
-          self.updateInstanceProfiles(self.template_directory_list,
-            self.options.instances_directory, partition_dict_list)
-        except:
-          self.server.call('updatePartitionState', self.computer_id, 'reportError',
-              'Unexpected issue while updating instance profiles: %s:%s' % (
-                str(sys.exc_info()[0]), str(sys.exc_info()[1])))
-          raise
+        self.updateInstanceProfiles()
         # 1b pass - main profile
-        try:
-          self.updateBaseProfile(self.template_directory_list, self.options.main_output,
-            self.options.base_profile, self.options.instances_directory,
-            partition_dict_list)
-        except:
-          self.server.call('updatePartitionState', self.computer_id, 'reportError',
-              'Unexpected issue while updating base profile: %s:%s' % (
-                str(sys.exc_info()[0]), str(sys.exc_info()[1])))
-          raise
+        self.updateBaseProfile()
         # 2 pass - run buildout
         self.runBuildout()
         self.updateSupervisor()
-        self.startAllSupervisor()
+        self.startAllSupervisored()
 
         # 3 pass - manage instances
         # XXX-Luke: To be moved to proper recipe
         updated_partition_list = []
         helper = Helper()
-        for partition_dict in partition_dict_list:
+        for partition_dict in self.partition_dict_list:
           # install
           # stop
           # switch to special management
@@ -587,76 +572,89 @@
           'Buildout finished with bad status code (%s). Stdout = "%s", stde'
           'rr = "%s"' % (popen.returncode, result_std, result_err))
 
-  def updateInstanceProfiles(self, template_directory_list, output_directory,
-      instance_dict_list):
-    for instance in instance_dict_list:
-      template_name = '%s-template.cfg' % instance['TYPE'].lower()\
-        .replace(' ','-')
-      template_path = self.findTemplate(template_directory_list, template_name)
-      if template_path is None:
-        logging.warning('Template %r for %s not found, ignoring' % (template_name,
-          instance['TYPE']))
-        continue
-      template_data = ''.join(file(template_path).readlines())
-
-      template = PercentTemplate(template_data)
-      if 'BT5_LIST' in instance:
-        instance['BT5_LIST'] = '\n  '.join(instance['BT5_LIST'])
-      if 'IP_ADDRESS_LIST' in instance:
-        if instance['IP_ADDRESS_LIST']:
-          instance['IP_ADDRESS'] = instance['IP_ADDRESS_LIST'][0]
-      out = file(os.path.join(output_directory, '%s.cfg' % instance['ID']), 'w')
-      out.write(template.substitute(instance))
-      out.close()
-
-  def findTemplate(self, template_directory_list, template_name):
-    for template_directory in template_directory_list:
+  def updateInstanceProfiles(self):
+    try:
+      for instance in self.partition_dict_list:
+        template_name = '%s-template.cfg' % instance['TYPE'].lower()\
+          .replace(' ','-')
+        template_path = self.findTemplate(template_name)
+        if template_path is None:
+          logging.warning('Template %r for %s not found, ignoring' % (
+            template_name, instance['TYPE']))
+          continue
+        template_data = ''.join(file(template_path).readlines())
+
+        template = PercentTemplate(template_data)
+        if 'BT5_LIST' in instance:
+          instance['BT5_LIST'] = '\n  '.join(instance['BT5_LIST'])
+        if 'IP_ADDRESS_LIST' in instance:
+          if instance['IP_ADDRESS_LIST']:
+            instance['IP_ADDRESS'] = instance['IP_ADDRESS_LIST'][0]
+        out = file(os.path.join(self.options.instances_directory, '%s.cfg' %
+          instance['ID']), 'w')
+        out.write(template.substitute(instance))
+        out.close()
+    except:
+      self.server.call('updatePartitionState', self.computer_id, 'reportError',
+          'Unexpected issue while updating instance profiles: %s:%s' % (
+            str(sys.exc_info()[0]), str(sys.exc_info()[1])))
+      raise
+
+  def findTemplate(self, template_name):
+    for template_directory in self.template_directory_list:
       path = os.path.join(template_directory, template_name)
       if os.path.isfile(path):
         logging.debug('Found template %r' % path)
         return path
     return None
 
-  def updateBaseProfile(self, template_directory_list, file_output, base_profile,
-      instances_directory, instance_dict_list):
+  def updateBaseProfile(self):
     # TODO:
     #  * cleanup in case of problem
     #  * use safe update of output file
-    template_data = ''.join(file(self.findTemplate(template_directory_list,
-      'main-template.cfg')).readlines())
-    template = PercentTemplate(template_data)
-    replacement_dict = {
-      'BASE_PROFILE': base_profile,
-      'INSTANCE_PROFILE_LIST': [],
-      'INSTANCE_PART_LIST': []
-    }
-    for instance in [q for q in instance_dict_list if q['TYPE'] != 'Zope Instance']:
-      profile_path = os.path.join(instances_directory,
-          '%s.cfg' % instance['ID'])
-      if not os.path.exists(profile_path):
-        logging.warning('Profile %r not generated, ignoring' % profile_path)
-        continue
-      replacement_dict['INSTANCE_PROFILE_LIST'].append('%s/%s.cfg' % (
-        instances_directory, instance['ID']))
-      replacement_dict['INSTANCE_PART_LIST'].append(instance['ID'])
-
-    for instance in [q for q in instance_dict_list if q['TYPE'] == 'Zope Instance']:
-      profile_path = os.path.join(instances_directory,
-          '%s.cfg' % instance['ID'])
-      if not os.path.exists(profile_path):
-        logging.warning('Profile %r not generated' % profile_path)
-        continue
-      replacement_dict['INSTANCE_PROFILE_LIST'].append('%s/%s.cfg' % (
-        instances_directory, instance['ID']))
-      replacement_dict['INSTANCE_PART_LIST'].append(instance['ID'])
-
-    replacement_dict['INSTANCE_PROFILE_LIST'] = '\n  '.join(
-        replacement_dict['INSTANCE_PROFILE_LIST'])
-    replacement_dict['INSTANCE_PART_LIST'] = '\n  '.join(
-        replacement_dict['INSTANCE_PART_LIST'])
-    out = file(file_output, 'w')
-    out.write(template.substitute(replacement_dict))
-    out.close()
+    try:
+      template_data = ''.join(file(self.findTemplate('main-template.cfg')).\
+          readlines())
+      template = PercentTemplate(template_data)
+      replacement_dict = {
+        'BASE_PROFILE': self.options.base_profile,
+        'INSTANCE_PROFILE_LIST': [],
+        'INSTANCE_PART_LIST': []
+      }
+      for instance in [q for q in self.partition_dict_list \
+          if q['TYPE'] != 'Zope Instance']:
+        profile_path = os.path.join(self.options.instances_directory,
+            '%s.cfg' % instance['ID'])
+        if not os.path.exists(profile_path):
+          logging.warning('Profile %r not generated, ignoring' % profile_path)
+          continue
+        replacement_dict['INSTANCE_PROFILE_LIST'].append('%s/%s.cfg' % (
+          self.options.instances_directory, instance['ID']))
+        replacement_dict['INSTANCE_PART_LIST'].append(instance['ID'])
+
+      for instance in [q for q in self.partition_dict_list \
+          if q['TYPE'] == 'Zope Instance']:
+        profile_path = os.path.join(self.options.instances_directory,
+            '%s.cfg' % instance['ID'])
+        if not os.path.exists(profile_path):
+          logging.warning('Profile %r not generated' % profile_path)
+          continue
+        replacement_dict['INSTANCE_PROFILE_LIST'].append('%s/%s.cfg' % (
+          self.options.instances_directory, instance['ID']))
+        replacement_dict['INSTANCE_PART_LIST'].append(instance['ID'])
+
+      replacement_dict['INSTANCE_PROFILE_LIST'] = '\n  '.join(
+          replacement_dict['INSTANCE_PROFILE_LIST'])
+      replacement_dict['INSTANCE_PART_LIST'] = '\n  '.join(
+          replacement_dict['INSTANCE_PART_LIST'])
+      out = file(self.options.main_output, 'w')
+      out.write(template.substitute(replacement_dict))
+      out.close()
+    except:
+      self.server.call('updatePartitionState', self.computer_id, 'reportError',
+          'Unexpected issue while updating base profile: %s:%s' % (
+            str(sys.exc_info()[0]), str(sys.exc_info()[1])))
+      raise
 
   def setRunning(self, value, pid_file):
     if value:
@@ -761,7 +759,7 @@
           log_message)
       logging.error(log_message)
 
-  def startAllSupervisor(self):
+  def startAllSupervisored(self):
     """Invoke start on all supervisor controlled programs
 
     It is no-op in case of running program, but forces start of problematic




More information about the Erp5-report mailing list