Exemplo n.º 1
0
 def do_restore(self, listItem=None):
     copy_success = 0
     restore_file_path = xbmcDialog.browse(1, oe._(32373), 'files',
                                           '??????????????.tar', False,
                                           False, self.BACKUP_DESTINATION)
     # Do nothing if the dialog is cancelled - path will be the backup destination
     if not os.path.isfile(restore_file_path):
         return
     log.log(f'Restore file: {restore_file_path}', log.INFO)
     restore_file_name = restore_file_path.split('/')[-1]
     if os.path.exists(self.RESTORE_DIR):
         oe.execute(f'rm -rf {self.RESTORE_DIR}')
     os.makedirs(self.RESTORE_DIR)
     folder_stat = os.statvfs(self.RESTORE_DIR)
     file_size = os.path.getsize(restore_file_path)
     free_space = folder_stat.f_frsize * folder_stat.f_bavail
     if free_space > file_size * 2:
         if os.path.exists(self.RESTORE_DIR + restore_file_name):
             os.remove(self.RESTORE_DIR + restore_file_name)
         if oe.copy_file(restore_file_path,
                         self.RESTORE_DIR + restore_file_name) != None:
             copy_success = 1
             log.log('Restore file successfully copied.', log.INFO)
         else:
             log.log(f'Failed to copy restore file to: {self.RESTORE_DIR}',
                     log.ERROR)
             oe.execute(f'rm -rf {self.RESTORE_DIR}')
     else:
         txt = oe.split_dialog_text(oe._(32379))
         answer = xbmcDialog.ok('Restore', f'{txt[0]}\n{txt[1]}\n{txt[2]}')
     if copy_success == 1:
         txt = oe.split_dialog_text(oe._(32380))
         answer = xbmcDialog.yesno('Restore',
                                   f'{txt[0]}\n{txt[1]}\n{txt[2]}')
         if answer == 1:
             if oe.reboot_counter(10, oe._(32371)) == 1:
                 oe.winOeMain.close()
                 oe.xbmcm.waitForAbort(1)
                 subprocess.call(
                     ['/usr/bin/systemctl', '--no-block', 'reboot'],
                     close_fds=True)
         else:
             log.log('User Abort!')
             oe.execute(f'rm -rf {self.RESTORE_DIR}')
Exemplo n.º 2
0
 def do_restore(self, listItem=None):
     copy_success = 0
     restore_file_path = xbmcDialog.browse(1, oe._(32373), 'files',
                                           '??????????????.tar', False,
                                           False, self.BACKUP_DESTINATION)
     # Do nothing if the dialog is cancelled - path will be the backup destination
     if not os.path.isfile(restore_file_path):
         return
     restore_file_name = restore_file_path.split('/')[-1]
     if os.path.exists(self.RESTORE_DIR):
         oe.execute('rm -rf %s' % self.RESTORE_DIR)
     os.makedirs(self.RESTORE_DIR)
     folder_stat = os.statvfs(self.RESTORE_DIR)
     file_size = os.path.getsize(restore_file_path)
     free_space = folder_stat.f_frsize * folder_stat.f_bavail
     if free_space > file_size * 2:
         if os.path.exists(self.RESTORE_DIR + restore_file_name):
             os.remove(self.RESTORE_DIR + restore_file_name)
         if oe.copy_file(restore_file_path,
                         self.RESTORE_DIR + restore_file_name) != None:
             copy_success = 1
         else:
             oe.execute(f'rm -rf {self.RESTORE_DIR}')
     else:
         txt = oe.split_dialog_text(oe._(32379))
         answer = xbmcDialog.ok('Restore', f'{txt[0]}\n{txt[1]}\n{txt[2]}')
     if copy_success == 1:
         txt = oe.split_dialog_text(oe._(32380))
         answer = xbmcDialog.yesno('Restore',
                                   f'{txt[0]}\n{txt[1]}\n{txt[2]}')
         if answer == 1:
             if oe.reboot_counter(10, oe._(32371)) == 1:
                 oe.winOeMain.close()
                 oe.xbmcm.waitForAbort(1)
                 xbmc.executebuiltin('Reboot')
         else:
             log.log('User Abort!')
             oe.execute(f'rm -rf {self.RESTORE_DIR}')
Exemplo n.º 3
0
    def do_backup(self, listItem=None):
        try:
            self.total_backup_size = 1
            self.done_backup_size = 1
            try:
                for directory in self.BACKUP_DIRS:
                    self.get_folder_size(directory)
            except:
                pass
            bckDir = xbmcDialog.browse(0, oe._(32371), 'files', '', False,
                                       False, self.BACKUP_DESTINATION)

            if bckDir and os.path.exists(bckDir):
                # free space check
                try:
                    folder_stat = os.statvfs(bckDir)
                    free_space = folder_stat.f_frsize * folder_stat.f_bavail
                    if self.total_backup_size > free_space:
                        txt = oe.split_dialog_text(oe._(32379))
                        answer = xbmcDialog.ok(
                            'Backup', f'{txt[0]}\n{txt[1]}\n{txt[2]}')
                        return 0
                except:
                    pass
                self.backup_dlg = xbmcgui.DialogProgress()
                self.backup_dlg.create('LibreELEC', oe._(32375))
                if not os.path.exists(self.BACKUP_DESTINATION):
                    os.makedirs(self.BACKUP_DESTINATION)
                self.backup_file = oe.timestamp() + '.tar'
                tar = tarfile.open(bckDir + self.backup_file, 'w')
                for directory in self.BACKUP_DIRS:
                    self.tar_add_folder(tar, directory)
                tar.close()
                self.backup_dlg.close()
                del self.backup_dlg
        finally:
            self.backup_dlg.close()
Exemplo n.º 4
0
    def do_backup(self, listItem=None):
        try:
            self.total_backup_size = 1
            self.done_backup_size = 1
            try:
                for directory in self.BACKUP_DIRS:
                    self.get_folder_size(directory)
                log.log(f'Uncompressed backup size: {total_backup_size}',
                        log.DEBUG)
            except:
                pass
            bckDir = xbmcDialog.browse(0, oe._(32371), 'files', '', False,
                                       False, self.BACKUP_DESTINATION)
            log.log(f'Directory for backup: {bckDir}', log.INFO)

            if bckDir and os.path.exists(bckDir):
                # free space check
                try:
                    folder_stat = os.statvfs(bckDir)
                    free_space = folder_stat.f_frsize * folder_stat.f_bavail
                    log.log(f'Available free space for backup: {free_space}',
                            log.DEBUG)
                    if self.total_backup_size > free_space:
                        txt = oe.split_dialog_text(oe._(32379))
                        answer = xbmcDialog.ok(
                            'Backup', f'{txt[0]}\n{txt[1]}\n{txt[2]}')
                        return 0
                except:
                    log.log(
                        'Unable to determine free space available for backup.',
                        log.DEBUG)
                    pass
                self.backup_dlg = xbmcgui.DialogProgress()
                self.backup_dlg.create('LibreELEC', oe._(32375))
                if not os.path.exists(self.BACKUP_DESTINATION):
                    os.makedirs(self.BACKUP_DESTINATION)
                self.backup_file = f'{oe.timestamp()}.tar'
                log.log(f'Backup file: {bckDir + self.backup_file}', log.INFO)
                tar = tarfile.open(bckDir + self.backup_file,
                                   'w',
                                   format=tarfile.GNU_FORMAT)
                for directory in self.BACKUP_DIRS:
                    self.tar_add_folder(tar, directory)
                    if self.backup_dlg is None or self.backup_dlg.iscanceled():
                        break
                tar.close()
                if self.backup_dlg is None or self.backup_dlg.iscanceled():
                    try:
                        os.remove(self.BACKUP_DESTINATION + self.backup_file)
                    except:
                        pass
                else:
                    self.backup_dlg.update(100, oe._(32401))
                os.sync()
        finally:
            # possibly already closed by tar_add_folder if an error occurred
            try:
                self.backup_dlg.close()
            except:
                pass
            self.backup_dlg = None