def createModel(self): model = QStandardItemModel(0, 7) model.setHeaderData(0, Qt.Horizontal, self.path_title) model.setHeaderData(1, Qt.Horizontal, self.sect_title) model.setHeaderData(2, Qt.Horizontal, self.subv_title) model.setHeaderData(3, Qt.Horizontal, self.wday_title) model.setHeaderData(4, Qt.Horizontal, self.date_title) model.setHeaderData(5, Qt.Horizontal, self.time_title) model.setHeaderData(6, Qt.Horizontal, self.ts_title) n = 0 for i in mainWindow.sectionTable.selected: x = Section(settings.config[i]) for j in x.snapshot_paths: snap = x.snapshot_info(j, printout=False) model.insertRow(n) model.setData(model.index(n, 0), j) model.setData(model.index(n, 1), x.name) model.setData(model.index(n, 2), x.subvolume) model.setData(model.index(n, 3), snap.wday) model.setData(model.index(n, 4), snap.date) model.setData(model.index(n, 5), snap.time) model.setData(model.index(n, 6), snap.ts) n = +1 return model
def snapshots(): for s in settings.sections: x = Section(settings.config[s]) if args.verbose: for i in x.snapshot_paths: print(i, 'from', x.subvolume) else: x.print_snapshots()
def section_snapshots(): s = args.section_snapshots.rstrip('/') x = Section(settings.config[s]) if args.verbose: for i in x.snapshot_paths: print(i, 'from', x.subvolume) else: x.print_snapshots()
def section_snapshots(): for i in Snapman.args.targets: s = i.rstrip('/') x = Section(settings.config[s]) if Snapman.args.verbose: for i in x.snapshot_paths: print(i, 'from', x.subvolume) else: x.print_snapshots()
def run_once(): if not check_root(): clean_exit( '''You need to have root privileges to execute this script. Please try again, this time using "sudo". Exiting.''', BADPERM) for i in settings.sections: x = Section(settings.config[i]) x.makesnapshot()
def daemon(): if not check_root(): clean_exit( '''You need to have root privileges to execute this script in daemon mode. Please try again, this time using "sudo". Exiting.''', BADPERM) for i in settings.sections: x = Section(settings.config[i]) x.daemonize()
def sections(): if not args.verbose: for i in settings.sections: print(i) else: for i in settings.sections: x = Section(settings.config[i]) r = 'readonly' if x.readonly else 'writable' print(x.name + ':', str(x.snapshot_count()) + '/' + str(x.quota), r, 'from', x.subvolume)
def subvolume_clean(): sub = args.subvolume_clean if sub != '/': # Prevent strip filesystem root. sub = sub.rstrip('/') found = False for i in settings.sections: if sub == settings.config[i]['subvolume']: found = True x = Section(settings.config[i]) x.snapshot_clean() if not found: clean_exit('No section manages the subvolume: ' + sub, BADSUB)
def snapshot_info(): snap = args.snapshot_info if snap != '/': # Prevent strip filesystem root. snap = snap.rstrip('/') else: clean_exit("Root directory can't be a snapshot!", BADSNAP) found = 0 for i in settings.sections: x = Section(settings.config[i]) if x.snapshot_info(snap): found =+ 1 if not found: clean_exit('No section manages the snapshot: ' + snap, BADSNAP)
def subvolume_info(): sub = args.subvolume_info if sub != '/': # Prevent strip filesystem root. sub = sub.rstrip('/') found = False snap = [] sect = [] for i in settings.sections: if sub == settings.config[i]['subvolume']: found = True x = Section(settings.config[i]) snap += x.snapshot_paths sect.append(x.name) if not found: clean_exit('No section manages the subvolume: ' + sub, BADSUB) if snap: sort_snaps = sorted(snap) newer = sort_snaps[0] older = sort_snaps[-1] else: newer = '' older = '' if args.verbose: print('Subvolume:', sub) print('Snapshots:', len(snap), '\nSections:', len(sect), '\nNewer:', newer, '\nOlder:', older)
def subvolume_sections(): sub = args.subvolume_sections if sub != '/': # Prevent strip filesystem root. sub = sub.rstrip('/') found = False for i in settings.sections: if sub == settings.config[i]['subvolume']: found = True x = Section(settings.config[i]) if not args.verbose: print(x.name) else: print(x.name + ':', x.snapshot_count()) if not found: clean_exit('No section manages the subvolume: ' + sub, BADSUB)
def subvolume_snapshots(): sub = args.subvolume_snapshots if sub != '/': # Prevent strip filesystem root. sub = sub.rstrip('/') found = False for i in settings.sections: if sub == settings.config[i]['subvolume']: found = True x = Section(settings.config[i]) if not args.verbose: x.print_snapshots() else: for s in x.snapshot_paths: print(s, 'from', x.subvolume) if not found: clean_exit('Currently there is no snapshot for the subvolume: ' + sub, BADSUB)
def delete(self): failed = [] ok = False for s in self.selected: x = Section(settings.config[s]) if x.snapshot_clean(): ok = True else: failed.append(s) if failed: text = 'Failed to clean sections: \n\n' + '\n'.join(failed) + '\ \n\nMaybe are not you root?' title = 'Operation failed' self.mbox.warning(self, title, text, self.mbox.Ok) if ok: # Only update table if some were deleted self.reloadTable()
def delete(self): failed = [] ok = False for snap in self.selected: sect = self.selected[snap] x = Section(settings.config[sect]) if x.delete(snap): ok = True else: failed.append(snap) if failed: text = 'Failed to delete snapshots: \n\n' + '\n'.join(failed) + '\ \n\nMaybe are not you root?' title = 'Operation failed' self.mbox.warning(self, title, text, self.mbox.Ok) if ok: # Only update table if some were deleted mainWindow.sectionTable.reloadTable()
def new_snapshot(self): failed = [] ok = False for s in self.selected: x = Section(settings.config[s]) if x.makesnapshot(force=True): ok = True else: failed.append(s) if failed: text = 'Failed to create new snapshots for the sections: \n\n' + \ '\n'.join(failed) + '\ \n\nMaybe are not you root?' title = 'Operation failed' self.mbox.warning(self, title, text, self.mbox.Ok) if ok: # Only update table if some change happened self.reloadTable()
def section_properties(): s = args.section_properties.rstrip('/') x = Section(settings.config[s]) if args.verbose: x.print_properties() else: x.print_properties()
def createModel(self): # Column indices: PATH, SUBV, NSNAP, QUOTA, FREQUENCY, ENABLED = range(6) model = QStandardItemModel(0, 6) model.setHeaderData(PATH, Qt.Horizontal, self.sect_title) model.setHeaderData(SUBV, Qt.Horizontal, self.subv_title) model.setHeaderData(NSNAP, Qt.Horizontal, self.count_title) model.setHeaderData(QUOTA, Qt.Horizontal, self.quota_title) model.setHeaderData(FREQUENCY, Qt.Horizontal, self.freq_title) model.setHeaderData(ENABLED, Qt.Horizontal, self.enabled_title) for i in settings.sections: x = Section(settings.config[i]) model.insertRow(0) model.setData(model.index(0, PATH), x.name) model.setData(model.index(0, SUBV), x.subvolume) model.setData(model.index(0, NSNAP), x.count) model.setData(model.index(0, QUOTA), x.percent) model.setData(model.index(0, FREQUENCY), x.frequency) model.setData(model.index(0, ENABLED), x.enabled) return model
def section_properties(): for i in Snapman.args.targets: s = i.rstrip('/') x = Section(settings.config[s]) x.print_properties() print()
def section_newsnapshot(): for i in Snapman.args.targets: s = i.rstrip('/') x = Section(settings.config[s]) x.makesnapshot(True)
def section_clean(): for i in Snapman.args.targets: s = i.rstrip('/') x = Section(settings.config[s]) x.snapshot_clean()
def section_info(): for i in Snapman.args.targets: s = i.rstrip('/') x = Section(settings.config[s]) x.info() print()
def section_info(): s = args.section_info.rstrip('/') x = Section(settings.config[s]) x.info()
def section_clean(): s = args.section_clean.rstrip('/') x = Section(settings.config[s]) x.snapshot_clean()
def section_newsnapshot(): s = args.section_newsnapshot.rstrip('/') x = Section(settings.config[s]) x.makesnapshot(True)
def daemon(): for i in settings.sections: x = Section(settings.config[i]) x.daemonize()
def run_once(): for i in settings.sections: x = Section(settings.config[i]) x.makesnapshot()