Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
60 changes: 45 additions & 15 deletions Decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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
Expand Down
47 changes: 21 additions & 26 deletions Utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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)
Expand All @@ -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

Expand Down