31
31
from packaging import version
32
32
from bs4 import BeautifulSoup
33
33
34
- REL_URL = 'https://www.mathworks.com/products/compiler/matlab-runtime.html'
35
- VER_LIMIT = '9.3' # release URLs get weird before that..
34
+ REL_URL = "https://www.mathworks.com/products/compiler/matlab-runtime.html"
35
+ VER_LIMIT = "9.3" # release URLs get weird before that..
36
+
36
37
37
38
def call (cmd , split = True ):
38
39
if split :
@@ -43,16 +44,16 @@ def call(cmd, split=True):
43
44
44
45
with request .urlopen (REL_URL ) as res :
45
46
if res .status != 200 :
46
- raise RuntimeError (' Could not open matlab release URL' )
47
+ raise RuntimeError (" Could not open matlab release URL" )
47
48
html = res .read ()
48
49
49
- soup = BeautifulSoup (html , ' html.parser' )
50
- ver_re = re .compile (r' (R2\d{3}.) \((\d\.\d)\)' )
51
- rel_re = re .compile (r' Release/(\d+)/' )
50
+ soup = BeautifulSoup (html , " html.parser" )
51
+ ver_re = re .compile (r" (R2\d{3}.) \((\d\.\d)\)" )
52
+ rel_re = re .compile (r" Release/(\d+)/" )
52
53
53
54
dockers = []
54
- for row in soup .find_all (' table' )[0 ].find_all ('tr' ):
55
- tds = row .find_all ('td' )
55
+ for row in soup .find_all (" table" )[0 ].find_all ("tr" ):
56
+ tds = row .find_all ("td" )
56
57
if len (tds ) >= 4 :
57
58
name = tds [0 ].text
58
59
match = ver_re .match (name )
@@ -62,55 +63,52 @@ def call(cmd, split=True):
62
63
if version .parse (mcr_ver ) <= version .parse (VER_LIMIT ):
63
64
continue
64
65
try :
65
- link = tds [2 ].a .get (' href' )
66
+ link = tds [2 ].a .get (" href" )
66
67
except (KeyError , ValueError ):
67
- raise RuntimeError (' Error parsing matlab release page' )
68
- if ' glnxa64' not in link :
69
- raise RuntimeError (' Error parsing matlab release page link' )
68
+ raise RuntimeError (" Error parsing matlab release page" )
69
+ if " glnxa64" not in link :
70
+ raise RuntimeError (" Error parsing matlab release page link" )
70
71
match = rel_re .search (link )
71
72
if match :
72
- mcr_ver = ' {}.{}' .format (mcr_ver , match .groups ()[0 ])
73
+ mcr_ver = " {}.{}" .format (mcr_ver , match .groups ()[0 ])
73
74
dockers .append ((mcr_name , mcr_ver , link ))
74
75
75
76
76
- variants = [
77
- ('Dockerfile-full.template' , '' ),
78
- ('Dockerfile-core.template' , '-core' )
79
- ]
77
+ variants = [("Dockerfile-full.template" , "" ), ("Dockerfile-core.template" , "-core" )]
80
78
new_tags = []
81
79
82
80
for docker in dockers :
83
81
mcr_name , mcr_ver , link = docker
84
- if len (mcr_ver .split ('.' )) == 2 :
85
- mcr_ver = mcr_ver + '.0'
86
- mcr_ver_maj = '.' .join (mcr_ver .split ('.' )[0 :2 ])
87
- mcr_ver_dir = ' v{}' .format (mcr_ver_maj .replace ('.' , '' ))
88
- if not call (' git checkout {}' .format (mcr_name )):
89
- call (' git checkout -b {}' .format (mcr_name ))
82
+ if len (mcr_ver .split ("." )) == 2 :
83
+ mcr_ver = mcr_ver + ".0"
84
+ mcr_ver_maj = "." .join (mcr_ver .split ("." )[0 :2 ])
85
+ mcr_ver_dir = " v{}" .format (mcr_ver_maj .replace ("." , "" ))
86
+ if not call (" git checkout {}" .format (mcr_name )):
87
+ call (" git checkout -b {}" .format (mcr_name ))
90
88
for (template , suffix ) in variants :
91
- tag = ' {}{}' .format (mcr_ver , suffix )
92
- if call (' git rev-parse --verify {}' .format (tag )):
93
- print (' Skipping {}/{}, already present' .format (mcr_name , tag ))
89
+ tag = " {}{}" .format (mcr_ver , suffix )
90
+ if call (" git rev-parse --verify {}" .format (tag )):
91
+ print (" Skipping {}/{}, already present" .format (mcr_name , tag ))
94
92
continue
95
- print (' Adding {}/{}' .format (mcr_name , tag ))
96
- if not call (' git merge master' ):
97
- raise RuntimeError (' Merging master failed, will not continue' )
93
+ print (" Adding {}/{}" .format (mcr_name , tag ))
94
+ if not call (" git merge master" ):
95
+ raise RuntimeError (" Merging master failed, will not continue" )
98
96
with open (template ) as f :
99
97
lines = f .read ()
100
- lines = lines .replace (' %%MATLAB_VERSION%%' , mcr_name )
101
- lines = lines .replace (' %%MCR_VERSION%%' , mcr_ver_dir )
102
- lines = lines .replace (' %%MCR_LINK%%' , link )
103
- with open (' Dockerfile' , 'w+' ) as f2 :
98
+ lines = lines .replace (" %%MATLAB_VERSION%%" , mcr_name )
99
+ lines = lines .replace (" %%MCR_VERSION%%" , mcr_ver_dir )
100
+ lines = lines .replace (" %%MCR_LINK%%" , link )
101
+ with open (" Dockerfile" , "w+" ) as f2 :
104
102
f2 .write (lines )
105
- call (' git add Dockerfile' )
106
- # Tag X.Y.Z[-variant] - see circle CI for shared tag X.Y[-variant]
107
- call ([' git' , ' commit' , '-m' , ' Auto-Update' ], split = False )
108
- call (' git tag {}' .format (tag ))
103
+ call (" git add Dockerfile" )
104
+ # Tag X.Y.Z[-variant] - see circle CI for shared tag X.Y[-variant]
105
+ call ([" git" , " commit" , "-m" , " Auto-Update" ], split = False )
106
+ call (" git tag {}" .format (tag ))
109
107
new_tags .append (tag )
110
- call (' git checkout master' )
108
+ call (" git checkout master" )
111
109
112
110
if new_tags :
113
- print (' New tags have been added, verify and update to git with:' )
114
- print (' git push --all' )
111
+ print (" New tags have been added, verify and update to git with:" )
112
+ print (" git push --all" )
115
113
for tag in reversed (new_tags ):
116
- print (' git push origin {}' .format (tag ))
114
+ print (" git push origin {}" .format (tag ))
0 commit comments