From efc4c9bcfff5fdc47f524e8d3502ef25df1eb55e Mon Sep 17 00:00:00 2001 From: Yuming Zhu Date: Jun 20 2017 13:32:19 +0000 Subject: change `run_plugin` to `run_callbacks` and remove the modification for kojikamid.py --- diff --git a/builder/kojid b/builder/kojid index 047cdaf..33c2bd8 100755 --- a/builder/kojid +++ b/builder/kojid @@ -1415,13 +1415,13 @@ class BuildMavenTask(BaseBuildTask): uploadpath = self.getUploadDir() - self.run_plugin('preSCMCheckout', scminfo=scm.get_info(), build_tag=build_tag) + self.run_callbacks('preSCMCheckout', scminfo=scm.get_info(), build_tag=build_tag) # Check out sources from the SCM sourcedir = scm.checkout(scmdir, self.session, uploadpath, logfile) - self.run_plugin("postSCMCheckout", - scminfo=scm.get_info(), - scratch=opts.get('scratch'), - srcdir=sourcedir) + self.run_callbacks("postSCMCheckout", + scminfo=scm.get_info(), + scratch=opts.get('scratch'), + srcdir=sourcedir) # zip up pristine sources for auditing purposes self._zip_dir(sourcedir, os.path.join(outputdir, 'scm-sources.zip')) @@ -1431,14 +1431,14 @@ class BuildMavenTask(BaseBuildTask): patchlog = self.workdir + '/patches.log' patch_scm = SCM(self.opts.get('patches')) patch_scm.assert_allowed(self.options.allowed_scms) - self.run_plugin('preSCMCheckout', scminfo=patch_scm.get_info(), build_tag=build_tag) + self.run_callbacks('preSCMCheckout', scminfo=patch_scm.get_info(), build_tag=build_tag) # never try to check out a common/ dir when checking out patches patch_scm.use_common = False patchcheckoutdir = patch_scm.checkout(patchdir, self.session, uploadpath, patchlog) - self.run_plugin("postSCMCheckout", - scminfo=patch_scm.get_info(), - scratch=opts.get('scratch'), - srcdir=patchcheckoutdir) + self.run_callbacks("postSCMCheckout", + scminfo=patch_scm.get_info(), + scratch=opts.get('scratch'), + srcdir=patchcheckoutdir) self._zip_dir(patchcheckoutdir, os.path.join(outputdir, 'patches.zip')) # Apply patches, if present @@ -1719,12 +1719,12 @@ class WrapperRPMTask(BaseBuildTask): logfile = os.path.join(self.workdir, 'checkout.log') scmdir = buildroot.rootdir() + '/tmp/scmroot' koji.ensuredir(scmdir) - self.run_plugin('preSCMCheckout', scminfo=scm.get_info(), build_tag=build_tag) + self.run_callbacks('preSCMCheckout', scminfo=scm.get_info(), build_tag=build_tag) specdir = scm.checkout(scmdir, self.session, self.getUploadDir(), logfile) - self.run_plugin("postSCMCheckout", - scminfo=scm.get_info(), - scratch=opts.get('scratch'), - srcdir=specdir) + self.run_callbacks("postSCMCheckout", + scminfo=scm.get_info(), + scratch=opts.get('scratch'), + srcdir=specdir) spec_template = None for path, dir, files in os.walk(specdir): @@ -2658,12 +2658,12 @@ class ImageTask(BaseTaskHandler): scm = SCM(self.opts['ksurl']) scm.assert_allowed(self.options.allowed_scms) logfile = os.path.join(self.workdir, 'checkout.log') - self.run_plugin('preSCMCheckout', scminfo=scm.get_info(), build_tag=build_tag) + self.run_callbacks('preSCMCheckout', scminfo=scm.get_info(), build_tag=build_tag) scmsrcdir = scm.checkout(scmdir, self.session, self.getUploadDir(), logfile) - self.run_plugin("postSCMCheckout", - scminfo=scm.get_info(), - scratch=self.opts.get('scratch'), - srcdir=scmsrcdir) + self.run_callbacks("postSCMCheckout", + scminfo=scm.get_info(), + scratch=self.opts.get('scratch'), + srcdir=scmsrcdir) kspath = os.path.join(scmsrcdir, ksfile) else: kspath = self.localPath("work/%s" % ksfile) @@ -3276,13 +3276,13 @@ class OzImageTask(BaseTaskHandler): scm = SCM(self.opts['ksurl']) scm.assert_allowed(self.options.allowed_scms) logfile = os.path.join(self.workdir, 'checkout-%s.log' % self.arch) - self.run_plugin('preSCMCheckout', scminfo=scm.get_info(), build_tag=build_tag) + self.run_callbacks('preSCMCheckout', scminfo=scm.get_info(), build_tag=build_tag) scmsrcdir = scm.checkout(self.workdir, self.session, self.getUploadDir(), logfile) - self.run_plugin("postSCMCheckout", - scminfo=scm.get_info(), - scratch=self.opts.get('scratch'), - srcdir=scmsrcdir) + self.run_callbacks("postSCMCheckout", + scminfo=scm.get_info(), + scratch=self.opts.get('scratch'), + srcdir=scmsrcdir) kspath = os.path.join(scmsrcdir, os.path.basename(ksfile)) else: tops = dict([(k, getattr(self.options, k)) for k in 'topurl','topdir']) @@ -4087,14 +4087,14 @@ class BuildIndirectionImageTask(OzImageTask): if fileurl: scm = SCM(fileurl) scm.assert_allowed(self.options.allowed_scms) - self.run_plugin('preSCMCheckout', scminfo=scm.get_info(), build_tag=build_tag) + self.run_callbacks('preSCMCheckout', scminfo=scm.get_info(), build_tag=build_tag) logfile = os.path.join(self.workdir, 'checkout.log') scmsrcdir = scm.checkout(self.workdir, self.session, self.getUploadDir(), logfile) - self.run_plugin("postSCMCheckout", - scminfo=scm.get_info(), - scratch=self.opts.get('scratch'), - srcdir=scmsrcdir) + self.run_callbacks("postSCMCheckout", + scminfo=scm.get_info(), + scratch=self.opts.get('scratch'), + srcdir=scmsrcdir) final_path = os.path.join(scmsrcdir, os.path.basename(filepath)) else: tops = dict([(k, getattr(self.options, k)) for k in 'topurl','topdir']) @@ -4436,13 +4436,13 @@ class BuildSRPMFromSCMTask(BaseBuildTask): logfile = self.workdir + '/checkout.log' uploadpath = self.getUploadDir() - self.run_plugin('preSCMCheckout', scminfo=scm.get_info(), build_tag=build_tag) + self.run_callbacks('preSCMCheckout', scminfo=scm.get_info(), build_tag=build_tag) # Check out spec file, etc. from SCM sourcedir = scm.checkout(scmdir, self.session, uploadpath, logfile) - self.run_plugin("postSCMCheckout", - scminfo=scm.get_info(), - scratch=self.opts.get('scratch'), - srcdir=sourcedir) + self.run_callbacks("postSCMCheckout", + scminfo=scm.get_info(), + scratch=self.opts.get('scratch'), + srcdir=sourcedir) # chown the sourcedir and everything under it to the mockuser # so we can build the srpm as non-root uid = pwd.getpwnam(self.options.mockuser)[2] diff --git a/koji/tasks.py b/koji/tasks.py index 5d7ac98..a11bd3e 100644 --- a/koji/tasks.py +++ b/koji/tasks.py @@ -383,7 +383,7 @@ class BaseTaskHandler(object): return repo_info - def run_plugin(self, plugin, *args, **kwargs): + def run_callbacks(self, plugin, *args, **kwargs): if 'taskinfo' not in kwargs: try: taskinfo = self.taskinfo diff --git a/vm/kojikamid.py b/vm/kojikamid.py index 710671a..0499c74 100755 --- a/vm/kojikamid.py +++ b/vm/kojikamid.py @@ -47,20 +47,19 @@ MANAGER_PORT = 7000 KOJIKAMID = True - ## INSERT kojikamid dup class fakemodule(object): pass - -# make parts of the above insert accessible as koji.X +#make parts of the above insert accessible as koji.X koji = fakemodule() koji.GenericError = GenericError koji.BuildError = BuildError class WindowsBuild(object): + LEADING_CHAR = re.compile('^[^A-Za-z_]') VAR_CHARS = re.compile('[^A-Za-z0-9_]') @@ -137,7 +136,7 @@ class WindowsBuild(object): self.logger.info('file %s exists', entry) if errors: raise BuildError('error validating build environment: %s' % \ - ', '.join(errors)) + ', '.join(errors)) def updateClam(self): """update ClamAV virus definitions""" @@ -319,7 +318,7 @@ class WindowsBuild(object): # rpms don't have a md5sum in the fileinfo, but check it for everything else if ('md5sum' in fileinfo) and (digest != fileinfo['md5sum']): raise BuildError('md5 checksum validation failed for %s, %s (computed) != %s (provided)' % \ - (destpath, digest, fileinfo['md5sum'])) + (destpath, digest, fileinfo['md5sum'])) self.logger.info('Retrieved %s (%s bytes, md5: %s)', destpath, offset, digest) def fetchBuildReqs(self): @@ -469,7 +468,7 @@ class WindowsBuild(object): self.virusCheck(self.workdir) if errors: raise BuildError('error validating build output: %s' % \ - ', '.join(errors)) + ', '.join(errors)) def virusCheck(self, path): """ensure a path is virus free with ClamAV. path should be absolute""" @@ -500,7 +499,6 @@ class WindowsBuild(object): self.expireBuildroot() return self.gatherResults() - def run(cmd, chdir=None, fatal=False, log=True): global logfd output = '' @@ -530,7 +528,6 @@ def run(cmd, chdir=None, fatal=False, log=True): raise BuildError(msg) return ret, output - def find_net_info(): """ Find the network gateway configured for this VM. @@ -559,7 +556,6 @@ def find_net_info(): gateway = None return macaddr, gateway - def upload_file(server, prefix, path): """upload a single file to the vmd""" logger = logging.getLogger('koji.vm') @@ -580,7 +576,6 @@ def upload_file(server, prefix, path): server.verifyChecksum(path, digest, 'md5') logger.info('Uploaded %s (%s bytes, md5: %s)', destpath, offset, digest) - def get_mgmt_server(): """Get a ServerProxy object we can use to retrieve task info""" logger = logging.getLogger('koji.vm') @@ -599,7 +594,6 @@ def get_mgmt_server(): logger.debug('found task-specific port %s', task_port) return xmlrpclib.ServerProxy('http://%s:%s/' % (gateway, task_port), allow_none=True) - def get_options(): """handle usage and parse options""" usage = """%prog [options] @@ -609,12 +603,10 @@ def get_options(): parser = OptionParser(usage=usage) parser.add_option('-d', '--debug', action='store_true', help='Log debug statements') parser.add_option('-i', '--install', action='store_true', help='Install this daemon as a service', default=False) - parser.add_option('-u', '--uninstall', action='store_true', - help='Uninstall this daemon if it was installed previously as a service', default=False) + parser.add_option('-u', '--uninstall', action='store_true', help='Uninstall this daemon if it was installed previously as a service', default=False) (options, args) = parser.parse_args() return options - def setup_logging(opts): global logfile, logfd logger = logging.getLogger('koji.vm') @@ -629,13 +621,11 @@ def setup_logging(opts): logger.addHandler(handler) return handler - def log_local(msg): tb = ''.join(traceback.format_exception(*sys.exc_info())) sys.stderr.write('%s: %s\n' % (time.ctime(), msg)) sys.stderr.write(tb) - def stream_logs(server, handler, builds): """Stream logs incrementally to the server. The global logfile will always be streamed. @@ -673,7 +663,6 @@ def stream_logs(server, handler, builds): log_local('error uploading %s' % relpath) time.sleep(1) - def fail(server, handler): """do the right thing when a build fails""" global logfile, logfd @@ -700,7 +689,6 @@ def fail(server, handler): logfile = '/tmp/build.log' logfd = None - def main(): prog = os.path.basename(sys.argv[0]) opts = get_options()