PageRenderTime 55ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/cola/job/__init__.py

https://github.com/Flowerowl/cola
Python | 58 lines | 53 code | 0 blank | 5 comment | 0 complexity | 99cc4105f89008144949eaf7b248d52b MD5 | raw file
Possible License(s): Apache-2.0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. '''
  4. Copyright (c) 2013 Qin Xuye <qin@qinxuye.me>
  5. Licensed under the Apache License, Version 2.0 (the "License");
  6. you may not use this file except in compliance with the License.
  7. You may obtain a copy of the License at
  8. http://www.apache.org/licenses/LICENSE-2.0
  9. Unless required by applicable law or agreed to in writing, software
  10. distributed under the License is distributed on an "AS IS" BASIS,
  11. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. See the License for the specific language governing permissions and
  13. limitations under the License.
  14. Created on 2013-5-26
  15. @author: Chine
  16. '''
  17. import re
  18. from cola.core.errors import ConfigurationError
  19. from cola.job.context import Context
  20. JOB_NAME_RE = re.compile(r'(\w| )+')
  21. class Job(object):
  22. def __init__(self, name, url_patterns, opener_cls, starts,
  23. is_bundle=False, unit_cls=str,
  24. instances=1, debug=False, user_conf=None,
  25. login_hook=None):
  26. self.name = name
  27. self.real_name = self.name.replace(' ', '_')
  28. if not JOB_NAME_RE.match(name):
  29. raise ConfigurationError('Job name can only contain alphabet, number and space.')
  30. self.url_patterns = url_patterns
  31. self.opener_cls = opener_cls
  32. self.starts = starts
  33. self.is_bundle = is_bundle
  34. self.unit_cls = unit_cls
  35. self.instances = instances
  36. self.debug = debug
  37. self.user_conf = user_conf
  38. self.login_hook = login_hook
  39. self.context = Context(user_conf=user_conf)
  40. def add_urlpattern(self, url_pattern):
  41. self.url_patterns += url_pattern
  42. def set_userconf(self, conf):
  43. self.user_conf = conf
  44. self.context = Context(user_conf=self.user_conf)