diff --git a/.travis.yml b/.travis.yml index 460aee40..15606ee2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -39,7 +39,7 @@ addons: install: - travis_wait 50 pip install -U -f https://extras.wxpython.org/wxPython4/extras/linux/gtk3/ubuntu-14.04 wxPython - travis_wait 50 python setup.py install - - pip install PyPubSub==3.3.0 pyyaml ruamel.yaml + - pip install PyPubSub==3.3.0 pyyaml ruamel.yaml requests # command to run script: travis_wait 20 python devsimpy.py examples/model0.dsp quit \ No newline at end of file diff --git a/Decorators.py b/Decorators.py index f2b32148..6f637be6 100644 --- a/Decorators.py +++ b/Decorators.py @@ -149,10 +149,14 @@ def __init__(self, *args, **kwargs): def run(self): if self._target is not None: - self._return = self._target(*self._args, **self._kwargs) - + try: + self._return = self._target(*self._args, **self._kwargs) + except Exception as e: + self._return = e + def join(self): - threading.Thread.join(self) + if not isinstance(self._return, Exception): + threading.Thread.join(self) return self._return @decorator_with_args @@ -166,9 +170,6 @@ def wrapper(*args): else: message = _('Please wait..') - # main window - mainW = wx.GetApp().GetTopWindow() - progress_dlg = wx.ProgressDialog(title, message, style=wx.PD_APP_MODAL|wx.PD_CAN_ABORT) thread = ThreadWithReturnValue(target = f, args = args) @@ -180,7 +181,7 @@ def wrapper(*args): wx.SafeYield() progress_dlg.Destroy() - + return thread.join() return wrapper diff --git a/Utilities.py b/Utilities.py index de9f33fb..ec53d64c 100644 --- a/Utilities.py +++ b/Utilities.py @@ -178,45 +178,64 @@ def PyBuzyInfo(msg, time): del busy -def updatePiP(): - """ - """ +def check_internet(): + url = 'https://github.com/capocchi/DEVSimPy' + timeout = 5 try: - check_call("python -m pip install --upgrade pip", shell=True) - except CalledProcessError as ee: - print(ee.output) + _ = requests.get(url, timeout=timeout) + except requests.ConnectionError as e: + print(e) return False else: return True +def updatePiP(): + """ + """ + + if check_internet(): + try: + check_call("python -m pip install --upgrade pip", shell=True) + except Exception as ee: + print(ee.output) + return False + else: + return True + else: + return False + def downloadFromURL(url): """ """ - - # downloading with requests - # download the file contents in binary format - r = requests.get(url) - if r.status_code == 200: - # 200 means a successful request - - tempdir = tempfile.gettempdir() - fn = os.path.join(tempdir, "DEVSimPy.zip") - # open method to open a file on your system and write the contents - with open(fn, "wb") as code: - code.write(r.content) - - # downloading with urllib - # Copy a network object to a local file - urlretrieve(url, fn) + try: + # downloading with requests + # download the file contents in binary format + r = requests.get(url) + except requests.ConnectionError as e: + print(e) + return None + else: + if r.status_code == 200: + # 200 means a successful request + + tempdir = tempfile.gettempdir() + fn = os.path.join(tempdir, "DEVSimPy.zip") + # open method to open a file on your system and write the contents + with open(fn, "wb") as code: + code.write(r.content) + + # downloading with urllib + # Copy a network object to a local file + urlretrieve(url, fn) - return fn + return fn - else: - return None + else: + return None def updateFromGit(): - """ + """ Updated DEVSimPy from Git with a zip (not with git command) """ # specifying the zip file name @@ -224,16 +243,24 @@ def updateFromGit(): if fn: # opening the zip file in READ mode - with ZipFile(fn, 'r') as zip: + with ZipFile(fn, 'r') as zip: + txt = 'Name / Size / Date\n' + txt +=' \n'.join([str(elem.filename)+'/'+str(elem.file_size)+'/'+str(elem.date_time) for elem in zip.infolist()]) # printing all the contents of the zip file - zip.printdir() + dlg = wx.RichMessageDialog(None, "Do you realy want to update DEVSimPy?\nAll files will be relaced and you cannot go backwards.", style=wx.YES_NO|wx.CENTER) + dlg.ShowDetailedText(txt) + if dlg.ShowModal() not in (wx.ID_NO, wx.ID_CANCEL): - # extracting all the files - print('Extracting all the files now...') - #zip.extractall() - print('Done!') + # extracting all the files + print('Extracting all the files now...') + #zip.extractall() + print('Done!') - return True + dlg.Destroy() + return True + else: + dlg.Destroy() + return False else: return False @@ -241,21 +268,23 @@ def updatePackageWithPiP(): """ Update all installed package using pip """ - updatePiP() + if updatePiP(): - if pip.__version__ > '10.0.1': - command = "pip install --user --upgrade -r requirements.txt" - else: - packages = [dist.project_name for dist in pip.get_installed_distributions() if 'PyPubSub' not in dist.project_name] - command = "pip install --user --upgrade " + ' '.join(packages) + if pip.__version__ > '10.0.1': + command = "pip install --user --upgrade -r requirements.txt" + else: + packages = [dist.project_name for dist in pip.get_installed_distributions() if 'PyPubSub' not in dist.project_name] + command = "pip install --user --upgrade " + ' '.join(packages) - try: - check_call(command, shell=True) - except CalledProcessError as ee: - print(ee.output) - return False + try: + check_call(command, shell=True) + except Exception as ee: + print(ee.output) + return False + else: + return True else: - return True + return False def install_and_import(package): """ Install and import the package diff --git a/devsimpy.py b/devsimpy.py index b2d4e25d..ad1e2bad 100644 --- a/devsimpy.py +++ b/devsimpy.py @@ -2042,12 +2042,24 @@ def OnHelp(self, event): @cond_decorator(builtins.__dict__.get('GUI_FLAG',True), ProgressNotification(_("Update of dependant pip packages."))) def OnUpdatPiPPackage(self, event): if updatePackageWithPiP(): - NotificationMessage(_('Information'), _('All pip packages that DEVSimPy depends have been updated!'), None, timeout=5) + args = (_('Information'), _('All pip packages that DEVSimPy depends have been updated!')) + kwargs = {'parent':self, 'timeout':5} + else: + args = (_('Error'), _('Pip packages update failed!\n Check the trace in background for more informations.')) + kwargs = {'parent':self, 'flag':wx.ICON_ERROR, 'timeout':5} + + NotificationMessage(*args, **kwargs) @cond_decorator(builtins.__dict__.get('GUI_FLAG',True), ProgressNotification(_("DEVSimPy Update from git."))) def OnUpdatFromGit(self, event): if updateFromGit(): - NotificationMessage(_('Information'), _('Update of DEVSimPy from git done!'), parent=self, timeout=5) + args = (_('Information'), _('Update of DEVSimPy from git done!')) + kwargs = {'parent':self, 'timeout':5} + else: + args = (_('Error'), _('DEVSimPy update from git failed!\n Check the trace in background for more informations.')) + kwargs = {'parent':self, 'flag':wx.ICON_ERROR, 'timeout':5} + + NotificationMessage(*args, **kwargs) def OnAPI(self, event): """ Shows the DEVSimPy API help file. """