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.

79 lines
2.9 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 sys
  16. from cl_print import color_print
  17. from cl_utils import _error
  18. # Перевод сообщений для программы
  19. from cl_lang import lang
  20. lang().setLanguage(sys.modules[__name__])
  21. class share_cmd(color_print, _error):
  22. """Класс общих методов обработки опций командной строки"""
  23. def printVars(self, optObj):
  24. """Печать переменных"""
  25. if optObj.v:
  26. varsFilter = None
  27. varsNames = []
  28. format = "default"
  29. # Фильтрование переменных
  30. if optObj.filter:
  31. optCmd = optObj.filter
  32. if ',' in optCmd:
  33. varsNames = optCmd.split(",")
  34. elif '*' in optCmd:
  35. varsFilter = optCmd.replace("*", ".*")
  36. else:
  37. varsNames.append(optCmd)
  38. if optObj.xml:
  39. format = "xml"
  40. self.logicObj.printVars(varsFilter, varsNames, outFormat=format)
  41. def setVars(self, optObj):
  42. """Установка переменных"""
  43. if optObj.set:
  44. for vals in optObj.set:
  45. for val in vals.split(','):
  46. k,o,v = val.partition('=')
  47. if self.logicObj.clVars.exists(k):
  48. if not self.logicObj.clVars.SetWriteVar(k,v):
  49. return False
  50. else:
  51. self.printERROR(_('variable %s not found')%k)
  52. return False
  53. return True
  54. def writeVars(self, optObj):
  55. """Запись переменных"""
  56. if optObj.set:
  57. if not self.logicObj.clVars.WriteVars():
  58. errMsg = self.getError()
  59. if errMsg:
  60. self.printERROR(errMsg.strip())
  61. self.printERROR(_('Can not write template variables'))
  62. return False
  63. return True
  64. def setPrintNoColor(self, optObj):
  65. """Установка печати сообщений без цвета"""
  66. if optObj.color and optObj.color=="never":
  67. color_print.colorPrint = lambda *arg : sys.stdout.write(arg[-1]) or\
  68. sys.stdout.flush()