@@ -39,24 +39,48 @@ def initialize(self):
39
39
platform_patch = IntentBuilder ("PlatformPatchIntent" ). \
40
40
require ("PlatformPatch" ).build ()
41
41
self .register_intent (platform_patch , self .patch_platform )
42
- if self .platform_build is not 2 :
43
- self .patch_platform ("" )
44
-
45
- def patch_platform (self , message ):
46
- if self .platform_type == "mycroft_mark_1" or self .platform_type == "picroft" :
47
- if self .platform_build < 4 or self .platform_build is None and self .platform_build is not 2 :
48
- try :
49
- script_fn = NamedTemporaryFile ().name
50
- ret_code = call ('curl -sL https://mycroft.ai/to/platform_patch_1 | base64 --decode > ' + script_fn , shell = True )
51
- if ret_code == 0 :
52
- if call ('bash ' + script_fn , shell = True ) == 0 :
53
- self .speak_dialog ("platform.patch.success" )
54
- return
55
- except :
56
- pass
57
- self .speak_dialog ("platform.patch.failure" )
58
- else :
42
+ if self .is_eligible () and self .must_apply ():
43
+ self .patch_platform ()
44
+
45
+ @staticmethod
46
+ def cmd (name ):
47
+ if call (name , shell = True ) != 0 :
48
+ raise RuntimeError ('Failed to run command: ' + name )
49
+
50
+ def is_eligible (self ):
51
+ """Duplicate logic exists in remote platform patch script"""
52
+ return self .platform_type == "mycroft_mark_1"
53
+
54
+ def must_apply (self ):
55
+ """Duplicate logic exists in remote platform patch script"""
56
+ return self .platform_build is None or self .platform_build < 9
57
+
58
+ @classmethod
59
+ def download_patch (cls ):
60
+ filename = NamedTemporaryFile ().name
61
+ cls .cmd ('curl -sL https://mycroft.ai/to/platform_patch_1 | base64 --decode > ' + filename )
62
+ return filename
63
+
64
+ @classmethod
65
+ def run_patch (cls , filename ):
66
+ """Replaces crontab, updates GPG key, and sets platform_build to 9"""
67
+ cls .cmd ('bash ' + filename )
68
+
69
+ def patch_platform (self ):
70
+ if not self .is_eligible ():
59
71
self .speak_dialog ("platform.patch.not.possible" )
72
+ elif not self .must_apply ():
73
+ self .speak_dialog ("platform.patch.not.needed" )
74
+ else :
75
+ try :
76
+ name = self .download_patch ()
77
+ self .run_patch (name )
78
+ self .speak_dialog ("platform.patch.success" )
79
+ except Exception as e :
80
+ self .speak_dialog ("platform.patch.failure" , data = {
81
+ 'error' : str (e ),
82
+ 'type' : e .__class__ .__name__
83
+ })
60
84
61
85
def stop (self ):
62
86
pass
0 commit comments