]>
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 if use_gui
and not wx
.App
.IsDisplayAvailable():
27 s
= xmlrpclib
.Server('%s/xmlrpc-server.php' % domain
, verbose
=(debug
== True))
29 def version_greater_than_or_equal(version1
, version2
):
31 Checks if version1 >= version2, returning true if so,
36 for index
in range(0, len(version1
)-1):
37 if version1
[index
] > version2
[index
]:
40 elif version
[index
] < current_version
[index
]:
46 def prompt_install(name
, version
):
47 should_install
= False
48 message
= "The wxaddon %s is not installed, but was found on the wxaddons site. Would you like to download and install it?" % (name
+ " " + version
)
50 app
= wx
.PySimpleApp()
52 result
= wx
.MessageBox(message
, "Install Dependency?", style
=wx
.YES_NO
)
56 result
= raw_input(message
+ " [y/n]")
57 if result
[0].lower() == "y":
62 def require_addon_version(name
, version
=[], canBeNewer
=True):
63 # Check the install receipt to see if we've got an appropriate version
64 config
= wx
.Config("wxaddons-receipts")
66 if config
.HasGroup(name
):
68 current_version
= config
.Read("version", "0.0").split(".")
70 needs_update
= version_greater_than_or_equal(version
, current_version
)
73 comp_xml
= s
.getComponent(name
)
77 comp
= xmlrpclib
.loads(comp_xml
)[0][0]
78 comp_version
= comp
["version"].split(".")
82 update_comp
= version_greater_than_or_equal(comp_version
, version
)
84 update_comp
= (version
== comp_version
)
87 url
= get_url(name
, version
)
88 should_install
= prompt_install(name
, comp_version
)
91 dl_and_install_addon(name
, comp_version
)
93 def get_url(name
, version
):
95 release_xml
= s
.getReleases(name
)
99 releases
= xmlrpclib
.loads(release_xml
)[0][0]
100 for release
in releases
:
101 if release
['version'] == version
:
106 def dl_and_install_addon(name
, version
, url
):
111 # get the package URL
112 url
= "http://wxpyaddons.wxcommunity.com/releases/sized_controls-0.5.tar.gz"
115 progress
= wx
.ProgressDialog("Installing Dependency",
116 "Preparing to install the %s addon module." % name
,
118 style
=wx
.PD_APP_MODAL|wx
.PD_SMOOTH
)
120 message
= "Downloading tarball..."
122 if use_gui
: progress
.Update(1, message
)
124 temp_archive
, headers
= urllib
.urlretrieve(url
)
126 message
= "Extracting files..."
128 if use_gui
: progress
.Update(2, message
)
130 tempdir
= tempfile
.mkdtemp()
134 tar
= tarfile
.open(temp_archive
, "r:gz")
141 message
= "Installing %s" % name
142 if use_gui
: progress
.Update(3, message
)
143 # TODO: Add support for modified PYTHONPATH?
144 # Also, do we need admin install support here?
145 retval
= os
.system(sys
.executable
+ " " + string
.join(("setup.py", "install"), " "))
146 if use_gui
: progress
.Update(4)
149 message
= "The %s addon was successfully installed." % name
152 wx
.MessageBox(message
, "Installation Successful")
157 if use_gui
: progress
.Destroy()
160 shutil
.rmtree(tempdir
)
161 os
.remove(temp_archive
)
165 def import_hook(name
, globals=None, locals=None, fromlist
=None):
166 # Fast path: see if the module has already been imported.
168 return builtin_import(name
, globals, locals, fromlist
)
170 if name
.startswith("wxaddons"):
171 print "Querying %s for module." % domain
173 modname
= name
.split(".")[1]
175 comp_xml
= s
.getComponent(modname
)
179 comp
= xmlrpclib
.loads(comp_xml
)[0][0]
180 url
= get_url(comp
["name"], comp
["version"])
181 should_install
= prompt_install(comp
["name"], comp
["version"])
185 success
= dl_and_install_addon(comp
["name"], comp
["version"], url
)
198 import wxaddons
.sized_controls
199 import wxaddons
.foo_bar
202 __builtin__
.__import
__ = import_hook