Changeset 3493 for lliurex-up/trunk/fuentes/lliurex-up-cli
- Timestamp:
- Feb 1, 2017, 2:49:56 PM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
lliurex-up/trunk/fuentes/lliurex-up-cli/usr/sbin/lliurex-upgrade
r3449 r3493 7 7 import sys 8 8 import commands 9 import time9 import datetime 10 10 11 11 class LliurexUpCli(object): … … 13 13 14 14 self.lliurexcore = lliurex.lliurexup.LliurexUpCore() 15 log_msg="------------------------------------------\n"+"LLIUREX-UP-CLI STARTING AT: " + datetime.datetime.today().strftime("%d/%m/%y %H:%M:%S") +"\n------------------------------------------" 16 self.log(log_msg) 15 17 self.checkInitialFlavour() 16 18 … … 18 20 19 21 self.targetMetapackage=self.lliurexcore.checkInitialFlavour() 20 21 # try: 22 # self.targetMetapackage=self.lliurexcore.checkFlavour() 23 24 # #if self.targetMetapackage !=None: 25 # self.metapackageRef=self.lliurexcore.metapackageRef 26 # if len(self.metapackageRef)==0: 27 # self.lliurexcore.getTargetMetapackage() 28 # self.metapackageRef=sorted(self.metapackageRef) 29 30 # self.previousFlavours=self.lliurexcore.previuosFlavours 31 # if len(self.previousFlavours)==0: 32 # self.lliurexcore.getPreviuosFlavours() 33 # except Exception as e: 34 # print e 22 log_msg="Initial check metapackage. Metapackage to install: " + str(self.targetMetapackage) 23 self.log(log_msg) 24 log_msg="Get initial flavours: " + str(self.lliurexcore.previuosFlavours) 25 self.log(log_msg) 26 35 27 36 28 def initActionsScript(self): 37 29 38 30 command=self.lliurexcore.initActionsScript(self.initActionsArg) 31 39 32 try: 40 33 os.system(command) 41 34 log_msg="Exec Init-Actions" 35 self.log(log_msg) 42 36 except Exception as e: 37 log_msg="Exec Init-Actions.Error: " +str(e) 38 self.log(log_msg) 43 39 print e 44 40 … … 46 42 47 43 is_lliurexup_updated=self.lliurexcore.isLliurexUpIsUpdated() 44 48 45 49 46 if not is_lliurexup_updated: 50 47 print (" [Lliurex-up]: Updating Lliurex-up") 51 48 is_lliurexup_installed=self.lliurexcore.installLliurexUp() 49 log_msg="Installing lliurex-up. Returncode: " + str(is_lliurexup_installed['returncode']) + ". Error: " + str(is_lliurexup_installed['stderrs']) 50 self.log(log_msg) 52 51 print (" [Lliurex-up]: Lliurex-up is now udpate and will be reboot now" ) 53 52 time.sleep(3) … … 55 54 56 55 else: 56 log_msg="Checking lliurex-up. Is lliurex-up updated: "+ str(is_lliurexup_updated) 57 self.log(log_msg) 57 58 print (" [Lliurex-up]: Lliurex-up is updated.Nothing to do") 58 59 … … 66 67 67 68 if is_mirror_updated['action']=='update': 69 log_msg="Checking mirror. Is mirror update: False" 70 self.log(log_msg) 68 71 if not is_mirror_running: 69 72 response=raw_input(' [LLiurex-up]: Do you want update mirror (yes/no): ').lower() 70 73 if response.startswith('y'): 74 log_msg="Update lliurex-mirror: Yes" 75 self.log(log_msg) 71 76 print(" [Lliurex-up]: Updating mirror. Wait a moment please") 72 77 command='lliurex-mirror update llx16' 73 78 os.system(command) 74 79 else: 80 log_msg="Update lliurex-mirror: No" 81 self.log(log_msg) 75 82 print(" [Lliurex-up]: Mirror update.Nothing to do") 76 83 else: 84 log_msg="Checking mirror. Is mirror update: None" 85 self.log(log_msg) 77 86 print(" [Lliurex-up]: Nothing to do with mirror") 78 87 … … 82 91 83 92 if self.targetMetapackage == None: 84 self.flavourToInstall=self.lliurexcore.requiresInstallFlavour() 85 if self.flavourToInstall != None: 86 print " [Lliurex-up]: Installation of flavour is required: " +str(self.flavourToInstall) 87 is_flavour_installed=self.lliurexcore.installInitialFlavour(self.flavourToInstall) 88 returncode=is_flavour_installed['returncode'] 89 error=is_flavour_installed['stderrs'] 90 print " [Lliurex-up]: Flavour is now installed: " + str(returncode) + " Error: " + str(error) 93 # self.flavourToInstall=self.lliurexcore.requiresInstallFlavour() 94 # if self.flavourToInstall != None: 95 # log_msg="Requires Install this Flavour: " + str(self.flavourToInstall) 96 # self.log(log_msg) 97 # print " [Lliurex-up]: Installation of flavour is required: " +str(self.flavourToInstall) 98 # is_flavour_installed=self.lliurexcore.installInitialFlavour(self.flavourToInstall) 99 # returncode=is_flavour_installed['returncode'] 100 # error=is_flavour_installed['stderrs'] 101 # print " [Lliurex-up]: Flavour is now installed: " + str(returncode) + " Error: " + str(error) 102 # log_msg="Install initial flavour:" + flavourToInstall + ": Returncode: " + str(returncode) + " Error: " + str(error) 103 # self.log(log_msg) 104 # else: 105 print " [Lliurex-up]: Installation of metapackage is not required" 106 107 else: 108 print " [Lliurex-up]: Installation of metapackage is required: " + str(self.targetMetapackage) 109 is_flavour_installed=self.lliurexcore.installInitialFlavour(self.targetMetapackage) 110 self.returncode_initflavour=is_flavour_installed['returncode'] 111 error=is_flavour_installed['stderrs'] 112 log_msg="Install initial flavour:" + self.targetMetapackage + ": Returncode: " + str(self.returncode_initflavour) + " Error: " + str(error) 113 self.log(log_msg) 114 print " [Lliurex-up]: Metapackage is now installed: " + str(returncode) + " Error: " + str(error) 115 116 117 def checkingIncorrectFlavours(self): 118 119 incorrectFlavours=self.lliurexcore.checkIncorrectFlavours() 120 log_msg="Checking incorrect metapackages. Others metapackages detected: " + str(incorrectFlavours) 121 self.log(log_msg) 122 123 return incorrectFlavours 124 125 126 def checkPreviousUpgrade(self): 127 128 error=False 129 if self.returncode_initflavour!=0: 130 error=True 131 132 else: 133 if self.version_update["candidate"]!=None: 134 if self.version_update["installed"]!=self.version_update["candidate"]: 135 error=True 91 136 else: 92 print " [Lliurex-up]: Installation of flavour is not required" 93 else: 94 print " [Lliurex-up]: Installation of flavour is required: " + str(self.targetMetapackage) 95 is_flavour_installed=self.lliurexcore.installInitialFlavour(self.targetMetapackage) 96 returncode=is_flavour_installed['returncode'] 97 error=is_flavour_installed['stderrs'] 98 print " [Lliurex-up]: Flavour is now installed: " + str(returncode) + " Error: " + str(error) 99 100 # def requiresInstallFlavour(self): 101 102 # flavourToInstall=None 103 104 # self.flavours=self.lliurexcore.flavours 105 # if not 'None' in self.previousFlavours: 106 # if self.previousFlavours !=self.flavours: 107 # flavourToInstall=self.parseFlavourToInstall(self.previousFlavours) 108 109 # else: 110 # if self.metapackageRef != self.flavours: 111 # flavourToInstall=self.parseFlavourToInstall(self.metapackageRef) 112 113 # return flavourToInstall 114 115 #def requiresInstallFlavour 116 117 # def parseFlavourToInstall(self,flavours): 118 119 # parse_flavour="" 120 121 # for item in flavours: 122 # if item != "edu": 123 # parse_flavour=parse_flavour + " " + "lliurex-meta-" + item 124 125 # return parse_flavour 126 127 def checkingIncorrectFlavours(self): 128 129 incorrectFlavours=self.lliurexcore.checkIncorrectFlavours() 130 return incorrectFlavours 131 # count=0 132 # ref_flavour=["lliurex-meta-server","lliurex-meta-client", "lliurex-meta-desktop", "lliurex-meta-music", "lliurex-meta-pyme", "lliurex-meta-infantil"] 133 # self.incorrect_flavours=[] 134 135 # for item in self.packages: 136 # if item in ref_flavour: 137 # self.incorrect_flavours.append(item) 138 139 # if len(self.incorrect_flavours)>0: 140 # for item in self.incorrect_flavours: 141 # if self.targetMetapackage != None: 142 # if item != self.targetMetapackage: 143 # count=count+1 144 # else: 145 # meta=item.split("-")[2] 146 # if 'None' in self.previousFlavours: 147 # if not meta in self.metapackageRef: 148 # count=count+1 149 # else: 150 # if not meta in self.previousFlavours: 151 # count=count+1 152 153 # if count>0: 154 # return True 155 # else: 156 # return False 157 158 159 def checkPreviousUpgrade(self): 160 161 error=False 162 if self.version_update["candidate"]!=None: 163 if self.version_update["installed"]!=self.version_update["candidate"]: 164 error=True 165 else: 166 if self.version_update["installed"]!=self.version_available["candidate"]: 167 error=True 137 if self.version_update["installed"]!=self.version_available["candidate"]: 138 error=True 168 139 169 140 return error … … 174 145 try: 175 146 os.system(command) 147 log_msg="Exec Pre-Actions" 148 self.log(log_msg) 176 149 177 150 except Exception as e: 151 log_msg="Exec Pre-Actions. Error " +str(e) 152 self.log(log_msg) 178 153 print e 179 154 … … 183 158 try: 184 159 os.system(command) 160 log_msg="Exec Dist-uggrade" 161 self.log(log_msg) 185 162 except Exception as e: 163 log_msg="Exec Dist-uggrade.Error : " +str(e) 164 self.log(log_msg) 186 165 print e 187 166 188 # def checkFinalFlavour(self): 189 190 # flavourToInstall=None 191 192 # try: 193 # self.targetMetapackage=self.lliurexcore.checkFlavour() 194 # if self.targetMetapackage==None: 195 # flavourToInstall=self.requiresInstallFlavour() 196 # else: 197 # flavourToInstall=self.targetMetapackage 198 199 # except Exception as e: 200 # print e 167 def checkingFinalFlavourToInstall(self): 168 169 #self.flavourToInstall=self.lliurexcore.checkFinalFlavour() 170 self.flavourToInstall=self.lliurexcore.checkFlavour() 171 172 log_msg="Final check metapackage. Metapackage to install: " + str(self.flavourToInstall) 173 self.log(log_msg) 174 175 if self.flavourToInstall!=None: 176 print (" [Lliurex-up]: Install of metapackage is required: " + str(self.flavourToInstall)) 201 177 202 # return flavourToInstall203 204 205 def checkingFinalFlavourToInstall(self):206 207 self.flavourToInstall=self.lliurexcore.checkFinalFlavour()208 209 if self.flavourToInstall!=None:210 print (" [Lliurex-up]: Install of meta is required: " + str(self.flavourToInstall))211 178 command=self.lliurexcore.installFinalFlavour(self.flavourToInstall) 212 179 try: 213 180 os.system(command) 181 214 182 except Exception as e: 215 183 print e 216 184 else: 217 print (" [Lliurex-up]: Meta is correct. Nothing to do") 218 219 return 185 print (" [Lliurex-up]: metapackage is correct. Nothing to do") 220 186 221 187 … … 225 191 try: 226 192 os.system(command) 193 log_msg="Exec Post-Actions" 194 self.log(log_msg) 227 195 except Exception as e: 228 196 print e … … 230 198 def checkFinalUpgrade(self): 231 199 232 print (" [Lliurex-up]: Checking ")200 print (" [Lliurex-up]: Checking Dist-upgrade ") 233 201 error=self.lliurexcore.checkErrorDistUpgrade() 234 202 235 # cmd='dpkg -l | grep "^i[^i]" >' + self.errorupgrade_token236 # os.system(cmd)237 238 # if os.path.exists(self.errorupgrade_token):239 # aux = open(self.errorupgrade_token,'r')240 # lines = aux.readlines()241 # aux.close()242 243 # if len(lines)>0:244 # error=True245 246 # else:247 # j=0248 # cmd='apt-get dist-upgrade -sV >' + self.finalupgrade_token249 # os.system(cmd)250 # if os.path.exists(self.finalupgrade_token):251 # aux = open(self.finalupgrade_token,'r')252 # lines = aux.readlines()253 # aux.close()254 255 # for x in lines:256 # if 'Inst' in x:257 # j=j+1258 259 # if j>0:260 # error=True261 203 if error: 262 204 print(" [Lliurex-up]: The updated process is endend with errors") 205 log_msg="Dist-upgrade process ending with errors" 263 206 264 207 else: 265 print(" [Lliurex-up]: The system is now update") 208 print(" [Lliurex-up]: The system is now update") 209 log_msg="Dist-upgrade process ending OK" 210 211 self.log(log_msg) 212 213 def log(self,msg): 214 215 log_file="/var/log/lliurex-up.log" 216 f=open(log_file,"a+") 217 f.write(msg + '\n') 218 f.close() 266 219 267 220 def main(self,mode): … … 271 224 272 225 else: 226 mode="nomal" 273 227 self.initActionsArg="initActions" 274 228 229 log_msg="Mode of execution: " + str(mode) 230 self.log(log_msg) 231 275 232 print(" [Lliurex-up]: Checking system") 276 233 self.initActionsScript() … … 281 238 print(" [Lliurex-up]: Checking LliurexVersion from local repository") 282 239 self.version_update=self.lliurexcore.getLliurexVersionLocal() 240 log_msg="Get LliurexVersion installed: " + str(self.version_update["installed"]) 241 self.log(log_msg) 242 log_msg="Get LliurexVersion candidate from Local repository: " + str(self.version_update["candidate"]) 243 self.log(log_msg) 244 283 245 print(" [Lliurex-up]: Checking LliurexVersion from lliurex.net") 284 246 self.version_available=self.lliurexcore.getLliurexVersionLliurexNet() 247 log_msg="Get LliurexVersion candidate from Lliurex Net: " + str(self.version_available["candidate"]) 248 self.log(log_msg) 285 249 286 250 print(" [Lliurex-up]: Checking if installation of flavour is required") … … 293 257 if len(self.packages)>0: 294 258 print(" [Lliurex-up]:List of packages to update") 259 log_msg="Number of packages: "+ str(len(self.packages)) 260 self.log(log_msg) 261 295 262 for item in self.packages: 296 263 print item + ": " + self.packages[item]["candidate"] … … 310 277 311 278 else: 279 log_msg="Cancel the update" 280 self.log(log_msg) 312 281 print(" [Lliurex-up]: Cancel the update") 313 282 self.lliurexcore.cleanEnvironment()
Note: See TracChangeset
for help on using the changeset viewer.