]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/wxaddons/__init__.py
1 #----------------------------------------------------------------------
3 # Purpose: Import logic and common functions for wxaddons module
5 # Author: Kevin Ollivier
9 # Copyright: (c) 2006 Kevin Ollivier
10 # Licence: wxWindows license
11 #----------------------------------------------------------------------
13 import sys
, os
, string
18 domain
= 'http://wxpyaddons.wxcommunity.com'
19 builtin_import
= __builtin__
.__import
__
24 config
= wx
.Config("wxaddons")
25 if config
.Read("PerformChecks", "true") != "true":
28 if use_gui
and not wx
.App
.IsDisplayAvailable():
31 s
= xmlrpclib
.Server('%s/xmlrpc-server.php' % domain
, verbose
=(debug
== True))
33 def check_imports(check
):
35 config
.Write("PerformChecks", "true")
37 config
.Write("PerformChecks", "false")
39 def version_greater_than_or_equal(version1
, version2
):
41 Checks if version1 >= version2, returning true if so,
46 for index
in range(0, len(version1
)-1):
47 if version1
[index
] > version2
[index
]:
50 elif version
[index
] < current_version
[index
]:
56 def prompt_install(name
, version
):
57 should_install
= False
58 message
= "The wxaddon %s is not installed, but was found on the wxaddons site. Would you like to download and install it?" % (name
+ " " + version
)
60 app
= wx
.PySimpleApp()
62 result
= wx
.MessageBox(message
, "Install Dependency?", style
=wx
.YES_NO
)
66 result
= raw_input(message
+ " [y/n]")
67 if result
[0].lower() == "y":
72 def require_addon_version(name
, version
=[], canBeNewer
=True):
73 # Check the install receipt to see if we've got an appropriate version
74 config
= wx
.Config("wxaddons-receipts")
76 if config
.HasGroup(name
):
78 current_version
= config
.Read("version", "0.0").split(".")
80 needs_update
= version_greater_than_or_equal(version
, current_version
)
83 comp_xml
= s
.getComponent(name
)
87 comp
= xmlrpclib
.loads(comp_xml
)[0][0]
88 comp_version
= comp
["version"].split(".")
92 update_comp
= version_greater_than_or_equal(comp_version
, version
)
94 update_comp
= (version
== comp_version
)
97 url
= get_url(name
, version
)
98 should_install
= prompt_install(name
, comp_version
)
101 dl_and_install_addon(name
, comp_version
)
103 def get_url(name
, version
):
105 release_xml
= s
.getReleases(name
)
109 releases
= xmlrpclib
.loads(release_xml
)[0][0]
110 for release
in releases
:
111 if release
['version'] == version
:
116 def dl_and_install_addon(name
, version
, url
):
121 # get the package URL
122 url
= "http://wxpyaddons.wxcommunity.com/releases/sized_controls-0.5.tar.gz"
125 progress
= wx
.ProgressDialog("Installing Dependency",
126 "Preparing to install the %s addon module." % name
,
128 style
=wx
.PD_APP_MODAL|wx
.PD_SMOOTH
)
130 message
= "Downloading tarball..."
132 if use_gui
: progress
.Update(1, message
)
134 temp_archive
, headers
= urllib
.urlretrieve(url
)
136 message
= "Extracting files..."
138 if use_gui
: progress
.Update(2, message
)
140 tempdir
= tempfile
.mkdtemp()
144 tar
= tarfile
.open(temp_archive
, "r:gz")
151 message
= "Installing %s" % name
152 if use_gui
: progress
.Update(3, message
)
153 # TODO: Add support for modified PYTHONPATH?
154 # Also, do we need admin install support here?
155 retval
= os
.system(sys
.executable
+ " " + string
.join(("setup.py", "install"), " "))
156 if use_gui
: progress
.Update(4)
159 message
= "The %s addon was successfully installed." % name
162 wx
.MessageBox(message
, "Installation Successful")
167 if use_gui
: progress
.Destroy()
170 shutil
.rmtree(tempdir
)
171 os
.remove(temp_archive
)
175 def import_hook(name
, globals=None, locals=None, fromlist
=None):
176 # Fast path: see if the module has already been imported.
178 return builtin_import(name
, globals, locals, fromlist
)
180 if name
.startswith("wxaddons"):
181 print "Querying %s for module." % domain
183 modname
= name
.split(".")[1]
185 comp_xml
= s
.getComponent(modname
)
189 comp
= xmlrpclib
.loads(comp_xml
)[0][0]
190 url
= get_url(comp
["name"], comp
["version"])
191 should_install
= prompt_install(comp
["name"], comp
["version"])
195 success
= dl_and_install_addon(comp
["name"], comp
["version"], url
)
208 import wxaddons
.sized_controls
209 import wxaddons
.foo_bar
213 __builtin__
.__import
__ = import_hook