-
Notifications
You must be signed in to change notification settings - Fork 204
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
Check if Include folders/files do exists (in case they are removed) #1718
base: dev
Are you sure you want to change the base?
Changes from 17 commits
f6bf5bc
d4556ca
5f3a8c7
e07d5a1
ce4d761
27fe2da
27ac817
4f36503
9cb8348
7472f54
287d129
5161ccd
45aa011
c2941ba
6668487
205ee49
03c1050
bb5969c
5416356
42b5e06
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -698,6 +698,15 @@ def remove(self, sid): | |
|
||
return True | ||
|
||
def _warning_on_take_snapshot(self, config): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This function name ( I suggest to rename the function to eg. |
||
missing = has_missing(config.include()) | ||
|
||
if missing: | ||
msg = ', '.join(missing) | ||
msg = f'The following folders are missing: {msg}' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think "includes" could be folders but also files so I would add "... following **files/**folders are missing..." to the message |
||
logger.warning(msg) | ||
self.setTakeSnapshotMessage(1, msg) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "1" means "error" ("0" would be "info"), but we do not yet have a value for "warnings". There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure. I think I used 1 in order to show properly in the Systray (but now systray is not working fine for me anymore :/) But sure. Let me know if you want me to change :) |
||
|
||
# TODO Refactor: This functions is extremely difficult to understand: | ||
# - Nested "if"s | ||
# - Fuzzy names of classes, attributes and methods | ||
|
@@ -806,6 +815,7 @@ def backup(self, force=False): | |
else: | ||
self.config.setCurrentHashId(hash_id) | ||
|
||
self._warning_on_take_snapshot(self.config) | ||
include_folders = self.config.include() | ||
|
||
if not include_folders: | ||
|
@@ -3087,6 +3097,25 @@ def lastSnapshot(cfg): | |
return sids[0] | ||
|
||
|
||
def has_missing(included): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would add what is missing to make the purpose of the function clear: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So I suggest to rename the function to |
||
""" | ||
Check if there are missing files or folders in a snapshot. | ||
Args: | ||
included (list): list of tuples (item, info) | ||
Returns: | ||
tuple: (bool, str) where bool is ``True`` if there are | ||
missing files or folders and str is a message | ||
describing the missing files or folders | ||
""" | ||
not_found = [] | ||
for path, info in included: | ||
if not os.path.exists(path): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am not sure if There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure. I just did it and it worked fine :) I tested via CLI:
I tested w/ CLI, and got correct results w/ this warning:
And also via GUI with real snapshots (w/ existent folder, removed folder, existent file and removed file). |
||
not_found.append(path) | ||
return not_found | ||
|
||
|
||
if __name__ == '__main__': | ||
config = config.Config() | ||
snapshots = Snapshots(config) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1211,12 +1211,27 @@ def updateTimeLine(self, refreshSnapshotsList=True): | |
item = self.timeLine.addSnapshot(sid) | ||
self.timeLine.checkSelection() | ||
|
||
def validate_on_take_snapshot(self): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. excellent function name 👍 !!! |
||
missing = snapshots.has_missing(self.config.include()) | ||
if missing: | ||
msg_missing = '\n'.join(missing) | ||
msg = _('The following folders are missing: {folders} Do you want to proceed?'.format( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The If you'd find a simple way to de-duplicate the code it would be great but if it is too complicated I could live with the existing code here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. About this, a similar code was made with the Only the text generation is different (also not translated the CLI version) and how we warn the user. Ok? |
||
folders=f'\n{msg_missing}\n\n')) | ||
answer = messagebox.warningYesNo(self, msg) | ||
buhtz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return answer == QMessageBox.StandardButton.Yes | ||
return True | ||
|
||
def btnTakeSnapshotClicked(self): | ||
backintime.takeSnapshotAsync(self.config) | ||
self.updateTakeSnapshot(True) | ||
self._take_snapshot_clicked(checksum=False) | ||
|
||
def btnTakeSnapshotChecksumClicked(self): | ||
backintime.takeSnapshotAsync(self.config, checksum = True) | ||
self._take_snapshot_clicked(checksum=True) | ||
|
||
def _take_snapshot_clicked(self, checksum): | ||
if not self.validate_on_take_snapshot(): | ||
return | ||
|
||
backintime.takeSnapshotAsync(self.config, checksum=checksum) | ||
self.updateTakeSnapshot(True) | ||
|
||
def btnStopTakeSnapshotClicked(self): | ||
|
@@ -1957,6 +1972,7 @@ def eventFilter(self, receiver, event): | |
return super(ExtraMouseButtonEventFilter, self) \ | ||
.eventFilter(receiver, event) | ||
|
||
|
||
class RemoveSnapshotThread(QThread): | ||
""" | ||
remove snapshots in background thread so GUI will not freeze | ||
|
@@ -1992,6 +2008,7 @@ def run(self): | |
if self.config.inhibitCookie: | ||
self.config.inhibitCookie = tools.unInhibitSuspend(*self.config.inhibitCookie) | ||
|
||
|
||
class FillTimeLineThread(QThread): | ||
""" | ||
add snapshot IDs to timeline in background | ||
|
@@ -2009,6 +2026,7 @@ def run(self): | |
|
||
self.parent.snapshotsList.sort() | ||
|
||
|
||
class SetupCron(QThread): | ||
""" | ||
Check crontab entries on startup. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be great to add a comment header to describe the purpose and arguments of the function