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/Decorators.py b/Decorators.py index 6f637be6..3018ea7d 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): @@ -175,13 +201,17 @@ def wrapper(*args): thread = ThreadWithReturnValue(target = f, args = args) thread.start() - while thread.isAlive(): - wx.MilliSleep(300) - progress_dlg.Pulse() - wx.SafeYield() + while thread.isAlive(): + if progress_dlg.WasCancelled() or progress_dlg.WasSkipped(): + thread.kill() + break + else: + wx.MilliSleep(300) + progress_dlg.Pulse() + wx.SafeYield() progress_dlg.Destroy() - + return thread.join() return wrapper diff --git a/Utilities.py b/Utilities.py index ec53d64c..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) @@ -244,23 +239,23 @@ 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) - 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