3
3
import json
4
4
from distutils .version import StrictVersion
5
5
6
- response = request .urlopen ('https://api.github.com/repos/tfausak/rattletrap/releases/latest' )
7
-
8
- js = json .loads (response .read ())
9
-
10
- cur_ver = '0.0.0'
11
- binaries = [f for f in os .listdir ('.' ) if not f .endswith ('.py' ) and os .path .isfile (f )]
12
- print (binaries )
13
- if len (binaries ) > 0 :
14
- cur_ver = binaries [0 ].split ('-' )[1 ]
15
- update = StrictVersion (js ['name' ]) > StrictVersion (cur_ver )
16
- print (f'GitHub version: { js ["name" ]} \n '
17
- f'Current version: { cur_ver } \n '
18
- f'Update? { update } ' )
19
- if update :
20
- for file in binaries :
21
- os .remove (file )
22
-
23
- for asset in js ['assets' ]:
24
-
25
- print ('Downloading {}' .format (asset ['name' ]))
26
- request .urlretrieve (asset ['browser_download_url' ], asset ['name' ])
6
+ from carball .rattletrap .rattletrap_utils import get_rattletrap_binaries , get_rattletrap_path
7
+
8
+
9
+ def update_rattletrap ():
10
+ path = get_rattletrap_path ()
11
+ print ('updating rattletrap in path' , path )
12
+ files = os .listdir (path )
13
+ print ('files in path' , files )
14
+
15
+ cur_ver = '0.0.0'
16
+ binaries = get_rattletrap_binaries (path )
17
+ print ('existing found' , binaries )
18
+
19
+ response = request .urlopen ('https://api.github.com/repos/tfausak/rattletrap/releases/latest' )
20
+
21
+ js = json .loads (response .read ())
22
+
23
+ if len (binaries ) > 0 :
24
+ cur_ver = binaries [0 ].split ('-' )[1 ]
25
+ update = StrictVersion (js ['name' ]) > StrictVersion (cur_ver )
26
+ print (f'GitHub version: { js ["name" ]} \n '
27
+ f'Current version: { cur_ver } \n '
28
+ f'Update? { update } ' )
29
+ if update :
30
+ for file in binaries :
31
+ os .remove (file )
32
+
33
+ for asset in js ['assets' ]:
34
+ print ('Downloading {}' .format (asset ['name' ]))
35
+ new_file = os .path .join (path , asset ['name' ])
36
+ request .urlretrieve (asset ['browser_download_url' ], filename = new_file )
37
+ print ('making file executable' , new_file )
38
+ os .chmod (new_file , 0o777 )
39
+
40
+
41
+ if __name__ == "__main__" :
42
+ update_rattletrap ()
0 commit comments