LicenseMake.py 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. """
  2. ***************************************************************************
  3. LicenseMake.py
  4. ---------------------
  5. Date : November 2012
  6. Copyright : (C) 2012 by Victor Olaya
  7. Email : volayaf at gmail dot com
  8. ***************************************************************************
  9. * *
  10. * This program is free software; you can redistribute it and/or modify *
  11. * it under the terms of the GNU General Public License as published by *
  12. * the Free Software Foundation; either version 2 of the License, or *
  13. * (at your option) any later version. *
  14. * *
  15. ***************************************************************************
  16. """
  17. __author__ = 'wanger'
  18. __date__ = 'November 2024'
  19. __copyright__ = '(C) 2012, siwei'
  20. import os
  21. from cryptography.fernet import Fernet
  22. from PyQt5.QtGui import QIcon
  23. from qgis._core import QgsCoordinateReferenceSystem, QgsProcessingParameterCrs, QgsProcessingParameterFileDestination
  24. from qgis.core import (QgsProcessing,
  25. QgsProcessingAlgorithm,
  26. QgsProcessingParameterDefinition,
  27. QgsProcessingParameterString,
  28. QgsProcessingParameterDateTime,
  29. QgsProcessingParameterFeatureSource,
  30. QgsProcessingParameterVectorDestination)
  31. from processing.algs.gdal.GdalAlgorithm import GdalAlgorithm
  32. from processing.algs.gdal.GdalUtils import GdalUtils
  33. pluginPath = os.path.split(os.path.split(os.path.dirname(__file__))[0])[0]
  34. class LicenseMake(GdalAlgorithm):
  35. HOST = 'LICENSEHOST'
  36. Date = 'LICENSEDATE'
  37. OUTPUT = 'OUTPUT'
  38. def __init__(self):
  39. super().__init__()
  40. def initAlgorithm(self, config=None):
  41. self.addParameter(QgsProcessingParameterString(self.HOST,
  42. self.tr('服务器机器名')))
  43. self.addParameter(
  44. QgsProcessingParameterDateTime(self.Date, '许可到期时间', type=QgsProcessingParameterDateTime.Type.Date))
  45. # 创建一个输出参数,指定为文本文件类型
  46. output_parameter = QgsProcessingParameterFileDestination(
  47. self.OUTPUT,
  48. self.tr('导出位置'),
  49. '.txt', defaultValue='license.txt')
  50. self.addParameter(output_parameter)
  51. def name(self):
  52. return 'licensemake'
  53. def displayName(self):
  54. return self.tr('生成许可文件')
  55. def group(self):
  56. return self.tr('软件许可')
  57. def groupId(self):
  58. return 'licensetools'
  59. def icon(self):
  60. return QIcon(os.path.join(pluginPath, 'images', 'dbms', 'certification.png'))
  61. def commandName(self):
  62. return 'ogr2ogr'
  63. def generateLicense(self, parameters):
  64. print("咱这块正在生成许可文件呢,别着急")
  65. outputpath = parameters.get("OUTPUT")
  66. custom_format = "yyyy-MM-dd"
  67. licensedate = parameters.get("LICENSEDATE").toString(custom_format)
  68. print(f"许可到期时间:{licensedate}")
  69. licensehost = parameters.get("LICENSEHOST")
  70. print(f"许可计算机机器名:{licensehost}")
  71. params = {
  72. "host": licensehost,
  73. "license": licensedate
  74. }
  75. # 生成一个密钥
  76. key = Fernet.generate_key()
  77. # 使用密钥创建一个Fernet对象
  78. cipher_suite = Fernet(key)
  79. # 需要加密的数据
  80. message = str(params).encode("utf-8")
  81. #
  82. # # 加密数据
  83. encrypted_message = cipher_suite.encrypt(message)
  84. print(f"加密的消息: {encrypted_message}")
  85. # 要写入的文本内容
  86. text_lines = [key.decode("utf-8"), encrypted_message.decode("utf-8")]
  87. # 打开文件进行写入
  88. with open(outputpath, 'w') as file:
  89. # 遍历文本行并写入文件
  90. for line in text_lines:
  91. file.write(line + "\n") # 添加换行符
  92. def getConsoleCommands(self, parameters, context, feedback, executing=True):
  93. print(parameters)
  94. arguments = [
  95. ]
  96. arguments = [
  97. ]
  98. return [self.commandName(), GdalUtils.escapeAndJoin(arguments)]