summaryrefslogtreecommitdiffstats
path: root/tools/site_compare/scrapers/__init__.py
blob: 5f6d77885b7251eb6cdedad19b6740aa11e819df (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/usr/bin/env python
# Copyright (c) 2011 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

"""Selects the appropriate scraper for a given browser and version."""

import types

# TODO(jhaas): unify all optional scraper parameters into kwargs

def GetScraper(browser):
  """Given a browser and an optional version, returns the scraper module.

  Args:
    browser: either a string (browser name) or a tuple (name, version)

  Returns:
    module
  """

  if type(browser) == types.StringType: browser = (browser, None)

  package = __import__(browser[0], globals(), locals(), [''])
  module = package.GetScraper(browser[1])
  if browser[1] is not None: module.version = browser[1]

  return module


# if invoked rather than imported, do some tests
if __name__ == "__main__":
  print GetScraper("IE")