mirror of
https://github.com/borgbase/vorta
synced 2025-01-03 05:36:19 +00:00
Fix parsing "changed link" lines (#510)
* Fix parsing "changed link" lines * Move borg diff parser test to test_archives.py
This commit is contained in:
parent
936d3c10d0
commit
c16a7509bd
2 changed files with 69 additions and 52 deletions
|
@ -19,6 +19,25 @@ def __init__(self, fs_data, archive_newer, archive_older):
|
|||
super().__init__()
|
||||
self.setupUi(self)
|
||||
|
||||
files_with_attributes, nested_file_list = parse_diff_lines(fs_data.split('\n'))
|
||||
model = DiffTree(files_with_attributes, nested_file_list)
|
||||
|
||||
view = self.treeView
|
||||
view.setAlternatingRowColors(True)
|
||||
view.setUniformRowHeights(True) # Allows for scrolling optimizations.
|
||||
view.setModel(model)
|
||||
header = view.header()
|
||||
header.setStretchLastSection(False)
|
||||
header.setSectionResizeMode(1, QHeaderView.ResizeToContents)
|
||||
header.setSectionResizeMode(2, QHeaderView.ResizeToContents)
|
||||
header.setSectionResizeMode(0, QHeaderView.Stretch)
|
||||
|
||||
self.archiveNameLabel_1.setText(f'{archive_newer.name}')
|
||||
self.archiveNameLabel_2.setText(f'{archive_older.name}')
|
||||
self.okButton.clicked.connect(self.accept)
|
||||
|
||||
|
||||
def parse_diff_lines(diff_lines):
|
||||
files_with_attributes = []
|
||||
nested_file_list = nested_dict()
|
||||
|
||||
|
@ -28,7 +47,7 @@ def parse_line(line):
|
|||
else:
|
||||
return 0, "", "", ""
|
||||
|
||||
if line_split[0] == 'added' or line_split[0] == 'removed':
|
||||
if line_split[0] in {'added', 'removed', 'changed'}:
|
||||
change_type = line_split[0]
|
||||
if line_split[1] in ['directory', 'link']:
|
||||
size = 0
|
||||
|
@ -68,24 +87,10 @@ def parse_line(line):
|
|||
|
||||
return size, change_type, name, dir
|
||||
|
||||
for line in fs_data.split('\n'):
|
||||
for line in diff_lines:
|
||||
files_with_attributes.append(parse_line(line))
|
||||
|
||||
model = DiffTree(files_with_attributes, nested_file_list)
|
||||
|
||||
view = self.treeView
|
||||
view.setAlternatingRowColors(True)
|
||||
view.setUniformRowHeights(True) # Allows for scrolling optimizations.
|
||||
view.setModel(model)
|
||||
header = view.header()
|
||||
header.setStretchLastSection(False)
|
||||
header.setSectionResizeMode(1, QHeaderView.ResizeToContents)
|
||||
header.setSectionResizeMode(2, QHeaderView.ResizeToContents)
|
||||
header.setSectionResizeMode(0, QHeaderView.Stretch)
|
||||
|
||||
self.archiveNameLabel_1.setText(f'{archive_newer.name}')
|
||||
self.archiveNameLabel_2.setText(f'{archive_older.name}')
|
||||
self.okButton.clicked.connect(self.accept)
|
||||
return (files_with_attributes, nested_file_list)
|
||||
|
||||
|
||||
def calc_size(significand, unit):
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import psutil
|
||||
from collections import namedtuple
|
||||
import pytest
|
||||
from PyQt5 import QtCore
|
||||
from vorta.models import BackupProfileModel, ArchiveModel
|
||||
import vorta.borg
|
||||
|
@ -165,3 +166,14 @@ def test_archive_diff(qapp, qtbot, mocker, borg_json_output, monkeypatch):
|
|||
|
||||
assert tab._resultwindow.archiveNameLabel_1.text() == 'test-archive'
|
||||
tab._resultwindow.accept()
|
||||
|
||||
|
||||
@pytest.mark.parametrize('line, expected', [
|
||||
('changed link some/changed/link',
|
||||
(0, 'changed', 'link', 'some/changed')),
|
||||
(' +77.8 kB -77.8 kB some/changed/file',
|
||||
(77800, 'modified', 'file', 'some/changed')),
|
||||
])
|
||||
def test_archive_diff_parser(line, expected):
|
||||
files_with_attributes, nested_file_list = vorta.views.diff_result.parse_diff_lines([line])
|
||||
assert files_with_attributes == [expected]
|
||||
|
|
Loading…
Reference in a new issue