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
- pip install PyPubSub==3.3.0 pyyaml ruamel.yaml requests

# command to run
script: travis_wait 20 python devsimpy.py examples/model0.dsp quit
15 changes: 8 additions & 7 deletions Decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -180,7 +181,7 @@ def wrapper(*args):
wx.SafeYield()

progress_dlg.Destroy()

return thread.join()

return wrapper
Expand Down
119 changes: 74 additions & 45 deletions Utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,84 +178,113 @@ 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
fn = downloadFromURL("https://github.com/capocchi/DEVSimPy/archive/master.zip")

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

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
Expand Down
16 changes: 14 additions & 2 deletions devsimpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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. """
Expand Down