Validate install PIP in Windows

This commit is contained in:
Mauricio Baeza 2020-11-12 23:10:42 -06:00
parent 41681330d3
commit 0099908afc
4 changed files with 79 additions and 55 deletions

View File

@ -39,6 +39,7 @@ import sys
import tempfile
import threading
import time
import traceback
import zipfile
from collections import OrderedDict
@ -170,6 +171,10 @@ PC = platform.node()
DESKTOP = os.environ.get('DESKTOP_SESSION', '')
INFO_DEBUG = f"{sys.version}\n\n{platform.platform()}\n\n" + '\n'.join(sys.path)
PYTHON = 'python'
if IS_WIN:
PYTHON = 'python.exe'
_MACROS = {}
_start = 0
@ -302,7 +307,7 @@ def catch_exception(f):
except Exception as e:
name = f.__name__
if IS_WIN:
debug(traceback.format_exc())
msgbox(traceback.format_exc())
log.error(name, exc_info=True)
return func
@ -535,7 +540,7 @@ def run(command, capture=False, split=True):
return subprocess.check_output(command, shell=True).decode()
cmd = shlex.split(command)
result = subprocess.run(cmd, capture_output=capture, text=True)
result = subprocess.run(cmd, capture_output=capture, text=True, shell=IS_WIN)
if capture:
result = result.stdout
else:
@ -543,15 +548,15 @@ def run(command, capture=False, split=True):
return result
# ~ def popen(command, stdin=None):
# ~ try:
# ~ proc = subprocess.Popen(shlex.split(command), shell=IS_WIN,
# ~ stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
# ~ for line in proc.stdout:
# ~ yield line.decode().rstrip()
# ~ except Exception as e:
# ~ error(e)
# ~ yield (e.errno, e.strerror)
def popen(command):
try:
proc = subprocess.Popen(shlex.split(command), shell=IS_WIN,
stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
for line in proc.stdout:
yield line.decode().rstrip()
except Exception as e:
error(e)
yield (e.errno, e.strerror)
def sleep(seconds):
@ -4039,7 +4044,13 @@ class Paths(object):
@classproperty
def python(self):
return sys.executable
if IS_WIN:
path = self.join(self.config('Module'), PYTHON)
elif IS_MAC:
path = self.join(self.config('Module'), '..', 'Resources', PYTHON)
else:
path = sys.executable
return path
@classmethod
def dir_tmp(self, only_name=False):

Binary file not shown.

View File

@ -39,6 +39,7 @@ import sys
import tempfile
import threading
import time
import traceback
import zipfile
from collections import OrderedDict
@ -170,6 +171,10 @@ PC = platform.node()
DESKTOP = os.environ.get('DESKTOP_SESSION', '')
INFO_DEBUG = f"{sys.version}\n\n{platform.platform()}\n\n" + '\n'.join(sys.path)
PYTHON = 'python'
if IS_WIN:
PYTHON = 'python.exe'
_MACROS = {}
_start = 0
@ -302,7 +307,7 @@ def catch_exception(f):
except Exception as e:
name = f.__name__
if IS_WIN:
debug(traceback.format_exc())
msgbox(traceback.format_exc())
log.error(name, exc_info=True)
return func
@ -535,7 +540,7 @@ def run(command, capture=False, split=True):
return subprocess.check_output(command, shell=True).decode()
cmd = shlex.split(command)
result = subprocess.run(cmd, capture_output=capture, text=True)
result = subprocess.run(cmd, capture_output=capture, text=True, shell=IS_WIN)
if capture:
result = result.stdout
else:
@ -543,15 +548,16 @@ def run(command, capture=False, split=True):
return result
# ~ def popen(command, stdin=None):
# ~ try:
# ~ proc = subprocess.Popen(shlex.split(command), shell=IS_WIN,
# ~ stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
# ~ for line in proc.stdout:
# ~ yield line.decode().rstrip()
# ~ except Exception as e:
# ~ error(e)
# ~ yield (e.errno, e.strerror)
def popen(command):
try:
proc = subprocess.Popen(shlex.split(command), shell=IS_WIN,
stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
for line in proc.stdout:
yield line.decode().rstrip()
except Exception as e:
error(e)
msg = f'Error No: {e.errno} - {e.strerror}'
yield msg
def sleep(seconds):
@ -4039,7 +4045,13 @@ class Paths(object):
@classproperty
def python(self):
return sys.executable
if IS_WIN:
path = self.join(self.config('Module'), PYTHON)
elif IS_MAC:
path = self.join(self.config('Module'), '..', 'Resources', PYTHON)
else:
path = sys.executable
return path
@classmethod
def dir_tmp(self, only_name=False):

View File

@ -4,6 +4,7 @@ import easymacro as app
ID_EXTENSION = ''
_ = None
TITLE = 'ZAZ-PIP'
@ -34,12 +35,12 @@ def open_dialog_pip():
def run(args, path_locales):
app.install_locales(path_locales)
global _
_ = app.install_locales(path_locales)
globals()[args]()
return
@app.catch_exception
class Controllers(object):
OK1 = 'Successfully installed'
OK2 = 'Requirement already'
@ -48,22 +49,20 @@ class Controllers(object):
def __init__(self, dialog):
self.d = dialog
self.path_python = app.paths.python
def _set_state(self, state):
self._states = {
'list': False,
'install': False,
'search': False,
'versions': False,
}
def _set_state(self, state):
for k in self._states.keys():
self._states[k] = False
self._states[state] = True
return
def cmd_install_pip_action(self, event):
msg = _('Do you want install PIP?')
if not app.question(msg, 'ZAZ-Pip'):
if not app.question(msg, TITLE):
return
self._install_pip()
@ -73,26 +72,25 @@ class Controllers(object):
def _install_pip(self):
self.d.link_proyect.visible = False
self.d.lst_log.visible = True
path_pip = app.get_temp_file(True)
self.d.lst_log.insert('Download PIP...')
data, err = app.url_open(URL_PIP, verify=False)
path_pip = app.paths.tmp()
self.d.lst_log.insert(_('Download PIP...'))
data, h, err = app.url_open(URL_PIP, verify=False)
app.msgbox(path_pip)
if err:
msg = _('Do you have internet connection?')
app.errorbox('{}\n\n{}'.format(msg, err))
return
app.save_file(path_pip, 'wb', data)
if not app.is_created(path_pip):
app.paths.save_bin(path_pip, data)
if not app.paths.exists(path_pip):
msg = _('File PIP not save')
app.errorbox(msg)
return
self.d.lst_log.insert(_('PIP save correctly...'))
try:
self.d.lst_log.insert(_('Start installing PIP...'))
cmd = '"{}" "{}" --user'.format(self.path_python, path_pip)
cmd = f'"{self.path_python}" "{path_pip}" --user'
for line in app.popen(cmd):
if isinstance(line, tuple):
app.errorbox(line)
@ -119,7 +117,6 @@ class Controllers(object):
cmd = '"{}" -m pip {}'.format(self.path_python, args)
return cmd
@app.catch_exception
def cmd_admin_pip_action(self, event):
self.d.lst_log.ps_from(self.d.lst_package)
self.d.lst_log.step = 1
@ -275,6 +272,7 @@ class Controllers(object):
@app.catch_exception
def _create_dialog():
BUTTON_WH = 20
args= {
'Name': 'dialog',
'Title': 'Zaz-Pip',
@ -303,6 +301,7 @@ def _create_dialog():
path_python = app.paths.python
cmd = '"{}" -V'.format(path_python)
app.msgbox(cmd)
label = app.run(cmd, True)
args = {
@ -321,7 +320,9 @@ def _create_dialog():
dialog.center(dialog.lbl_python, y=25)
cmd = '"{}" -m pip -V'.format(path_python)
app.msgbox(cmd)
label = app.run(cmd, True)
app.msgbox(label)
exists_pip = True
if not label:
exists_pip = False
@ -345,8 +346,8 @@ def _create_dialog():
'Type': 'Button',
'Name': 'cmd_admin_pip',
'Label': _('Admin PIP'),
'Width': 60,
'Height': 18,
'Width': 70,
'Height': BUTTON_WH,
'Step': 10,
'ImageURL': 'python.png',
'ImagePosition': 1,
@ -359,7 +360,7 @@ def _create_dialog():
'Name': 'cmd_install_pip',
'Label': _('Install PIP'),
'Width': 60,
'Height': 18,
'Height': BUTTON_WH,
'Step': 10,
'ImageURL': 'install.png',
'ImagePosition': 1,
@ -428,8 +429,8 @@ def _create_dialog():
'Type': 'Button',
'Name': 'cmd_close',
'Label': _('~Close'),
'Width': 60,
'Height': 18,
'Width': 70,
'Height': BUTTON_WH,
'Step': 1,
'ImageURL': 'close.png',
'ImagePosition': 1,
@ -441,8 +442,8 @@ def _create_dialog():
args = {
'Type': 'Button',
'Name': 'cmd_home',
'Width': 18,
'Height': 18,
'Width': BUTTON_WH,
'Height': BUTTON_WH,
'Step': 1,
'ImageURL': 'home.png',
'FocusOnClick': False,
@ -453,8 +454,8 @@ def _create_dialog():
args = {
'Type': 'Button',
'Name': 'cmd_search',
'Width': 18,
'Height': 18,
'Width': BUTTON_WH,
'Height': BUTTON_WH,
'Step': 1,
'ImageURL': 'search.png',
'FocusOnClick': False,
@ -465,8 +466,8 @@ def _create_dialog():
args = {
'Type': 'Button',
'Name': 'cmd_uninstall',
'Width': 18,
'Height': 18,
'Width': BUTTON_WH,
'Height': BUTTON_WH,
'Step': 1,
'ImageURL': 'uninstall.png',
'FocusOnClick': False,
@ -477,8 +478,8 @@ def _create_dialog():
args = {
'Type': 'Button',
'Name': 'cmd_install',
'Width': 18,
'Height': 18,
'Width': BUTTON_WH,
'Height': BUTTON_WH,
'Step': 1,
'ImageURL': 'install.png',
'FocusOnClick': False,
@ -489,8 +490,8 @@ def _create_dialog():
args = {
'Type': 'Button',
'Name': 'cmd_shell',
'Width': 18,
'Height': 18,
'Width': BUTTON_WH,
'Height': BUTTON_WH,
'Step': 1,
'ImageURL': 'shell.png',
'FocusOnClick': False,