host.py 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. # Copyright (c) 2010 Google Inc. All rights reserved.
  2. # Copyright (c) 2009 Apple Inc. All rights reserved.
  3. #
  4. # Redistribution and use in source and binary forms, with or without
  5. # modification, are permitted provided that the following conditions are
  6. # met:
  7. #
  8. # * Redistributions of source code must retain the above copyright
  9. # notice, this list of conditions and the following disclaimer.
  10. # * Redistributions in binary form must reproduce the above
  11. # copyright notice, this list of conditions and the following disclaimer
  12. # in the documentation and/or other materials provided with the
  13. # distribution.
  14. # * Neither the name of Google Inc. nor the names of its
  15. # contributors may be used to endorse or promote products derived from
  16. # this software without specific prior written permission.
  17. #
  18. # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  19. # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  20. # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  21. # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  22. # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  23. # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  24. # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  25. # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  26. # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  27. # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  28. # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29. import logging
  30. import os
  31. import sys
  32. from webkitpy.common.checkout import Checkout
  33. from webkitpy.common.checkout.scm.detection import SCMDetector
  34. from webkitpy.common.memoized import memoized
  35. from webkitpy.common.net import bugzilla, buildbot, web
  36. from webkitpy.common.system.systemhost import SystemHost
  37. from webkitpy.common.watchlist.watchlistparser import WatchListParser
  38. from webkitpy.port.factory import PortFactory
  39. _log = logging.getLogger(__name__)
  40. class Host(SystemHost):
  41. def __init__(self):
  42. SystemHost.__init__(self)
  43. self.web = web.Web()
  44. # FIXME: Checkout should own the scm object.
  45. self._scm = None
  46. self._checkout = None
  47. # Everything below this line is WebKit-specific and belongs on a higher-level object.
  48. self.bugs = bugzilla.Bugzilla()
  49. self.buildbot = buildbot.BuildBot()
  50. # FIXME: Unfortunately Port objects are currently the central-dispatch objects of the NRWT world.
  51. # In order to instantiate a port correctly, we have to pass it at least an executive, user, scm, and filesystem
  52. # so for now we just pass along the whole Host object.
  53. # FIXME: PortFactory doesn't belong on this Host object if Port is going to have a Host (circular dependency).
  54. self.port_factory = PortFactory(self)
  55. self._engage_awesome_locale_hacks()
  56. # We call this from the Host constructor, as it's one of the
  57. # earliest calls made for all webkitpy-based programs.
  58. def _engage_awesome_locale_hacks(self):
  59. # To make life easier on our non-english users, we override
  60. # the locale environment variables inside webkitpy.
  61. # If we don't do this, programs like SVN will output localized
  62. # messages and svn.py will fail to parse them.
  63. # FIXME: We should do these overrides *only* for the subprocesses we know need them!
  64. # This hack only works in unix environments.
  65. os.environ['LANGUAGE'] = 'en'
  66. os.environ['LANG'] = 'en_US.UTF-8'
  67. os.environ['LC_MESSAGES'] = 'en_US.UTF-8'
  68. os.environ['LC_ALL'] = ''
  69. def initialize_scm(self, patch_directories=None):
  70. detector = SCMDetector(self.filesystem, self.executive)
  71. self._scm = detector.default_scm(patch_directories)
  72. self._checkout = Checkout(self.scm())
  73. def scm(self):
  74. return self._scm
  75. def checkout(self):
  76. return self._checkout
  77. @memoized
  78. def watch_list(self):
  79. config_path = self.filesystem.dirname(self.filesystem.path_to_module('webkitpy.common.config'))
  80. watch_list_full_path = self.filesystem.join(config_path, 'watchlist')
  81. if not self.filesystem.exists(watch_list_full_path):
  82. raise Exception('Watch list file (%s) not found.' % watch_list_full_path)
  83. watch_list_contents = self.filesystem.read_text_file(watch_list_full_path)
  84. return WatchListParser().parse(watch_list_contents)