1# Copyright (C) 2010 Chris Jerdonek (cjerdonek@webkit.org)
2#
3# Redistribution and use in source and binary forms, with or without
4# modification, are permitted provided that the following conditions
5# are met:
6# 1.  Redistributions of source code must retain the above copyright
7#     notice, this list of conditions and the following disclaimer.
8# 2.  Redistributions in binary form must reproduce the above copyright
9#     notice, this list of conditions and the following disclaimer in the
10#     documentation and/or other materials provided with the distribution.
11#
12# THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND
13# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
14# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
15# DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR
16# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
17# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
18# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
19# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
20# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
21# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
22
23# This module is required for Python to treat this directory as a package.
24
25"""Autoinstalls third-party code required by WebKit."""
26
27from __future__ import with_statement
28
29import codecs
30import os
31
32from webkitpy.common.system.autoinstall import AutoInstaller
33
34# Putting the autoinstall code into webkitpy/thirdparty/__init__.py
35# ensures that no autoinstalling occurs until a caller imports from
36# webkitpy.thirdparty.  This is useful if the caller wants to configure
37# logging prior to executing autoinstall code.
38
39# FIXME: Ideally, a package should be autoinstalled only if the caller
40#        attempts to import from that individual package.  This would
41#        make autoinstalling lazier than it is currently.  This can
42#        perhaps be done using Python's import hooks as the original
43#        autoinstall implementation did.
44
45# FIXME: If any of these servers is offline, webkit-patch breaks (and maybe
46# other scripts do, too). See <http://webkit.org/b/42080>.
47
48# We put auto-installed third-party modules in this directory--
49#
50#     webkitpy/thirdparty/autoinstalled
51thirdparty_dir = os.path.dirname(__file__)
52autoinstalled_dir = os.path.join(thirdparty_dir, "autoinstalled")
53
54# We need to download ClientForm since the mechanize package that we download
55# below requires it.  The mechanize package uses ClientForm, for example,
56# in _html.py.  Since mechanize imports ClientForm in the following way,
57#
58# > import sgmllib, ClientForm
59#
60# the search path needs to include ClientForm.  We put ClientForm in
61# its own directory so that we can include it in the search path without
62# including other modules as a side effect.
63clientform_dir = os.path.join(autoinstalled_dir, "clientform")
64installer = AutoInstaller(append_to_search_path=True,
65                          target_dir=clientform_dir)
66installer.install(url="http://pypi.python.org/packages/source/C/ClientForm/ClientForm-0.2.10.zip",
67                  url_subpath="ClientForm.py")
68
69# The remaining packages do not need to be in the search path, so we create
70# a new AutoInstaller instance that does not append to the search path.
71installer = AutoInstaller(target_dir=autoinstalled_dir)
72
73installer.install(url="http://pypi.python.org/packages/source/m/mechanize/mechanize-0.2.4.zip",
74                  url_subpath="mechanize")
75installer.install(url="http://pypi.python.org/packages/source/p/pep8/pep8-0.5.0.tar.gz#md5=512a818af9979290cd619cce8e9c2e2b",
76                  url_subpath="pep8-0.5.0/pep8.py")
77installer.install(url="http://www.adambarth.com/webkit/eliza",
78                  target_name="eliza.py")
79
80# Since irclib and ircbot are two top-level packages, we need to import
81# them separately.  We group them into an irc package for better
82# organization purposes.
83irc_dir = os.path.join(autoinstalled_dir, "irc")
84installer = AutoInstaller(target_dir=irc_dir)
85installer.install(url="http://downloads.sourceforge.net/project/python-irclib/python-irclib/0.4.8/python-irclib-0.4.8.zip", url_subpath="irclib.py")
86installer.install(url="http://downloads.sourceforge.net/project/python-irclib/python-irclib/0.4.8/python-irclib-0.4.8.zip", url_subpath="ircbot.py")
87
88pywebsocket_dir = os.path.join(autoinstalled_dir, "pywebsocket")
89installer = AutoInstaller(target_dir=pywebsocket_dir)
90installer.install(url="http://pywebsocket.googlecode.com/files/mod_pywebsocket-0.5.2.tar.gz",
91                  url_subpath="pywebsocket-0.5.2/src/mod_pywebsocket")
92
93readme_path = os.path.join(autoinstalled_dir, "README")
94if not os.path.exists(readme_path):
95    with codecs.open(readme_path, "w", "ascii") as file:
96        file.write("This directory is auto-generated by WebKit and is "
97                   "safe to delete.\nIt contains needed third-party Python "
98                   "packages automatically downloaded from the web.")
99