fix: 账号备份密码如 t08\x08fIE 备份失败

pull/12447/head
feng 2023-12-28 16:26:49 +08:00 committed by Bryan
parent 6c1c8b241e
commit 219fad9b62
4 changed files with 29 additions and 10 deletions

View File

@ -3,13 +3,13 @@ import time
from collections import defaultdict, OrderedDict from collections import defaultdict, OrderedDict
from django.conf import settings from django.conf import settings
from openpyxl import Workbook
from rest_framework import serializers from rest_framework import serializers
from xlsxwriter import Workbook
from accounts.const.automation import AccountBackupType from accounts.const.automation import AccountBackupType
from accounts.models.automations.backup_account import AccountBackupAutomation
from accounts.notifications import AccountBackupExecutionTaskMsg, AccountBackupByObjStorageExecutionTaskMsg from accounts.notifications import AccountBackupExecutionTaskMsg, AccountBackupByObjStorageExecutionTaskMsg
from accounts.serializers import AccountSecretSerializer from accounts.serializers import AccountSecretSerializer
from accounts.models.automations.backup_account import AccountBackupAutomation
from assets.const import AllTypes from assets.const import AllTypes
from common.utils.file import encrypt_and_compress_zip_file, zip_files from common.utils.file import encrypt_and_compress_zip_file, zip_files
from common.utils.timezone import local_now_filename, local_now_display from common.utils.timezone import local_now_filename, local_now_display
@ -144,10 +144,11 @@ class AccountBackupHandler:
wb = Workbook(filename) wb = Workbook(filename)
for sheet, data in data_map.items(): for sheet, data in data_map.items():
ws = wb.create_sheet(str(sheet)) ws = wb.add_worksheet(str(sheet))
for row in data: for row in data:
ws.append(row) for col, _data in enumerate(row):
wb.save(filename) ws.write_string(0, col, _data)
wb.close()
files.append(filename) files.append(filename)
timedelta = round((time.time() - time_start), 2) timedelta = round((time.time() - time_start), 2)
print('创建备份文件完成: 用时 {}s'.format(timedelta)) print('创建备份文件完成: 用时 {}s'.format(timedelta))

View File

@ -4,7 +4,7 @@ from copy import deepcopy
from django.conf import settings from django.conf import settings
from django.utils import timezone from django.utils import timezone
from openpyxl import Workbook from xlsxwriter import Workbook
from accounts.const import AutomationTypes, SecretType, SSHKeyStrategy, SecretStrategy from accounts.const import AutomationTypes, SecretType, SSHKeyStrategy, SecretStrategy
from accounts.models import ChangeSecretRecord from accounts.models import ChangeSecretRecord
@ -227,8 +227,9 @@ class ChangeSecretManager(AccountBasePlaybookManager):
rows.insert(0, header) rows.insert(0, header)
wb = Workbook(filename) wb = Workbook(filename)
ws = wb.create_sheet('Sheet1') ws = wb.add_worksheet('Sheet1')
for row in rows: for row in rows:
ws.append(row) for col, data in enumerate(row):
wb.save(filename) ws.write_string(0, col, data)
wb.close()
return True return True

18
poetry.lock generated
View File

@ -7540,6 +7540,22 @@ type = "legacy"
url = "https://pypi.tuna.tsinghua.edu.cn/simple" url = "https://pypi.tuna.tsinghua.edu.cn/simple"
reference = "tsinghua" reference = "tsinghua"
[[package]]
name = "xlsxwriter"
version = "3.1.9"
description = "A Python module for creating Excel XLSX files."
optional = false
python-versions = ">=3.6"
files = [
{file = "XlsxWriter-3.1.9-py3-none-any.whl", hash = "sha256:b61c1a0c786f82644936c0936ec96ee96cd3afb9440094232f7faef9b38689f0"},
{file = "XlsxWriter-3.1.9.tar.gz", hash = "sha256:de810bf328c6a4550f4ffd6b0b34972aeb7ffcf40f3d285a0413734f9b63a929"},
]
[package.source]
type = "legacy"
url = "https://pypi.tuna.tsinghua.edu.cn/simple"
reference = "tsinghua"
[[package]] [[package]]
name = "xmlsec" name = "xmlsec"
version = "1.3.13" version = "1.3.13"
@ -7755,4 +7771,4 @@ reference = "tsinghua"
[metadata] [metadata]
lock-version = "2.0" lock-version = "2.0"
python-versions = "^3.11" python-versions = "^3.11"
content-hash = "397cb294c81da3ce74f1a1c3044bd778669284c0c280177162ed9d51e623a7c8" content-hash = "19950a5300f8a4425e3e3c9a096fc3782cb544e02152e92ac1bc09d1d9b5274a"

View File

@ -145,6 +145,7 @@ user-agents = "^2.2.0"
django-cors-headers = "^4.3.0" django-cors-headers = "^4.3.0"
mistune = "0.8.4" mistune = "0.8.4"
openai = "^1.3.7" openai = "^1.3.7"
xlsxwriter = "^3.1.9"
[tool.poetry.group.xpack.dependencies] [tool.poetry.group.xpack.dependencies]