From ffe5428e403883ab4c90699d834b24298572eb88 Mon Sep 17 00:00:00 2001 From: Capocchi L Date: Tue, 24 Mar 2020 22:06:46 +0100 Subject: [PATCH 1/8] bug fix --- Utilities.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Utilities.py b/Utilities.py index ec53d64c..60c90a67 100644 --- a/Utilities.py +++ b/Utilities.py @@ -244,10 +244,10 @@ def updateFromGit(): if fn: # opening the zip file in READ mode 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 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) + txt = 'Name / Size / Date\n' + txt +=' \n'.join([str(elem.filename)+'/'+str(elem.file_size)+'/'+str(elem.date_time) for elem in zip.infolist()]) dlg.ShowDetailedText(txt) if dlg.ShowModal() not in (wx.ID_NO, wx.ID_CANCEL): From 932fd05da96228a59296fec40882b700ee1a59d5 Mon Sep 17 00:00:00 2001 From: Capocchi L Date: Tue, 24 Mar 2020 22:09:02 +0100 Subject: [PATCH 2/8] bug fix --- Utilities.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Utilities.py b/Utilities.py index 60c90a67..ee9c27aa 100644 --- a/Utilities.py +++ b/Utilities.py @@ -249,7 +249,7 @@ def updateFromGit(): txt = 'Name / Size / Date\n' txt +=' \n'.join([str(elem.filename)+'/'+str(elem.file_size)+'/'+str(elem.date_time) for elem in zip.infolist()]) dlg.ShowDetailedText(txt) - if dlg.ShowModal() not in (wx.ID_NO, wx.ID_CANCEL): + if dlg.ShowModal() == wx.ID_YES: #not in (wx.ID_NO, wx.ID_CANCEL): # extracting all the files print('Extracting all the files now...') From d2a9707e69a77f27be5c0a4b1edc060835d160e0 Mon Sep 17 00:00:00 2001 From: Capocchi L Date: Tue, 24 Mar 2020 22:13:53 +0100 Subject: [PATCH 3/8] bug fix --- Utilities.py | 6 +++--- devsimpy.py | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Utilities.py b/Utilities.py index ee9c27aa..3aca13c9 100644 --- a/Utilities.py +++ b/Utilities.py @@ -234,7 +234,7 @@ def downloadFromURL(url): else: return None -def updateFromGit(): +def updateFromGit(parent): """ Updated DEVSimPy from Git with a zip (not with git command) """ @@ -245,11 +245,11 @@ def updateFromGit(): # opening the zip file in READ mode with ZipFile(fn, 'r') as zip: # printing all the contents of the zip file - 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 = wx.RichMessageDialog(parent, "Do you realy want to update DEVSimPy?\nAll files will be relaced and you cannot go backwards.", style=wx.YES_NO|wx.CENTER) txt = 'Name / Size / Date\n' txt +=' \n'.join([str(elem.filename)+'/'+str(elem.file_size)+'/'+str(elem.date_time) for elem in zip.infolist()]) dlg.ShowDetailedText(txt) - if dlg.ShowModal() == wx.ID_YES: #not in (wx.ID_NO, wx.ID_CANCEL): + if dlg.ShowModal() not in (wx.ID_NO, wx.ID_CANCEL): # extracting all the files print('Extracting all the files now...') diff --git a/devsimpy.py b/devsimpy.py index ad1e2bad..cc7c0ce6 100644 --- a/devsimpy.py +++ b/devsimpy.py @@ -2052,7 +2052,7 @@ def OnUpdatPiPPackage(self, event): @cond_decorator(builtins.__dict__.get('GUI_FLAG',True), ProgressNotification(_("DEVSimPy Update from git."))) def OnUpdatFromGit(self, event): - if updateFromGit(): + if updateFromGit(self): args = (_('Information'), _('Update of DEVSimPy from git done!')) kwargs = {'parent':self, 'timeout':5} else: From 0763f4cdc5586f1c454acc7dc20b5fe4e974fc4a Mon Sep 17 00:00:00 2001 From: Capocchi L Date: Tue, 24 Mar 2020 22:36:54 +0100 Subject: [PATCH 4/8] bug fix --- Utilities.py | 30 +++++++++++++++--------------- devsimpy.py | 2 +- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/Utilities.py b/Utilities.py index 3aca13c9..75be4da3 100644 --- a/Utilities.py +++ b/Utilities.py @@ -234,7 +234,7 @@ def downloadFromURL(url): else: return None -def updateFromGit(parent): +def updateFromGit(): """ Updated DEVSimPy from Git with a zip (not with git command) """ @@ -245,22 +245,22 @@ def updateFromGit(parent): # opening the zip file in READ mode with ZipFile(fn, 'r') as zip: # printing all the contents of the zip file - dlg = wx.RichMessageDialog(parent, "Do you realy want to update DEVSimPy?\nAll files will be relaced and you cannot go backwards.", style=wx.YES_NO|wx.CENTER) - txt = 'Name / Size / Date\n' - txt +=' \n'.join([str(elem.filename)+'/'+str(elem.file_size)+'/'+str(elem.date_time) for elem in zip.infolist()]) - dlg.ShowDetailedText(txt) - if dlg.ShowModal() not in (wx.ID_NO, wx.ID_CANCEL): + #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) + #txt = 'Name / Size / Date\n' + #txt +=' \n'.join([str(elem.filename)+'/'+str(elem.file_size)+'/'+str(elem.date_time) for elem in zip.infolist()]) + #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!') - dlg.Destroy() - return True - else: - dlg.Destroy() - return False + #dlg.Destroy() + return True + #else: + # dlg.Destroy() + # return False else: return False diff --git a/devsimpy.py b/devsimpy.py index cc7c0ce6..ad1e2bad 100644 --- a/devsimpy.py +++ b/devsimpy.py @@ -2052,7 +2052,7 @@ def OnUpdatPiPPackage(self, event): @cond_decorator(builtins.__dict__.get('GUI_FLAG',True), ProgressNotification(_("DEVSimPy Update from git."))) def OnUpdatFromGit(self, event): - if updateFromGit(self): + if updateFromGit(): args = (_('Information'), _('Update of DEVSimPy from git done!')) kwargs = {'parent':self, 'timeout':5} else: From f1282f4c914999a73c8ae1ba023904127e8a2c68 Mon Sep 17 00:00:00 2001 From: Capocchi L Date: Tue, 24 Mar 2020 23:14:33 +0100 Subject: [PATCH 5/8] bug fix --- Decorators.py | 54 +++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 42 insertions(+), 12 deletions(-) diff --git a/Decorators.py b/Decorators.py index 6f637be6..d3f84cb4 100644 --- a/Decorators.py +++ b/Decorators.py @@ -146,18 +146,44 @@ class ThreadWithReturnValue(threading.Thread): def __init__(self, *args, **kwargs): super(ThreadWithReturnValue, self).__init__(*args, **kwargs) self._return = None + self.killed = False + + def start(self): + self.__run_backup = self.run + self.run = self.__run + threading.Thread.start(self) - def run(self): - if self._target is not None: - try: - self._return = self._target(*self._args, **self._kwargs) - except Exception as e: - self._return = e + def __run(self): + sys.settrace(self.globaltrace) + self._return = self.__run_backup() + self.run = self.__run_backup + + def globaltrace(self, frame, event, arg): + if event == 'call': + return self.localtrace + else: + return None + + def localtrace(self, frame, event, arg): + if self.killed: + if event == 'line': + raise SystemExit() + return self.localtrace + + def kill(self): + self.killed = True + + # def run(self): + # if self._target is not None: + # try: + # self._return = self._target(*self._args, **self._kwargs) + # except Exception as e: + # self._return = e - def join(self): - if not isinstance(self._return, Exception): - threading.Thread.join(self) - return self._return + # def join(self): + # if not isinstance(self._return, Exception): + # threading.Thread.join(self) + # return self._return @decorator_with_args def ProgressNotification(f, arg): @@ -177,11 +203,15 @@ def wrapper(*args): while thread.isAlive(): wx.MilliSleep(300) - progress_dlg.Pulse() + + if progress_dlg.WasCancelled() or progress_dlg.WasSkipped(): + thread.kill() + else: + progress_dlg.Pulse() wx.SafeYield() progress_dlg.Destroy() - + return thread.join() return wrapper From 286b21f3c259cbb56c157b71c2949d96784bab47 Mon Sep 17 00:00:00 2001 From: Capocchi L Date: Tue, 24 Mar 2020 23:21:36 +0100 Subject: [PATCH 6/8] bug fix --- Decorators.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/Decorators.py b/Decorators.py index d3f84cb4..fc7269e2 100644 --- a/Decorators.py +++ b/Decorators.py @@ -201,14 +201,13 @@ def wrapper(*args): thread = ThreadWithReturnValue(target = f, args = args) thread.start() - while thread.isAlive(): - wx.MilliSleep(300) - + while thread.isAlive(): if progress_dlg.WasCancelled() or progress_dlg.WasSkipped(): thread.kill() else: + wx.MilliSleep(300) progress_dlg.Pulse() - wx.SafeYield() + wx.SafeYield() progress_dlg.Destroy() From 5dbade72ba8505fd303d458ad9e8d645ed08df98 Mon Sep 17 00:00:00 2001 From: Capocchi L Date: Tue, 24 Mar 2020 23:22:54 +0100 Subject: [PATCH 7/8] bug fix --- Decorators.py | 1 + 1 file changed, 1 insertion(+) diff --git a/Decorators.py b/Decorators.py index fc7269e2..3018ea7d 100644 --- a/Decorators.py +++ b/Decorators.py @@ -204,6 +204,7 @@ def wrapper(*args): while thread.isAlive(): if progress_dlg.WasCancelled() or progress_dlg.WasSkipped(): thread.kill() + break else: wx.MilliSleep(300) progress_dlg.Pulse() From 55bb922d53fc3b7aeccf236c98d0f962d2da3c16 Mon Sep 17 00:00:00 2001 From: Capocchi L Date: Tue, 24 Mar 2020 23:40:38 +0100 Subject: [PATCH 8/8] bug fix --- .travis.yml | 2 +- Utilities.py | 19 +++++++------------ 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/.travis.yml b/.travis.yml index 15606ee2..460aee40 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 requests + - pip install PyPubSub==3.3.0 pyyaml ruamel.yaml # command to run script: travis_wait 20 python devsimpy.py examples/model0.dsp quit \ No newline at end of file diff --git a/Utilities.py b/Utilities.py index 75be4da3..1db5b49e 100644 --- a/Utilities.py +++ b/Utilities.py @@ -65,8 +65,6 @@ import fnmatch import urllib.request, urllib.parse, urllib.error, urllib.request, urllib.error, urllib.parse, http.client from urllib.request import urlretrieve - -import requests import pip import importlib @@ -182,8 +180,9 @@ def check_internet(): url = 'https://github.com/capocchi/DEVSimPy' timeout = 5 try: - _ = requests.get(url, timeout=timeout) - except requests.ConnectionError as e: + + _ = urllib.request.urlopen(url, timeout=timeout) + except Exception as e: print(e) return False else: @@ -209,22 +208,18 @@ def downloadFromURL(url): """ try: - # downloading with requests + # downloading with request # download the file contents in binary format - r = requests.get(url) - except requests.ConnectionError as e: + r = urllib.request.urlopen(url) + except Exception as e: print(e) return None else: - if r.status_code == 200: + if r.getcode() == 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)