extras-buildsys/server PackageJob.py,1.16,1.17

Daniel Williams (dcbw) fedora-extras-commits at redhat.com
Thu Aug 4 11:47:09 UTC 2005


Author: dcbw

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

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

    * server/PackageJob.py
        - Clean up job files when the job is done.  We now only
            keep logs and 1 SRPM in 'server_work_dir', the RPMs
            get copied to the repo and then deleted from server_work_dir




Index: PackageJob.py
===================================================================
RCS file: /cvs/fedora/extras-buildsys/server/PackageJob.py,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -r1.16 -r1.17
--- PackageJob.py	2 Aug 2005 04:10:32 -0000	1.16
+++ PackageJob.py	4 Aug 2005 11:47:07 -0000	1.17
@@ -130,7 +130,7 @@
         self.repo = repo
         self.no_cvs = config_opts['use_srpm_not_cvs']
         self.cvs_tag = cvs_tag
-        self.stage_dir = None
+        self.result_dir = None
         self.srpm_path = None
         self.srpm_http_path = None
         self.repofiles = {}
@@ -256,17 +256,6 @@
 
         return (build_arches, pkg_arches, allowed_arches)
 
-
-    def _make_stage_dir(self, rootdir):
-        # The dir will look like this:
-        # <rootdir>/devel/95-foo-1.1.0-23
-        pkgsubdir = '%d-%s-%s-%s' % (self.uid, self.name, self.ver, self.release)
-        stage_dir = os.path.join(rootdir, self.target, pkgsubdir)
-        if os.path.exists(stage_dir):
-            shutil.rmtree(stage_dir, ignore_errors=True)
-        os.makedirs(stage_dir)
-        return stage_dir
-
     def _stage_initialize(self):
         self._set_cur_stage('checkout_wait')
         self.bm.queue_checkout_wait(self)
@@ -356,6 +345,16 @@
         self._set_cur_stage('prep')
         return False
 
+    def _make_stage_dir(self, rootdir):
+        # The dir will look like this:
+        # <rootdir>/devel/95-foo-1.1.0-23
+        pkgsubdir = '%d-%s-%s-%s' % (self.uid, self.name, self.ver, self.release)
+        stage_dir = os.path.join(rootdir, self.target, pkgsubdir)
+        if os.path.exists(stage_dir):
+            shutil.rmtree(stage_dir, ignore_errors=True)
+        os.makedirs(stage_dir)
+        return stage_dir
+
     def _stage_prep(self):
 
         # In SRPM-only mode, cvs_tag is path to the SRPM to build
@@ -381,24 +380,17 @@
 """ % (self.cvs_tag, pkg_arches, allowed_arches)
             raise PrepError(msg)
 
-        self.stage_dir = self._make_stage_dir(config_opts['server_work_dir'])
+        self.result_dir = self._make_stage_dir(config_opts['server_work_dir'])
         for arch in self.archjobs.keys():
-            thisdir = os.path.join(self.stage_dir, arch)
+            thisdir = os.path.join(self.result_dir, arch)
             if not os.path.exists(thisdir):
                 os.makedirs(thisdir)
 
-        # Copy the SRPM to the final package product dir
-        srpm = os.path.basename(self.srpm_path)
-        srpm_in_dir = os.path.join(self.stage_dir, srpm)
-        if os.path.exists(srpm_in_dir):
-            os.unlink(srpm_in_dir)
-        shutil.copy(self.srpm_path, self.stage_dir)
-
-        # Must also copy SRPM to where the build client can get it over HTTP
+        # Copy SRPM to where the builder can access it
         http_pkg_path = self._make_stage_dir(self.http_dir)
-        self.srpm_http_path = os.path.join(http_pkg_path, srpm)
+        self.srpm_http_path = os.path.join(http_pkg_path, os.path.basename(self.srpm_path))
         shutil.copy(self.srpm_path, self.srpm_http_path)
-        self.srpm_path = srpm_in_dir
+        self.srpm_path = None
 
         # Remove CVS checkout and make_srpm dirs
         if not self.no_cvs:
@@ -532,14 +524,41 @@
         return True
 
     def get_stage_dir(self):
-        return self.stage_dir
+        return self.result_dir
 
     def _stage_failed(self, msg=None):
         self.result = 'failed'
         self._set_cur_stage('failed', msg)
         self.endtime = time.time()
+        self._cleanup_job_files()
         self.bm.notify_job_done(self)
-        
+
+    def _cleanup_job_files(self):
+        srpm_file = os.path.join(self.result_dir, os.path.basename(self.srpm_http_path))
+
+        # Delete any RPMs in the arch dirs
+        for job in self.archjobs.values():
+            if not job:
+                continue
+            for f in job.get_files():
+                if not f.endswith(".rpm"):
+                    continue
+                src_file = os.path.join(self.result_dir, job.arch, f)
+                if src_file.endswith(".src.rpm"):
+                    # Keep an SRPM.  We prefer built SRPMs from builders over
+                    # the original SRPM.
+                    if not os.path.exists(srpm_file):
+                        shutil.copy(src_file, srpm_file)
+                else:
+                    os.remove(src_file)
+
+        # If there were no builder-built SRPMs, keep the original around
+        if not os.path.exists(srpm_file):
+            shutil.copy(self.srpm_http_path, srpm_file)
+
+        # Delete the SRPM in the server's HTTP dir
+        shutil.rmtree(os.path.dirname(self.srpm_http_path), ignore_errors=True)
+
     def _stage_add_to_repo(self):
         # Create a list of files that the repo should copy to
         # the repo dir
@@ -549,7 +568,7 @@
             for f in job.get_files():
                 if not f.endswith(".rpm"):
                     continue
-                src_file = os.path.join(self.stage_dir, job.arch, f)
+                src_file = os.path.join(self.result_dir, job.arch, f)
                 verrel = "%s-%s" % (self.ver, self.release)
                 if f.endswith(".src.rpm"):
                     dst_path = os.path.join(config_opts['repo_dir'], self.target, self.name, verrel, "SRPM")
@@ -577,6 +596,8 @@
         self.result = 'success'
         self._set_cur_stage('needsign', resultstring)
 
+        self._cleanup_job_files()
+
         log_url = make_job_log_url(self.target, self.uid, self.name, self.ver, self.release)
         resultstring = resultstring + "\n     Build logs may be found at %s\n" % (log_url)
         self.email_result(self.username, resultstring)




More information about the scm-commits mailing list