extras-buildsys/builder builder.py,1.30,1.31

Daniel Williams (dcbw) fedora-extras-commits at redhat.com
Thu Aug 11 19:32:34 UTC 2005


Author: dcbw

Update of /cvs/fedora/extras-buildsys/builder
In directory cvs-int.fedora.redhat.com:/tmp/cvs-serv10667/builder

Modified Files:
	builder.py 
Log Message:
2005-08-11  Dan Williams <dcbw at redhat.com>

    * plague.spec
        - Clean up to Fedora Extras standards in preparation for package submission

    * builder/builder.py
        - Don't ignore mock output during the 'cleanup' stage
        - Make the process() function less byzantine by moving each step to a
            separate function and using getattr() to call them, like in
            PackageJob.py on the server

    * www/*
        - Clean up error handling so it actually works all the time intead of
            returning Error 500 Internal Server Error when, for example, the
            build server isn't running

    Patch from Ville Skyttä <ville.skytta at iki.fi>
    * www/template/head.psp
      www/indiv.psp
        - Use HTTP GET instead of POST to stop nags about form data resubmission




Index: builder.py
===================================================================
RCS file: /cvs/fedora/extras-buildsys/builder/builder.py,v
retrieving revision 1.30
retrieving revision 1.31
diff -u -r1.30 -r1.31
--- builder.py	8 Aug 2005 02:54:10 -0000	1.30
+++ builder.py	11 Aug 2005 19:32:32 -0000	1.31
@@ -280,9 +280,8 @@
         return contents
 
     def _grab_mock_output(self):
-        # We don't care about output from the 'cleanup' stage
-        if self._pobj and self._status != 'cleanup':
-            # Grab any mock output and write it to a log
+        """ Grab mock output and write it to a log """
+        if self._pobj:
             string = ' '
             while len(string) > 0:
                 try:
@@ -293,9 +292,11 @@
                     else:
                         self.log("Error reading mock output: %s\n" % e)
                 else:
-                    self._log_fd.write(string)
-                    self._log_fd.flush()
-                    os.fsync(self._log_fd.fileno())
+                    # We don't care about output from the 'cleanup' stage
+                    if self._status != 'cleanup':
+                        self._log_fd.write(string)
+                        self._log_fd.flush()
+                        os.fsync(self._log_fd.fileno())
 
     def _mock_done(self):
         # Ensure child mock is reaped
@@ -317,61 +318,72 @@
             self._log_fd.close()
             self._log_fd = None
 
+    def _status_init(self):
+        pass
+
+    def _status_downloading(self):
+        pass
+
+    def _status_downloaded(self):
+        # We can't start doing anything with yum until the build
+        # server tells us the repo is unlocked.
+        if not self._repo_locked:
+            self._build()
+        else:
+            # Only show this message once
+            if not self._repo_locked_msg:
+                self.log("Waiting for repository to unlock before starting the build...\n")
+                self._repo_locked_msg = True
+
+    def _status_prepping(self):
+        if not self._mock_config and self._mock_is_prepping():
+            self._mock_config = self._read_mock_config()
+        if not self._mock_using_repo():
+            self._status = 'building'
+
+    def _status_building(self):
+        exit_status = self._pobj.poll()
+        if exit_status == 0:
+            # mock completed successfully
+            if self._status != 'building':
+                self.log("Bad job end status %s encountered!" % self._status)
+            self._done_status = 'done'
+            self._cleanup()
+        elif exit_status > 0:
+            # mock exited with an error
+            self._done_status = 'failed'
+            self._cleanup()
+
+    def _status_cleanup(self):
+        exit_status = self._pobj.poll()
+        if exit_status >= 0:
+            # Mock exited
+            self._status = self._done_status
+            if self._mock_config and self._mock_config.has_key('rootdir') and self._mock_config.has_key('statedir'):
+                # Kill the entire job dir, not just the rootdir
+                job_dir = os.path.normpath(self._mock_config['rootdir'] + "/../")
+                job_dir2 = os.path.normpath(self._mock_config['statedir'] + "/../")
+                print job_dir, job_dir2
+
+                # Be a little paranoid about randomly removing an entire directory.
+                # Compare the rootdir's parent to the statedir's parent and remove the
+                # parent only if they match.
+                if job_dir == job_dir2:
+                    shutil.rmtree(job_dir, ignore_errors=True)
+                else:
+                    shutil.rmtree(self._mock_config['rootdir'], ignore_errors=True)
+
     def process(self):
         if self.is_done_status():
             return
 
-        if self._status == 'downloading':
-            pass
-        elif self._status == 'downloaded':
-            # We can't start doing anything with yum until the build
-            # server tells us the repo is unlocked.
-            if not self._repo_locked:
-                self._build()
-            else:
-                # Only show this message once
-                if not self._repo_locked_msg:
-                    self.log("Waiting for repository to unlock before starting the build...\n")
-                    self._repo_locked_msg = True
-        elif self._status == 'prepping':
-            if not self._mock_config and self._mock_is_prepping():
-                self._mock_config = self._read_mock_config()
-            if not self._mock_using_repo():
-                self._status = 'building'
-        elif self._status == 'building':
-            exit_status = self._pobj.poll()
-            if exit_status == 0:
-                # mock completed successfully
-                if self._status != 'building':
-                    self.log("Bad job end status %s encountered!" % self._status)
-                self._done_status = 'done'
-                self._cleanup()
-            elif exit_status > 0:
-                # mock exited with an error
-                self._done_status = 'failed'
-                self._cleanup()
-            else:
-                # mock still running
-                pass
-        elif self._status == 'cleanup':
-            exit_status = self._pobj.poll()
-            if exit_status >= 0:
-                # We ignore mock errors when cleaning the buildroot
-                self._status = self._done_status
-                if self._mock_config and self._mock_config.has_key('rootdir') and self._mock_config.has_key('statedir'):
-                    # Kill the entire job dir, not just the rootdir
-                    job_dir = os.path.normpath(self._mock_config['rootdir'] + "/../")
-                    job_dir2 = os.path.normpath(self._mock_config['statedir'] + "/../")
-                    # Be a little paranoid about randomly removing an entire directory.
-                    # Compare the rootdir's parent to the statedir's parent and remove the
-                    # parent only if they match.
-                    if job_dir == job_dir2:
-                        shutil.rmtree(job_dir, ignore_errors=True)
-                    else:
-                        shutil.rmtree(self._mock_config['rootdir'], ignore_errors=True)
-            else:
-                # mock still running
-                pass
+        # Execute operations for our current status
+        try:
+            func = getattr(self, "_status_%s" % self._status)
+            func()
+        except AttributeError:
+            self.log("ERROR: internal builder inconsistency, didn't recognize status '%s'." % self._status)
+            self._status = 'failed'
 
         self._grab_mock_output()
         if self.is_done_status():




More information about the scm-commits mailing list