Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

#$Id: update.py 148 2013-07-09 12:25:20Z sarkiss $ 

"""This module is used for Help --> Check for Updates... 

""" 

import sys, os, pdb, user, subprocess, urllib, shutil 

from about import version 

from utils import rcFolder 

from download import download 

import wx 

 

def DoUpdates(update_url): 

    destFile = os.path.join(rcFolder, 'pyrx_update.tar.gz') 

    if not download(update_url, destFile): return 

    updateFolder = os.path.join(rcFolder, 'update') 

    executable = sys.executable 

    if os.path.exists(updateFolder): 

        shutil.rmtree(updateFolder) 

    os.mkdir(updateFolder) 

    script = sys.argv[0] 

 

    if os.name == 'nt': 

        executable = executable.replace("\\","""\\\\""") 

        script = script.replace("\\","""\\\\""") 

 

    executable = '"'+executable+'"' 

    script = '"'+script+'"' 

 

    txt = """ 

import time,os,tarfile,subprocess 

time.sleep(1) 

tarfile.open("%s").extractall("%s") 

subprocess.call([%s,%s]) 

"""%(destFile, updateFolder, executable, script) 

    updatePy = os.path.join(rcFolder, 'update.py') 

    open(updatePy,'w').write(txt) 

    cmd = executable +" " +updatePy 

    if os.name == 'nt': 

        cmd = cmd.encode() 

    else: 

        cmd += ' &' 

 

    subprocess.Popen(cmd, shell=True) 

    os._exit(0) 

 

def CheckForUpdates(): 

    txt = urllib.urlopen("http://pyrx.sourceforge.net/updates/check").readlines() 

    update_versions  = txt[0].split('\t') 

    upgrade_versions  = txt[1].split('\t') 

    frame = wx.GetApp().GetTopWindow() 

    if version in update_versions: 

        if update_versions[0]: 

            updateFolder = os.path.join(rcFolder, 'update') 

            if os.path.exists(updateFolder) and os.path.getctime(updateFolder) > float(update_versions[1]): #used time.time() to insert this into check 

                dlg = wx.MessageDialog(frame, 'No new updates are available at this time.', 

                                       'No Updates', wx.OK | wx.ICON_INFORMATION) 

                dlg.ShowModal() 

                dlg.Destroy() 

                return 

            dlg = wx.MessageDialog(frame, 'New updates are available.\nWould you like to install them?', 

                                   "Updates are Ready", wx.YES_NO | wx.ICON_INFORMATION) 

            if dlg.ShowModal() == wx.ID_YES: 

                dlg.Destroy() 

                DoUpdates(update_versions[0]) 

            else: 

                dlg.Destroy() 

            updateFolder = os.path.join(rcFolder, 'update') 

        else: 

            dlg = wx.MessageDialog(frame, 'No updates are available at this time.', 

                                   'No Updates', wx.OK | wx.ICON_INFORMATION) 

            dlg.ShowModal() 

            dlg.Destroy() 

 

    elif version in upgrade_versions: 

            dlg = wx.MessageDialog(frame, 'Please visit http://pyrx.sourceforge.net to upgrade your version of PyRx ('+version+').', 

                                   "Needs Upgrade", wx.OK | wx.ICON_INFORMATION) 

            dlg.ShowModal() 

            dlg.Destroy() 

    else: 

        dlg = wx.MessageDialog(frame, 'No updates are available at this time.', 

                               'No Updates', wx.OK | wx.ICON_INFORMATION) 

        dlg.ShowModal() 

        dlg.Destroy() 

 

def Update(event): 

    frame = wx.GetApp().GetTopWindow() 

    frame.TryCommand(CheckForUpdates)