This repository has been archived by the owner on Sep 22, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmakeScreenshots.py
executable file
·300 lines (234 loc) · 9.91 KB
/
makeScreenshots.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
#!/usr/bin/env python3
# Copyright (C) 2016 Germar Reitze
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
import sys
import os
import subprocess
from PyQt5.QtCore import QTimer
from PyQt5.QtWidgets import QDialog
from tempfile import TemporaryDirectory
from datetime import date, time, datetime, timedelta
os.environ['LANGUAGE'] = 'en_US.UTF-8'
sys.path.insert(0, '../backintime/common')
sys.path.insert(0, '../backintime/qt')
import app
import settingsdialog
import qttools
import config
import snapshots
from guiapplicationinstance import GUIApplicationInstance
from snapshotsdialog import SnapshotsDialog
from logviewdialog import LogViewDialog
def setScreenshotTimer(widget, filename, width = 720, hight = 480):
widget.move(100, 50)
if width and hight:
widget.resize(width, hight)
widget.show()
scrTimer = QTimer(widget)
scrTimer.setInterval(1000)
scrTimer.setSingleShot(True)
scrTimer.timeout.connect(lambda: takeScreenshot(filename))
quitTimer = QTimer(widget)
quitTimer.setInterval(1500)
quitTimer.setSingleShot(True)
quitTimer.timeout.connect(widget.close)
scrTimer.start()
quitTimer.start()
qapp.exec_()
def setScreenshotTimerDlg(mainWindow, dlgFunct, filename):
def close():
for child in mainWindow.children():
if isinstance(child, QDialog):
child.close()
mainWindow.hide()
def moveDlg():
for child in mainWindow.children():
if isinstance(child, QDialog):
child.move(100, 50)
dlgTimer = QTimer(mainWindow)
dlgTimer.setInterval(10)
dlgTimer.setSingleShot(True)
dlgTimer.timeout.connect(dlgFunct)
dlgMoveTimer = QTimer(mainWindow)
dlgMoveTimer.setInterval(100)
dlgMoveTimer.setSingleShot(True)
dlgMoveTimer.timeout.connect(moveDlg)
scrTimer = QTimer(mainWindow)
scrTimer.setInterval(2000)
scrTimer.setSingleShot(True)
scrTimer.timeout.connect(lambda: takeScreenshot(filename))
quitTimer = QTimer(mainWindow)
quitTimer.setInterval(2500)
quitTimer.setSingleShot(True)
quitTimer.timeout.connect(close)
scrTimer.start()
quitTimer.start()
dlgTimer.start()
dlgMoveTimer.start()
qapp.exec_()
def takeScreenshot(filename):
cmd = ['scrot', '-b', '-u', filename]
# print(cmd)
proc = subprocess.Popen(cmd)
proc.communicate()
with TemporaryDirectory() as tmp:
cfgFile = os.path.join(tmp, 'config')
appInstanceFile = os.path.join(tmp, 'appinstance')
cfg = config.Config(cfgFile)
appInstance = GUIApplicationInstance(appInstanceFile, '')
cfg.setSnapshotsPath(tmp)
cfg.setInclude([('/home/janedoe', 0),])
cfg.checkConfig()
cfg.save()
sn = snapshots.Snapshots(cfg)
rootSid = snapshots.RootSnapshot(cfg)
global qapp
qapp = qttools.createQApplication(cfg.APP_NAME)
translator = qttools.translator()
qapp.installTranslator(translator)
#########################
### Snapshot Log View ###
#########################
backintime_exec = '../backintime/common/backintime'
# backintime_exec = 'backintime'
cmd = [backintime_exec, '--config', cfgFile, 'backup']
proc = subprocess.Popen(cmd)
proc.communicate()
mainWindow = app.MainWindow(cfg, appInstance, qapp)
log = LogViewDialog(mainWindow, snapshots.lastSnapshot(cfg))
setScreenshotTimer(log, '_images/snapshot_log_view.png')
#####################
### Last Log View ###
#####################
log = LogViewDialog(mainWindow)
setScreenshotTimer(log, '_images/last_log_view.png')
sn.remove(snapshots.lastSnapshot(cfg))
#############################
### create fake snapshots ###
#############################
for d, t in ((date.today(), time(hour = 21, minute = 10, second = 14)),
(date.today(), time(hour = 17, minute = 53, second = 52)),
(date.today(), time(hour = 11, minute = 22, second = 3)),
(date.today() - timedelta(1), time(hour = 15, minute = 8, second = 25)),
(date.today() - timedelta(3), time(hour = 19, minute = 43, second = 13)),
(date.today() - timedelta(4), time(hour = 16, minute = 25, second = 47)),
(date.today() - timedelta(13), time(hour = 14, minute = 38, second = 11)),
):
sid = snapshots.SID(datetime.combine(d, t), cfg)
sid.makeDirs()
###################
### Main Window ###
###################
mainWindow = app.MainWindow(cfg, appInstance, qapp)
mainWindow.openPath('/home/janedoe')
# fix column width
mainWindow.mainSplitter.setSizes([120, 450])
mainWindow.secondSplitter.setSizes([110, 300])
mainWindow.filesView.header().resizeSection(0, 135)
mainWindow.filesView.header().resizeSection(1, 45)
setScreenshotTimer(mainWindow, '_images/main_window.png')
######################
### Restore Dialog ###
######################
mainWindow = app.MainWindow(cfg, appInstance, qapp)
setScreenshotTimerDlg(mainWindow,
lambda: mainWindow.confirmRestore(('/home/janedoe/Documents',
'/home/janedoe/Pictures')),
'_images/restore_confirm.png')
########################
### Snapshots Dialog ###
########################
snDlg = SnapshotsDialog(mainWindow, snapshots.NewSnapshot(cfg), '/home/janedoe/foo')
snDlg.addSnapshot(rootSid)
snDlg.comboEqualTo.addSnapshotID(rootSid)
for sid in mainWindow.snapshotsList:
snDlg.addSnapshot(sid)
snDlg.cbDeepCheck.setEnabled(True)
setScreenshotTimer(snDlg, '_images/snapshotsdialog.png', None, None)
#################################
### Settings Dialog - General ###
#################################
settings = settingsdialog.SettingsDialog(mainWindow)
settings.editSnapshotsPath.setText('/media/janedoe/ExternalDrive')
settings.txtHost.setText('testhost')
settings.txtUser.setText('janedoe')
settings.setComboValue(settings.comboSchedule, cfg._2_HOURS)
setScreenshotTimer(settings, '_images/settings_general.png')
# local encrypted
settings = settingsdialog.SettingsDialog(mainWindow)
settings.setComboValue(settings.comboModes, 'local_encfs')
settings.txtPassword1.setText('123456789012345678')
settings.editSnapshotsPath.setText('/media/janedoe/ExternalDrive')
settings.txtHost.setText('testhost')
settings.txtUser.setText('janedoe')
settings.setComboValue(settings.comboSchedule, cfg._2_HOURS)
setScreenshotTimer(settings, '_images/settings_general_local_encrypted.png')
# SSH
settings = settingsdialog.SettingsDialog(mainWindow)
settings.setComboValue(settings.comboModes, 'ssh')
settings.txtSshHost.setText('192.168.0.42')
settings.txtSshUser.setText('jane')
settings.txtSshPath.setText('/mnt/backup/')
settings.txtSshPrivateKeyFile.setText('/home/janedoe/.ssh/id_rsa')
settings.txtPassword1.setText('12345678901234')
settings.txtHost.setText('testhost')
settings.txtUser.setText('janedoe')
settings.setComboValue(settings.comboSchedule, cfg._2_HOURS)
setScreenshotTimer(settings, '_images/settings_general_ssh.png')
# SSH encrypted
settings = settingsdialog.SettingsDialog(mainWindow)
settings.setComboValue(settings.comboModes, 'ssh_encfs')
settings.txtSshHost.setText('192.168.0.42')
settings.txtSshUser.setText('jane')
settings.txtSshPath.setText('/mnt/backup/')
settings.txtSshPrivateKeyFile.setText('/home/janedoe/.ssh/id_rsa')
settings.txtPassword1.setText('12345678901234')
settings.txtPassword2.setText('123456789012345678')
settings.txtHost.setText('testhost')
settings.txtUser.setText('janedoe')
settings.setComboValue(settings.comboSchedule, cfg._2_HOURS)
setScreenshotTimer(settings, '_images/settings_general_ssh_encrypted.png')
#################################
### Settings Dialog - Include ###
#################################
settings = settingsdialog.SettingsDialog(mainWindow)
settings.tabs.setCurrentIndex(1)
setScreenshotTimer(settings, '_images/settings_include.png')
#################################
### Settings Dialog - Exclude ###
#################################
settings = settingsdialog.SettingsDialog(mainWindow)
settings.tabs.setCurrentIndex(2)
setScreenshotTimer(settings, '_images/settings_exclude.png')
####################################
### Settings Dialog - Autoremove ###
####################################
settings = settingsdialog.SettingsDialog(mainWindow)
settings.tabs.setCurrentIndex(3)
setScreenshotTimer(settings, '_images/settings_autoremove.png')
#################################
### Settings Dialog - Options ###
#################################
settings = settingsdialog.SettingsDialog(mainWindow)
settings.tabs.setCurrentIndex(4)
setScreenshotTimer(settings, '_images/settings_options.png')
########################################
### Settings Dialog - Expert Options ###
########################################
settings = settingsdialog.SettingsDialog(mainWindow)
settings.tabs.setCurrentIndex(5)
setScreenshotTimer(settings, '_images/settings_expert_options.png',
hight = 670)