Skip to content
This repository was archived by the owner on May 23, 2020. It is now read-only.

Commit df03b35

Browse files
committed
added backup file size info
1 parent 1f6f021 commit df03b35

File tree

1 file changed

+39
-14
lines changed

1 file changed

+39
-14
lines changed

blog/management/commands/autobackup.py

Lines changed: 39 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -57,30 +57,55 @@ def backupMixin(resources_set, fname):
5757
with open(filepath, 'w') as outfile:
5858
json.dump(resources_set.json, outfile)
5959

60-
flastbackup = directory_backup + \
61-
'/last_backup_date_{}'.format(time.strftime("%d-%m-%Y"))
62-
with open(flastbackup, 'w') as f:
63-
f.write('Just for date info!')
64-
f.close()
60+
# returning file size to 'kB' version.
61+
return int(os.path.getsize(filepath)) / 1000
6562

6663
authorset = AuthorResource().export()
67-
backupMixin(authorset, 'author')
64+
fsizeAuthor = backupMixin(authorset, 'author')
6865

6966
tagset = TagResource().export()
70-
backupMixin(tagset, 'tag')
67+
fsizeTag = backupMixin(tagset, 'tag')
7168

7269
postset = PostResource().export()
73-
backupMixin(postset, 'post')
70+
fsizePost = backupMixin(postset, 'post')
7471

7572
galleryset = GalleryResource().export()
76-
backupMixin(galleryset, 'gallery')
73+
fsizeGallery = backupMixin(galleryset, 'gallery')
7774

7875
visitorset = VisitorResource().export()
79-
backupMixin(visitorset, 'visitor')
76+
fsizeVisitor = backupMixin(visitorset, 'visitor')
8077

8178
pageset = PageResource().export()
82-
backupMixin(pageset, 'page')
83-
84-
self.stdout.write(self.style.SUCCESS('[+] Successfully backup blog!'))
79+
fsizePage = backupMixin(pageset, 'page')
80+
81+
def backupInfo():
82+
return ''\
83+
'-------------------------------\n' \
84+
'| Last backup date: {0}\n' \
85+
'-------------------------------\n' \
86+
'| Author : {1} kB\n' \
87+
'| Tag : {2} kB\n' \
88+
'| Post : {3} kB\n' \
89+
'| Gallery : {4} kB\n' \
90+
'| Visitor : {5} kB\n' \
91+
'| Page : {6} kB\n' \
92+
'-------------------------------'.format(
93+
time.strftime("%d-%m-%Y"),
94+
fsizeAuthor, fsizeTag, fsizePost,
95+
fsizeGallery, fsizeGallery, fsizePage
96+
)
97+
98+
finfo = directory_backup + '/backupinfo.txt'
99+
with open(finfo, 'w') as f:
100+
f.write(backupInfo())
101+
f.close()
102+
103+
self.stdout.write(
104+
self.style.SUCCESS(
105+
backupInfo()
106+
)
107+
)
85108
else:
86-
self.stdout.write(self.style.WARNING('[-] Can not backup blog!'))
109+
self.stdout.write(
110+
self.style.WARNING('[-] Can not backup blog!')
111+
)

0 commit comments

Comments
 (0)