You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

105 lines
3.3 KiB

  1. #-*- coding: utf-8 -*-
  2. # Copyright 2010 Calculate Ltd. http://www.calculate-linux.org
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. import os
  16. from os import path
  17. import re
  18. import sys
  19. import pwd
  20. import time
  21. import traceback
  22. from datavars import DataVarsUpdate, DataVars, __version__,__app__
  23. from calculate.lib.cl_template import Template, ProgressTemplate,TemplatesError
  24. from calculate.lib.utils.files import runOsCommand, isMount
  25. from calculate.lib.utils.common import getpathenv,appendProgramToEnvFile, \
  26. removeProgramToEnvFile
  27. from calculate.core.server.func import safetyWrapper
  28. from calculate.lib.cl_lang import setLocalTranslate,getLazyLocalTranslate
  29. setLocalTranslate('cl_update3',sys.modules[__name__])
  30. __ = getLazyLocalTranslate(_)
  31. class UpdateError(Exception):
  32. """Update Error"""
  33. class Update:
  34. """
  35. Update logic object
  36. Has fundamental method update for system update
  37. """
  38. def __init__(self):
  39. self.homeDir = ""
  40. self.clTempl = None
  41. self.clVars = None
  42. def displayTemplatesApplied(self,dirsFiles):
  43. """
  44. Display templates are applied (--verbose)
  45. """
  46. self.printSUCCESS(_("The following files were changed")+":")
  47. for nameF in dirsFiles[1]:
  48. nameFile = nameF
  49. if nameFile[:1] != "/":
  50. nameFile = "/" + nameFile
  51. self.printSUCCESS(" "*5 + nameFile)
  52. def applyTemplatesFromUser(self):
  53. """Apply templates for user"""
  54. if self.clTempl:
  55. self.closeClTemplate()
  56. self.clTempl = ProgressTemplate(self.setProgress,self.clVars,
  57. cltObj=False)
  58. dirsFiles = self.clTempl.applyTemplates()
  59. if self.clTempl.getError():
  60. self.printERROR(self.clTempl.getError().strip())
  61. return False
  62. else:
  63. if self.verbose:
  64. self.displayTemplatesApplied(dirsFiles)
  65. return dirsFiles
  66. def initVars(self,datavars=None):
  67. """Primary variables initialization"""
  68. if not datavars:
  69. self.clVars = DataVarsDesktop()
  70. self.clVars.importDesktop()
  71. self.clVars.flIniFile()
  72. else:
  73. self.clVars = datavars
  74. def closeClTemplate(self):
  75. if self.clTempl:
  76. if self.clTempl.cltObj:
  77. self.clTempl.cltObj.closeFiles()
  78. self.clTempl.closeFiles()
  79. self.clTempl = None
  80. @safetyWrapper(native_errors=(TemplatesError,UpdateError),
  81. man_int=__("Update manually interrupted"),
  82. post_action=closeClTemplate,
  83. success_message=__("Update finished!"))
  84. def update(self, datavars=None):
  85. """
  86. Creating user profile and userdir
  87. """
  88. self.initVars(datavars)
  89. return True