def uninstall_python_module(package_name, cachedir): if package_name == 'wxPython': python_exe = os.path.join(sys.prefix, 'python.exe') if not os.path.exists(python_exe): raise Exception("Cannot uninstall wxPython: cannot find python.exe here: %s" % python_exe) wx_install_dir = subprocess.check_output([os.path.join(sys.prefix, 'python.exe'), '-c', "import wx; import os; print os.path.abspath(os.path.dirname(os.path.dirname(wx.__file__)))"]).strip() uninstall_exe = os.path.join(wx_install_dir, 'unins000.exe') if not os.path.exists(uninstall_exe): raise Exception('Cannot uninstall python module. Cannot find uninstall exe: %s', uninstall_exe) subprocess.check_call([uninstall_exe, '/SILENT', '/NORESTART']) return uninstall_name = package_name install_log = os.path.abspath(os.path.join(sys.prefix, '%s-wininst.log'%uninstall_name)) if not os.path.exists(install_log): # Look for the msi version = package_version(package_name) urls, dlls = PackageStore.find_package_urls(package_name, version) if urls is None: urls, dlls = PackageStore.find_package_urls(package_name) if urls is not None: msi_install = None python_version = sys.version[:3] for url in urls: if url['python_version'] == python_version: if url["packagetype"] == "msi": msi_install = url break elif url['packagetype'] == 'bdist_wininst': if 'uninstall_name' in url: other_install_log = os.path.abspath(os.path.join(sys.prefix, '%s-wininst.log'%url['uninstall_name'])) if os.path.exists(other_install_log): install_log = other_install_log uninstall_name = url['uninstall_name'] break if not os.path.exists(install_log) and msi_install is not None: fname, md5sum = PyPiDownloader().download_file(msi_install['url'], fname=msi_install['filename'], \ md5_digest=msi_install.get('md5_digest',None), cachedir=cachedir,\ out=sys.stdout) if fname: subprocess.check_call(['msiexec','/x',fname,'/quiet','/qn','/norestart']) return if not os.path.exists(install_log): raise Exception('Cannot uninstall python module. Cannot find msi or install log: %s', install_log) uninstall_exe = os.path.abspath(os.path.join(sys.prefix, 'Remove%s.exe'%uninstall_name)) if not os.path.exists(uninstall_exe): raise Exception('Cannot uninstall python module. Cannot find uninstall exe: %s', uninstall_exe) app = application.Application.start('"%s" -u "%s"' % (uninstall_exe, install_log)) _press_buttons(app, 'Please confirm', 'Yes', 'OK', next_count=1, finishdialogname='Uninstall Finished!')
def download_package(self, package_name, version=None, python_version=None, python_platform=None, cachedir=None, out=None): python_version = python_version or sys.version[:3] if python_platform is None: python_platform = sys.platform if version and PackageStore.has_package_version(package_name, version): r = self._download_package_from_local(package_name, version, python_version, python_platform, cachedir, out) if r: return r try: (fname, actual_md5_digest) = self._download_package_from_pypi( package_name, version, python_version, python_platform, cachedir, out) return (fname, actual_md5_digest, []) except PackageNotFoundException, e: r = self._download_package_from_local(package_name, version, python_version, python_platform, cachedir, out) if r is None: raise return r
def _download_package_from_local(self, package_name, version=None, python_version=None, python_platform=None, cachedir=None, out=None): urls, dlls = PackageStore.find_package_urls(package_name, version) if urls: (fname, actual_md5_digest) = self._download_package( urls, package_name, version, python_version, python_platform, cachedir, out) downloaded_dlls = [] for dll in dlls: (zip_fname, actual_md5_digest) = self.download_file( dll['url'], fname=None, md5_digest=dll['md5_digest'], cachedir=cachedir, out=out, verify_ssl=dll.get('verify_ssl', True)) for file in dll['files']: downloaded_dlls.append( (file, zip_fname, dll['destination'])) return (fname, actual_md5_digest, downloaded_dlls) return None
def _download_package_from_local(self, package_name, version=None, python_version=None, python_platform=None, cachedir=None, out=None): urls, dlls = PackageStore.find_package_urls(package_name, version) if urls: (fname, actual_md5_digest) = self._download_package(urls, package_name, version, python_version, python_platform, cachedir, out) downloaded_dlls = [] for dll in dlls: (zip_fname, actual_md5_digest) = self.download_file(dll['url'], fname=None, md5_digest=dll['md5_digest'], cachedir=cachedir, out=out) for file in dll['files']: downloaded_dlls.append((file, zip_fname, dll['destination'])) return (fname, actual_md5_digest, downloaded_dlls) return None
def download_package(self, package_name, version=None, python_version=None, python_platform=None, cachedir=None, out=None): python_version = python_version or sys.version[:3] if python_platform is None: python_platform = sys.platform if version and PackageStore.has_package_version(package_name, version): r = self._download_package_from_local(package_name, version, python_version, python_platform, cachedir, out) if r: return r try: (fname, actual_md5_digest) = self._download_package_from_pypi(package_name, version, python_version, python_platform, cachedir, out) return (fname, actual_md5_digest, []) except PackageNotFoundException, e: r = self._download_package_from_local(package_name, version, python_version, python_platform, cachedir, out) if r is None: raise return r
def uninstall_python_module(package_name, cachedir): if package_name == 'wxPython': python_exe = os.path.join(sys.prefix, 'python.exe') if not os.path.exists(python_exe): raise Exception( "Cannot uninstall wxPython: cannot find python.exe here: %s" % python_exe) wx_install_dir = subprocess.check_output([ os.path.join(sys.prefix, 'python.exe'), '-c', "import wx; import os; print os.path.abspath(os.path.dirname(os.path.dirname(wx.__file__)))" ]).strip() uninstall_exe = os.path.join(wx_install_dir, 'unins000.exe') if not os.path.exists(uninstall_exe): raise Exception( 'Cannot uninstall python module. Cannot find uninstall exe: %s', uninstall_exe) subprocess.check_call([uninstall_exe, '/SILENT', '/NORESTART']) return uninstall_name = package_name install_log = os.path.abspath( os.path.join(sys.prefix, '%s-wininst.log' % uninstall_name)) if not os.path.exists(install_log): # Look for the msi version = package_version(package_name) urls, dlls = PackageStore.find_package_urls(package_name, version) if urls is None: urls, dlls = PackageStore.find_package_urls(package_name) if urls is not None: msi_install = None python_version = sys.version[:3] for url in urls: if url['python_version'] == python_version: if url["packagetype"] == "msi": msi_install = url break elif url['packagetype'] == 'bdist_wininst': if 'uninstall_name' in url: other_install_log = os.path.abspath( os.path.join( sys.prefix, '%s-wininst.log' % url['uninstall_name'])) if os.path.exists(other_install_log): install_log = other_install_log uninstall_name = url['uninstall_name'] break if not os.path.exists(install_log) and msi_install is not None: fname, md5sum = PyPiDownloader().download_file(msi_install['url'], fname=msi_install['filename'], \ md5_digest=msi_install.get('md5_digest',None), cachedir=cachedir,\ out=sys.stdout) if fname: subprocess.check_call([ 'msiexec', '/x', fname, '/quiet', '/qn', '/norestart' ]) return if not os.path.exists(install_log): raise Exception( 'Cannot uninstall python module. Cannot find msi or install log: %s', install_log) uninstall_exe = os.path.abspath( os.path.join(sys.prefix, 'Remove%s.exe' % uninstall_name)) if not os.path.exists(uninstall_exe): raise Exception( 'Cannot uninstall python module. Cannot find uninstall exe: %s', uninstall_exe) app = application.Application.start('"%s" -u "%s"' % (uninstall_exe, install_log)) _press_buttons(app, 'Please confirm', 'Yes', 'OK', next_count=1, finishdialogname='Uninstall Finished!')