Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve source management Control #617

Merged
merged 78 commits into from Oct 30, 2020
Merged
Show file tree
Hide file tree
Changes from 71 commits
Commits
Show all changes
78 commits
Select commit Hold shift + click to select a range
1b072fc
add function to get path info async
XXXBold Sep 5, 2020
13fd1a2
change sourcelist to QTableWidget
XXXBold Sep 5, 2020
9ec1b20
update for new source control
XXXBold Sep 5, 2020
7682780
Update source_tab.py
XXXBold Sep 5, 2020
814e48d
Merge branch 'master' into improve-src-mgmt
XXXBold Sep 6, 2020
1bc94f6
Merge branch 'master' into improve-src-mgmt
XXXBold Sep 6, 2020
dc5001e
add more attributes for paths in source list
XXXBold Sep 6, 2020
6974a8c
add missing code for DB update
XXXBold Sep 6, 2020
9e5e626
updated source entry data
XXXBold Sep 7, 2020
1e28b91
updated function for getting a folders size
XXXBold Sep 7, 2020
fef831f
Improved add/remove functionality
XXXBold Sep 7, 2020
06327d0
Merge branch 'master' into improve-src-mgmt
XXXBold Sep 7, 2020
48dd903
Merge branch 'master' into improve-src-mgmt
XXXBold Sep 10, 2020
c4a9a6d
update properties
XXXBold Sep 10, 2020
8d5923b
Add new option in misc ui
XXXBold Sep 10, 2020
acf444e
Check if new added source's size should be updated
XXXBold Sep 10, 2020
8a81097
variable name cleanup
XXXBold Sep 10, 2020
a04ed9b
Merge branch 'master' into improve-src-mgmt
XXXBold Sep 13, 2020
7857e31
Merge branch 'master' into improve-src-mgmt
XXXBold Sep 26, 2020
34f23c9
Add "Update sources" button
XXXBold Sep 26, 2020
00d91f7
remove debug stuff
XXXBold Sep 26, 2020
ae6eba8
Add stuff to update source infos
XXXBold Sep 26, 2020
e54bd42
Update src/vorta/assets/UI/sourcetab.ui
XXXBold Sep 27, 2020
65916b1
Update src/vorta/views/source_tab.py
XXXBold Sep 27, 2020
384c2c7
Update src/vorta/views/source_tab.py
XXXBold Sep 27, 2020
7516a74
Update src/vorta/assets/UI/sourcetab.ui
XXXBold Sep 27, 2020
b64a486
run lint
XXXBold Sep 27, 2020
f67203e
run lint
XXXBold Sep 27, 2020
7aaceb1
Merge branch 'master' into improve-src-mgmt
XXXBold Sep 27, 2020
b84f7a9
re-add network status monitor
XXXBold Sep 29, 2020
567cbbe
Add spacer
XXXBold Sep 29, 2020
1e7b2a0
re-add network status monitor
XXXBold Sep 29, 2020
04ec022
remove keyring stuff
XXXBold Sep 29, 2020
4023708
fixes some previous bugs
XXXBold Sep 29, 2020
55a1257
Fixed some bugs
XXXBold Sep 29, 2020
b71c156
Lint, use QTableWidget
samuel-w Oct 1, 2020
dec0ae9
Fix tests
samuel-w Oct 1, 2020
cf4d35e
applied patch
XXXBold Oct 3, 2020
2db7347
applied patch
XXXBold Oct 3, 2020
a22455c
applied patch
XXXBold Oct 3, 2020
4078038
Merge branch 'master' into improve-src-mgmt
XXXBold Oct 3, 2020
6f6de67
Changed as requested
XXXBold Oct 3, 2020
789ea66
Merge branch 'improve-src-mgmt' of github:XXXBold/vorta into improve-…
samuel-w Oct 3, 2020
4464318
Remove extra file
samuel-w Oct 3, 2020
62477dd
Merge pull request #1 from samuel-w/improve-src-mgmt
XXXBold Oct 4, 2020
99c7d8c
Undelete version
samuel-w Oct 4, 2020
5f8c421
enabled sorting via sort indicator
XXXBold Oct 7, 2020
ffebd8a
Merge pull request #2 from samuel-w/improve-src-mgmt
XXXBold Oct 7, 2020
cc0cd26
some cleanups
XXXBold Oct 8, 2020
2a3031b
Sort by file size
samuel-w Oct 8, 2020
dbaab67
Fix
samuel-w Oct 9, 2020
090b04f
Merge pull request #3 from samuel-w/improve-src-mgmt
XXXBold Oct 10, 2020
a0ca737
Fixed sorting
XXXBold Oct 10, 2020
d323eb1
Changed command to get foldersize
XXXBold Oct 10, 2020
84d3d76
GetFolderSize: Add different cmd for MacOS
XXXBold Oct 11, 2020
955c45d
fix lint
XXXBold Oct 11, 2020
53c916c
fix lint2
XXXBold Oct 11, 2020
2fa600e
Change for Mac OS
XXXBold Oct 12, 2020
78e5f19
Syntax corrected
XXXBold Oct 12, 2020
9776708
typo
XXXBold Oct 12, 2020
4f6bbff
Changed get_directory_size
XXXBold Oct 13, 2020
79f7c41
fix lint
XXXBold Oct 13, 2020
0e46143
Update src/vorta/views/source_tab.py
XXXBold Oct 14, 2020
2fd8539
Update src/vorta/views/source_tab.py
XXXBold Oct 14, 2020
3cda2ed
Update src/vorta/views/source_tab.py
XXXBold Oct 14, 2020
2dad3fb
Update src/vorta/views/source_tab.py
XXXBold Oct 14, 2020
629faeb
Update src/vorta/assets/UI/sourcetab.ui
XXXBold Oct 14, 2020
6d9e847
Update src/vorta/views/source_tab.py
XXXBold Oct 14, 2020
b0d0020
Use python method to get folder size
XXXBold Oct 14, 2020
8ed9ad9
lint
XXXBold Oct 14, 2020
837f132
Merge branch 'master' into improve-src-mgmt
m3nu Oct 17, 2020
1c88285
Update src/vorta/models.py
XXXBold Oct 20, 2020
87d357a
Update src/vorta/utils.py
XXXBold Oct 20, 2020
1704e77
Update src/vorta/utils.py
XXXBold Oct 20, 2020
1f59399
Update src/vorta/utils.py
XXXBold Oct 21, 2020
1753170
Update src/vorta/utils.py
XXXBold Oct 26, 2020
790d938
Update src/vorta/utils.py
XXXBold Oct 26, 2020
3a3fa6e
Merge branch 'master' into improve-src-mgmt
m3nu Oct 30, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
73 changes: 67 additions & 6 deletions src/vorta/assets/UI/sourcetab.ui
Expand Up @@ -24,7 +24,10 @@
<item>
<layout class="QHBoxLayout" name="horizontalLayout" stretch="0,0">
<item>
<widget class="QListWidget" name="sourceFilesWidget">
<widget class="QTableWidget" name="sourceFilesWidget">
<property name="enabled">
<bool>true</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
Expand All @@ -37,12 +40,50 @@
<height>0</height>
</size>
</property>
<property name="editTriggers">
<set>QAbstractItemView::NoEditTriggers</set>
</property>
<property name="selectionMode">
<enum>QAbstractItemView::ExtendedSelection</enum>
</property>
<property name="sortingEnabled">
<bool>true</bool>
<property name="selectionBehavior">
<enum>QAbstractItemView::SelectRows</enum>
</property>
<property name="showGrid">
<bool>false</bool>
</property>
<attribute name="horizontalHeaderVisible">
<bool>false</bool>
</attribute>
<attribute name="horizontalHeaderHighlightSections">
<bool>false</bool>
</attribute>
<attribute name="verticalHeaderVisible">
<bool>false</bool>
</attribute>
<attribute name="verticalHeaderHighlightSections">
<bool>false</bool>
</attribute>
<column>
<property name="text">
<string>Path</string>
</property>
</column>
<column>
<property name="text">
<string>Type</string>
</property>
</column>
<column>
<property name="text">
<string>Size</string>
</property>
</column>
<column>
<property name="text">
<string>File Count</string>
</property>
</column>
</widget>
</item>
<item>
Expand All @@ -61,6 +102,13 @@
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="sourceRemove">
<property name="text">
<string>Remove</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="paste">
<property name="toolTip">
Expand All @@ -71,13 +119,26 @@
</property>
</widget>
</item>
<item alignment="Qt::AlignTop">
<widget class="QPushButton" name="sourceRemove">
<item>
XXXBold marked this conversation as resolved.
Show resolved Hide resolved
<widget class="QPushButton" name="sourcesUpdate">
<property name="text">
<string>Remove</string>
<string>Recalculate sizes</string>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
Expand Down
21 changes: 20 additions & 1 deletion src/vorta/models.py
Expand Up @@ -16,7 +16,7 @@
from vorta.i18n import trans_late
from vorta.utils import slugify

SCHEMA_VERSION = 15
SCHEMA_VERSION = 16

db = pw.Proxy()

Expand Down Expand Up @@ -106,6 +106,9 @@ class Meta:
class SourceFileModel(pw.Model):
"""A folder to be backed up, related to a Backup Configuration."""
dir = pw.CharField()
XXXBold marked this conversation as resolved.
Show resolved Hide resolved
dir_size = pw.BigIntegerField()
dir_files_count = pw.BigIntegerField()
path_isdir = pw.BooleanField()
profile = pw.ForeignKeyField(BackupProfileModel, default=1)
added_at = pw.DateTimeField(default=datetime.utcnow)

Expand Down Expand Up @@ -215,6 +218,11 @@ def get_misc_settings():
'label': trans_late('settings',
'Open main window on startup')
},
{
'key': 'get_srcpath_datasize', 'value': True, 'type': 'checkbox',
'label': trans_late('settings',
'Get size of file/folder when added')
XXXBold marked this conversation as resolved.
Show resolved Hide resolved
},
{
'key': 'previous_profile_id', 'str_value': '1', 'type': 'internal',
'label': 'Previously selected profile'
Expand Down Expand Up @@ -362,6 +370,17 @@ def init_db(con=None):
'dont_run_on_metered_networks', pw.BooleanField(default=True))
)

if current_schema.version < 16:
_apply_schema_update(
current_schema, 16,
migrator.add_column(SourceFileModel._meta.table_name,
'dir_size', pw.BigIntegerField(default=-1)),
migrator.add_column(SourceFileModel._meta.table_name,
'dir_files_count', pw.BigIntegerField(default=-1)),
migrator.add_column(SourceFileModel._meta.table_name,
'path_isdir', pw.BooleanField(default=False))
)

# Create missing settings and update labels. Leave setting values untouched.
for setting in get_misc_settings():
s, created = SettingsModel.get_or_create(key=setting['key'], defaults=setting)
Expand Down
80 changes: 77 additions & 3 deletions src/vorta/utils.py
Expand Up @@ -17,7 +17,9 @@
from paramiko.ed25519key import Ed25519Key
from paramiko.rsakey import RSAKey
from PyQt5 import QtCore
from PyQt5.QtCore import QFileInfo, QThread, pyqtSignal
from PyQt5.QtWidgets import QApplication, QFileDialog, QSystemTrayIcon
from decimal import Decimal
XXXBold marked this conversation as resolved.
Show resolved Hide resolved

from vorta.borg._compatibility import BorgCompatibility
from vorta.log import logger
Expand All @@ -26,10 +28,52 @@
QApplication.setAttribute(QtCore.Qt.AA_EnableHighDpiScaling, True) # enable highdpi scaling
QApplication.setAttribute(QtCore.Qt.AA_UseHighDpiPixmaps, True) # use highdpi icons

network_status_monitor = NetworkStatusMonitor.get_network_status_monitor()
XXXBold marked this conversation as resolved.
Show resolved Hide resolved
logger.info('Using %s NetworkStatusMonitor implementation.', network_status_monitor.__class__.__name__)

XXXBold marked this conversation as resolved.
Show resolved Hide resolved
borg_compat = BorgCompatibility()
_network_status_monitor = None


_network_status_monitor = None
class FilePathInfoAsync(QThread):
signal = pyqtSignal(str, str, str)

def __init__(self, path):
self.path = path
QThread.__init__(self)
self.exiting = False

def run(self):
# logger.info("running thread to get path=%s...", self.path)
self.files_count = 0
self.size, self.files_count = get_path_datasize(self.path)
self.signal.emit(self.path, str(self.size), str(self.files_count))


def get_directory_size(dir_path):
''' Get number of files only and total size in bytes from a path.
Based off https://stackoverflow.com/a/17936789 '''
data_size = 0
seen = set()

for curr_path, _, file_names in os.walk(dir_path):
for file_name in file_names:
file_path = os.path.join(curr_path, file_name)

# Ignore symbolic links, since borg doesn't follow them
if os.path.islink(file_path):
continue

stat = os.stat(file_path)

# Visit each file once
if stat.st_ino not in seen:
seen.add(stat.st_ino)
data_size += stat.st_size

files_count = len(seen)

return data_size, files_count


def get_network_status_monitor():
Expand All @@ -40,6 +84,22 @@ def get_network_status_monitor():
return _network_status_monitor


def get_path_datasize(path):
file_info = QFileInfo(path)
data_size = 0

if file_info.isDir():
data_size, files_count = get_directory_size(file_info.absoluteFilePath())
# logger.info("path (folder) %s %u elements size now=%u (%s)",
# file_info.absoluteFilePath(), files_count, data_size, pretty_bytes(data_size))
else:
# logger.info("path (file) %s size=%u", file_info.path(), file_info.size())
data_size = file_info.size()
files_count = 1

return data_size, files_count


def nested_dict():
"""
Combination of two idioms to quickly build dicts from lists of keys:
Expand Down Expand Up @@ -98,10 +158,24 @@ def get_private_keys():
return available_private_keys


def sort_sizes(size_list):
""" Sorts sizes with extensions. Assumes that size is already in largest unit possible """
final_list = []
for suffix in [" B", " KB", " MB", " GB", " TB"]:
sub_list = [Decimal(size[:-len(suffix)])
XXXBold marked this conversation as resolved.
Show resolved Hide resolved
for size in size_list if size.endswith(suffix) and size[:-len(suffix)][-1].isnumeric()]
sub_list.sort()
final_list += [(str(size) + suffix) for size in sub_list]
# Skip additional loops
if len(final_list) == len(size_list):
break
return final_list


def pretty_bytes(size):
"""from https://stackoverflow.com/questions/12523586/
python-format-size-application-converting-b-to-kb-mb-gb-tb/37423778"""
if type(size) != int:
if not isinstance(size, int):
return ''
power = 1000 # GiB is base 2**10, GB is base 10**3.
n = 0
Expand Down Expand Up @@ -132,7 +206,7 @@ def get_sorted_wifis(profile):

from vorta.models import WifiSettingModel

system_wifis = get_network_status_monitor().get_known_wifis()
system_wifis = network_status_monitor.get_known_wifis()
XXXBold marked this conversation as resolved.
Show resolved Hide resolved
if system_wifis is None:
# Don't show any networks if we can't get the current list
return []
Expand Down