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

Viewmanager.py: add check disk space #1212

Closed
wants to merge 4 commits into from
Closed

Viewmanager.py: add check disk space #1212

wants to merge 4 commits into from

Conversation

PushKK
Copy link
Contributor

@PushKK PushKK commented May 20, 2021

For https://gramps-project.org/bugs/view.php?id=12306
I add check disk space before Quit and BackUp.

Test this code please.

PushKK added 2 commits May 20, 2021 21:04
1. Old menu changed:
Database Processing > Family Tree Processing
Compare and Merge... > Merge...
2. Add string "The function ".
1. Capitalize all first letter "семейное древо" > "Семейное древо",
2. Old words from Tips.xml:
Database Processing  > Family Tree Processing
Compare and Merge... > Merge...
3. Change:
"Местоположение" > "Место"
"граф" > "график"
4. Other small fix.
@PushKK PushKK changed the title Viewmanager.py Viewmanager.py: add check disk space May 20, 2021
@tosky
Copy link
Contributor

tosky commented May 20, 2021

This looks like a duplicate of #1211 - wrong branch?

@codecov-commenter
Copy link

Codecov Report

Merging #1212 (24b6ae3) into master (9495d73) will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #1212   +/-   ##
=======================================
  Coverage   41.16%   41.16%           
=======================================
  Files        1062     1062           
  Lines      144695   144695           
=======================================
  Hits        59564    59564           
  Misses      85131    85131           

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 9495d73...24b6ae3. Read the comment docs.

@PushKK
Copy link
Contributor Author

PushKK commented May 21, 2021

Sorry, GitHub add all my previous PRs to last PR. Alltime.
For resolve this problem I delete my fork and create fork again...

Oh, GitHub not include .py files in this PR...

@Nick-Hall
Copy link
Member

@PushKK You probably just need to rebase your branches on master.

Copy link
Member

@Nick-Hall Nick-Hall left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea. It just needs a little refinement.

@@ -580,10 +580,47 @@ def no_del_event(self, *obj):
hits 'x' multiple times. """
return True

def checkdisk(self, dbfolder): # TODO check this function
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This belongs in gramps/gen/utils/file.py.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, in new PR this function move to file.py.

"""
Check disk space
"""
if win(): # for windows:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What should we do for Windows?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gramps work in Windows too. it's draft for Windows. I check this code in my Linux system, but I have not Windows.

if (self.checkdisk(config.get('database.path')) < diskspace):
self.uistate.push_message(self.dbstate, _("Disk space < " + str(diskspace) + " MB. Quit impossible. Clear your disk and repeat this operation."))
WarningDialog(
_("Message for user:"),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps "Low disk space" instead?

Copy link
Contributor Author

@PushKK PushKK May 21, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, of course.
For me - after this message I must run BleachBit and clear disk.
Gramps wait me and not freeze.

# - every backup (we need space 'last_backup_file_size'+ 5%)
diskspace = 20 # Disk space for Linux - 20 MB, for Gramps - 5 MB, for backup 'last_backup_file_size' + 5%
if (self.checkdisk(config.get('database.path')) < diskspace):
self.uistate.push_message(self.dbstate, _("Disk space < " + str(diskspace) + " MB. Quit impossible. Clear your disk and repeat this operation."))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use format strings instead of concatenation.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not Python man.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I rewrite this code. New PR have normal string concatenation.
I check code, all translated strings are present in .po file.

if os.path.isfile(os.path.join(path, bfile)) and bfile.startswith(backup_name) and bfile.endswith(backup_ext):
blastfile = bfile

bfile_size = round(os.path.getsize(os.path.join(path, blastfile))/(1024))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A utility function to return the largest backup size would be neater.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think about this - we must use biggest or last backup file.
In result - Gramps must use last backup file for active database.
Reason:
If user delete non used info from database -> new_database_size < old_database_size.
And Gramps create new_database_backup with small size.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. It just needs to be put into a utility function in gramps/gen/utils/file.py.

Copy link
Contributor Author

@PushKK PushKK May 23, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I test this code two day.
In result - backup_file_size must be calculated from active_database_size.
For SQLite3 - database with testdata have 71 MB, backup have 4,1 MB file (> 7%).
If user create new Family tree and import to tree data from other base - Gramps must say to user:

  1. You need least 'calculated backup_file_size' MB
    or (easy way on 'try - except')
  2. You cannot save your file. Clear your disk and try save again.

@Nick-Hall
Copy link
Member

Replaced by PR #1218.

1 similar comment
@Nick-Hall
Copy link
Member

Replaced by PR #1218.

@Nick-Hall Nick-Hall closed this Mar 12, 2022
@Nick-Hall Nick-Hall closed this Mar 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants