diff options
author | Jan Safranek <jsafrane@redhat.com> | 2014-04-17 15:30:12 +0200 |
---|---|---|
committer | Jan Safranek <jsafrane@redhat.com> | 2014-04-17 15:30:12 +0200 |
commit | 9621f87dddc14333ce691656127fa317cae42936 (patch) | |
tree | 58d79f1c107c1ad349d08d78c341f85fd896a56e | |
parent | ab258cb4f8af61117496f72dae48a4493bae55e5 (diff) | |
download | openlmi-providers-9621f87dddc14333ce691656127fa317cae42936.tar.gz openlmi-providers-9621f87dddc14333ce691656127fa317cae42936.tar.xz openlmi-providers-9621f87dddc14333ce691656127fa317cae42936.zip |
Update job_handler decorator for Python 2.6
There is no inspect.callargs there. As a simple workaround, 'job' must be
the first parameter in decorated method.
-rw-r--r-- | src/software/lmi/software/yumdb/jobmanager.py | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/src/software/lmi/software/yumdb/jobmanager.py b/src/software/lmi/software/yumdb/jobmanager.py index c064583..e20146f 100644 --- a/src/software/lmi/software/yumdb/jobmanager.py +++ b/src/software/lmi/software/yumdb/jobmanager.py @@ -58,13 +58,16 @@ def job_handler(job_from_target=True): """ Decorator for JobManager methods serving as handlers for control jobs. + If job_from_target is True, 'job' MUST be the first parameter of decorated + method! + Decorator locks the :py:attr:`JobManager._job_lock` of manager's instance. """ def _wrapper_jft(method): """ - It consumes "target" keyword argument (which is job's id) and makes - it an instance of YumJob. The method is then called with "job" argument - instead of "target". + It consumes "job" keyword argument (which is job's id) and makes + it an instance of YumJob. The method is then called with the instance + of YumJob instead of job id. """ logged = cmpi_logging.trace_method(method, frame_level=2) @@ -72,15 +75,20 @@ def job_handler(job_from_target=True): def _new_func(self, *args, **kwargs): """Wrapper around method.""" if 'target' in kwargs: - kwargs['job'] = kwargs.pop('target') - callargs = inspect.getcallargs(method, self, *args, **kwargs) - target = callargs.pop('job') + target = kwargs.pop('target') + elif 'job' in kwargs: + target = kwargs.pop('job') + else: + # 'job' is not in kwargs, it _must_ be in args then + assert len(args) > 0 + target = args[0] + args = args[1:] + with self._job_lock: if not target in self._async_jobs: raise errors.JobNotFound(target) job = self._async_jobs[target] - callargs['job'] = job - return logged(**callargs) + return logged(self, job, *args, **kwargs) return _new_func def _simple_wrapper(method): |