コード例 #1
0
ファイル: Command.py プロジェクト: tstenner/bleachbit
 def execute(self, really_delete):
     """Make changes and return results"""
     if FileUtilities.whitelisted(self.path):
         yield whitelist(self.path)
         return
     ret = {
         # TRANSLATORS: This is the label in the log indicating will be
         # deleted (for previews) or was actually deleted
         'label': _('Delete'),
         'n_deleted': 1,
         'n_special': 0,
         'path': self.path,
         'size': FileUtilities.getsize(self.path)}
     if really_delete:
         try:
             FileUtilities.delete(self.path, self.shred)
         except WindowsError as e:
             # WindowsError: [Error 32] The process cannot access the file because it is being
             # used by another process: u'C:\\Documents and
             # Settings\\username\\Cookies\\index.dat'
             if 32 != e.winerror and 5 != e.winerror:
                 raise
             try:
                 bleachbit.Windows.delete_locked_file(self.path)
             except:
                 raise
             else:
                 if self.shred:
                     import warnings
                     warnings.warn(
                         _('At least one file was locked by another process, so its contents could not be overwritten. It will be marked for deletion upon system reboot.'))
                 # TRANSLATORS: The file will be deleted when the
                 # system reboots
                 ret['label'] = _('Mark for deletion')
     yield ret
コード例 #2
0
 def execute(self, really_delete):
     """Make changes and return results"""
     if FileUtilities.whitelisted(self.path):
         yield whitelist(self.path)
         return
     ret = {
         # TRANSLATORS: This is the label in the log indicating will be
         # deleted (for previews) or was actually deleted
         'label': _('Delete'),
         'n_deleted': 1,
         'n_special': 0,
         'path': self.path,
         'size': FileUtilities.getsize(self.path)}
     if really_delete:
         try:
             FileUtilities.delete(self.path, self.shred)
         except WindowsError as e:
             # WindowsError: [Error 32] The process cannot access the file because it is being
             # used by another process: u'C:\\Documents and
             # Settings\\username\\Cookies\\index.dat'
             if 32 != e.winerror and 5 != e.winerror:
                 raise
             try:
                 bleachbit.Windows.delete_locked_file(self.path)
             except:
                 raise
             else:
                 if self.shred:
                     import warnings
                     warnings.warn(
                         _('At least one file was locked by another process, so its contents could not be overwritten. It will be marked for deletion upon system reboot.'))
                 # TRANSLATORS: The file will be deleted when the
                 # system reboots
                 ret['label'] = _('Mark for deletion')
     yield ret
コード例 #3
0
ファイル: Command.py プロジェクト: zhgfly01/bleachbit
    def execute(self, really_delete):

        if self.path is not None and FileUtilities.whitelisted(self.path):
            yield whitelist(self.path)
            return

        ret = {
            'label': self.label,
            'n_deleted': 0,
            'n_special': 1,
            'path': self.path,
            'size': None
        }

        if really_delete:
            if self.path is None:
                # Function takes no path.  It returns the size.
                func_ret = self.func()
                if isinstance(func_ret, types.GeneratorType):
                    # function returned generator
                    for func_ret in self.func():
                        if True == func_ret or isinstance(func_ret, tuple):
                            # Return control to GTK idle loop.
                            # If tuple, then display progress.
                            yield func_ret
                # either way, func_ret should be an integer
                assert isinstance(func_ret, (int, long))
                ret['size'] = func_ret
            else:
                if os.path.isdir(self.path):
                    raise RuntimeError(
                        'Attempting to run file function %s on directory %s' %
                        (self.func.func_name, self.path))
                # Function takes a path.  We check the size.
                oldsize = FileUtilities.getsize(self.path)
                try:
                    self.func(self.path)
                except DatabaseError as e:
                    if -1 == e.message.find('file is encrypted or is not a database') and \
                       -1 == e.message.find('or missing database'):
                        raise
                    logging.getLogger(__name__).exception(e.message)
                    return
                try:
                    newsize = FileUtilities.getsize(self.path)
                except OSError as e:
                    from errno import ENOENT
                    if e.errno == ENOENT:
                        # file does not exist
                        newsize = 0
                    else:
                        raise
                ret['size'] = oldsize - newsize
        yield ret
コード例 #4
0
ファイル: Command.py プロジェクト: tstenner/bleachbit
    def execute(self, really_delete):

        if self.path is not None and FileUtilities.whitelisted(self.path):
            yield whitelist(self.path)
            return

        ret = {
            'label': self.label,
            'n_deleted': 0,
            'n_special': 1,
            'path': self.path,
            'size': None}

        if really_delete:
            if self.path is None:
                # Function takes no path.  It returns the size.
                func_ret = self.func()
                if isinstance(func_ret, types.GeneratorType):
                    # function returned generator
                    for func_ret in self.func():
                        if True == func_ret or isinstance(func_ret, tuple):
                            # Return control to GTK idle loop.
                            # If tuple, then display progress.
                            yield func_ret
                # either way, func_ret should be an integer
                assert isinstance(func_ret, (int, long))
                ret['size'] = func_ret
            else:
                if os.path.isdir(self.path):
                    raise RuntimeError('Attempting to run file function %s on directory %s' %
                                       (self.func.func_name, self.path))
                # Function takes a path.  We check the size.
                oldsize = FileUtilities.getsize(self.path)
                try:
                    self.func(self.path)
                except DatabaseError as e:
                    if -1 == e.message.find('file is encrypted or is not a database') and \
                       -1 == e.message.find('or missing database'):
                        raise
                    logging.getLogger(__name__).exception(e.message)
                    return
                try:
                    newsize = FileUtilities.getsize(self.path)
                except OSError as e:
                    from errno import ENOENT
                    if e.errno == ENOENT:
                        # file does not exist
                        newsize = 0
                    else:
                        raise
                ret['size'] = oldsize - newsize
        yield ret
コード例 #5
0
ファイル: Command.py プロジェクト: tstenner/bleachbit
    def execute(self, really_delete):
        """Make changes and return results"""

        if FileUtilities.whitelisted(self.path):
            yield whitelist(self.path)
            return

        ret = {
            # TRANSLATORS: The file will be truncated to 0 bytes in length
            'label': _('Truncate'),
            'n_deleted': 1,
            'n_special': 0,
            'path': self.path,
            'size': FileUtilities.getsize(self.path)}
        if really_delete:
            f = open(self.path, 'wb')
            f.truncate(0)
        yield ret
コード例 #6
0
    def execute(self, really_delete):
        """Make changes and return results"""

        if FileUtilities.whitelisted(self.path):
            yield whitelist(self.path)
            return

        ret = {
            # TRANSLATORS: The file will be truncated to 0 bytes in length
            'label': _('Truncate'),
            'n_deleted': 1,
            'n_special': 0,
            'path': self.path,
            'size': FileUtilities.getsize(self.path)}
        if really_delete:
            f = open(self.path, 'wb')
            f.truncate(0)
        yield ret
コード例 #7
0
ファイル: Command.py プロジェクト: tstenner/bleachbit
    def execute(self, really_delete):
        """Make changes and return results"""

        if FileUtilities.whitelisted(self.path):
            yield whitelist(self.path)
            return

        ret = {
            'label': _('Clean file'),
            'n_deleted': 0,
            'n_special': 1,
            'path': self.path,
            'size': None}
        if really_delete:
            oldsize = FileUtilities.getsize(self.path)
            FileUtilities.clean_json(self.path, self.address)
            newsize = FileUtilities.getsize(self.path)
            ret['size'] = oldsize - newsize
        yield ret
コード例 #8
0
    def execute(self, really_delete):
        """Make changes and return results"""

        if FileUtilities.whitelisted(self.path):
            yield whitelist(self.path)
            return

        ret = {
            'label': _('Clean file'),
            'n_deleted': 0,
            'n_special': 1,
            'path': self.path,
            'size': None}
        if really_delete:
            oldsize = FileUtilities.getsize(self.path)
            FileUtilities.clean_json(self.path, self.address)
            newsize = FileUtilities.getsize(self.path)
            ret['size'] = oldsize - newsize
        yield ret
コード例 #9
0
ファイル: Command.py プロジェクト: tstenner/bleachbit
    def execute(self, really_delete):
        """Make changes and return results"""

        if FileUtilities.whitelisted(self.path):
            yield whitelist(self.path)
            return

        ret = {
            # TRANSLATORS: Parts of this file will be deleted
            'label': _('Clean file'),
            'n_deleted': 0,
            'n_special': 1,
            'path': self.path,
            'size': None}
        if really_delete:
            oldsize = FileUtilities.getsize(self.path)
            FileUtilities.clean_ini(self.path, self.section, self.parameter)
            newsize = FileUtilities.getsize(self.path)
            ret['size'] = oldsize - newsize
        yield ret
コード例 #10
0
    def execute(self, really_delete):
        """Make changes and return results"""

        if FileUtilities.whitelisted(self.path):
            yield whitelist(self.path)
            return

        ret = {
            # TRANSLATORS: Parts of this file will be deleted
            'label': _('Clean file'),
            'n_deleted': 0,
            'n_special': 1,
            'path': self.path,
            'size': None}
        if really_delete:
            oldsize = FileUtilities.getsize(self.path)
            FileUtilities.clean_ini(self.path, self.section, self.parameter)
            newsize = FileUtilities.getsize(self.path)
            ret['size'] = oldsize - newsize
        yield ret