-
Notifications
You must be signed in to change notification settings - Fork 2
/
updateAutoplot.jy
70 lines (59 loc) · 2.96 KB
/
updateAutoplot.jy
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
# title: update Autoplot
# label: update Autoplot
# Update the jar used to run the application.
version= getParam( 'version', 'devel', 'Autoplot version number', [ 'latest', 'devel', '20190221a' ] )
# find the physical Jar file for Autoplot
from org.autoplot import AutoplotUI
r1= AutoplotUI.getClassLoader().getResource("org/autoplot/AutoplotUI.class")
if ( r1==None ):
r1= AutoplotUI.getClassLoader().getResource("org/autoplot/AutoplotUI.class")
resource= r1.toString()
if ( resource.startswith('jar:file:') ) :
i2= resource.index('!')
jarfile= resource[9:i2]
print 'current jar file: ' + jarfile
else:
raise Exception('unable to update jar file, autoplot.jar not found.')
from java.io import File
from java.nio.file import Files, FileSystems,Paths
from javax.swing import JOptionPane
from javax.imageio import ImageIO
new=''
if ( jarfile.find( 'autoplot.jar' )>-1 ): # may end with version
if ( not jarfile.endswith('autoplot.jar') ):
i= jarfile.find( 'autoplot.jar' )
jarfile= jarfile[0:i+12]
response= JOptionPane.showConfirmDialog(getViewWindow(),'replace '+jarfile+
(' with http://autoplot.org/jnlp/%s/autoplot.jar?' % version),'update',JOptionPane.OK_CANCEL_OPTION )
print 'response=', response
if ( response==JOptionPane.OK_OPTION ):
print 'replacing single jar version of autoplot in ' + jarfile
new= downloadResourceAsTempFile(URL('http://autoplot.org/jnlp/%s/autoplot.jar' % version ),3600,monitor)
new= new.toString()
if ( File(jarfile).exists() ):
print 'jarfile '+jarfile+' exists.'
if Files.isSymbolicLink( File(jarfile).toPath() ):
print 'removing symbolic link '+jarfile
File(jarfile).delete()
elif ( jarfile.endswith('autoplot.jar') ):
print 'renaming ' + jarfile + ' to ' + jarfile+'.t'
r= File(jarfile).renameTo(File(jarfile+'.t'))
if ( r!=0 ):
raise Exception('cannot mv ' + jarfile + ' ' + jarfile+'.t' )
print 'deleting '+jarfile
if ( not File(jarfile).delete() ):
raise Exception('cannot rm '+jarfile )
else:
print 'jarfile '+jarfile + ' does not exist. Deleting anyway because it might be symlink'
File(jarfile).delete()
print 'renaming downloaded file to '+jarfile+'.'+version
File( new ).renameTo( File( jarfile+'.'+version ) )
Files.createSymbolicLink( Paths.get(jarfile,[]),Paths.get(jarfile+'.'+version,[]),[])
else:
new= 'abort'
if ( new=='' ):
JOptionPane.showMessageDialog(getViewWindow(),'unable to update','update failed, unable to find autoplot.jar.',JOptionPane.WARNING_MESSAGE)
elif ( new=='abort' ):
pass
else:
JOptionPane.showMessageDialog(getViewWindow(),'updated to '+version+'. Restart Autoplot.','update',JOptionPane.INFORMATION_MESSAGE)