当前位置: 首页>>代码示例>>Python>>正文


Python FileUtilities.delete方法代码示例

本文整理汇总了Python中bleachbit.FileUtilities.delete方法的典型用法代码示例。如果您正苦于以下问题:Python FileUtilities.delete方法的具体用法?Python FileUtilities.delete怎么用?Python FileUtilities.delete使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在bleachbit.FileUtilities的用法示例。


在下文中一共展示了FileUtilities.delete方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: execute

# 需要导入模块: from bleachbit import FileUtilities [as 别名]
# 或者: from bleachbit.FileUtilities import delete [as 别名]
 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
开发者ID:tstenner,项目名称:bleachbit,代码行数:37,代码来源:Command.py

示例2: start_with_computer

# 需要导入模块: from bleachbit import FileUtilities [as 别名]
# 或者: from bleachbit.FileUtilities import delete [as 别名]
def start_with_computer(enabled):
    """If enabled, create shortcut to start application with computer.
    If disabled, then delete the shortcut."""
    autostart_path = get_autostart_path()
    if not enabled:
        if os.path.lexists(autostart_path):
            FileUtilities.delete(autostart_path)
        return
    if os.path.lexists(autostart_path):
        return
    import winshell
    winshell.CreateShortcut(Path=autostart_path,
                            Target=os.path.join(bleachbit.bleachbit_exe_path, 'bleachbit.exe'))
开发者ID:tstenner,项目名称:bleachbit,代码行数:15,代码来源:Windows.py

示例3: sqlite_clean_helper

# 需要导入模块: from bleachbit import FileUtilities [as 别名]
# 或者: from bleachbit.FileUtilities import delete [as 别名]
    def sqlite_clean_helper(self, sql, fn, clean_func, check_func=None, setup_func=None):
        """Helper for cleaning special SQLite cleaning"""

        self.assertFalse(sql and fn, "sql and fn are mutually exclusive ways to create the data")

        if fn:
            filename = os.path.normpath(os.path.join(self.dir_base, fn))
            self.assertExists(filename)

        # create sqlite file
        elif sql:
            # create test file
            filename = self.mkstemp(prefix='bleachbit-test-sqlite')

            # additional setup
            if setup_func:
                setup_func(filename)

            # before SQL creation executed, cleaning should fail
            self.assertRaises(sqlite3.DatabaseError, clean_func, filename)
            # create
            FileUtilities.execute_sqlite3(filename, sql)
            self.assertExists(filename)
        else:
            raise RuntimeError('neither fn nor sql supplied')

        # clean the file
        old_shred = options.get('shred')
        options.set('shred', False, commit=False)
        self.assertFalse(options.get('shred'))
        clean_func(filename)
        options.set('shred', True, commit=False)
        self.assertTrue(options.get('shred'))
        options.set('shred', old_shred, commit=False)
        clean_func(filename)
        self.assertExists(filename)

        # check
        if check_func:
            check_func(self, filename)

        # tear down
        FileUtilities.delete(filename)
        self.assertNotExists(filename)
开发者ID:az0,项目名称:bleachbit,代码行数:46,代码来源:TestSpecial.py

示例4: test_delete

# 需要导入模块: from bleachbit import FileUtilities [as 别名]
# 或者: from bleachbit.FileUtilities import delete [as 别名]
    def test_delete(self):
        """Unit test for --delete option"""
        filename = self.mkstemp(prefix='bleachbit-test-cli-delete')
        if 'nt' == os.name:
            filename = os.path.normcase(filename)
        # replace delete function for testing
        save_delete = FileUtilities.delete
        deleted_paths = []

        def dummy_delete(path, shred=False):
            self.assertExists(path)
            deleted_paths.append(os.path.normcase(path))
        FileUtilities.delete = dummy_delete
        FileUtilities.delete(filename)
        self.assertExists(filename)
        operations = args_to_operations(['system.tmp'], False)
        preview_or_clean(operations, True)
        FileUtilities.delete = save_delete
        self.assertIn(filename, deleted_paths, "%s not found deleted" % filename)
        os.remove(filename)
        self.assertNotExists(filename)
开发者ID:az0,项目名称:bleachbit,代码行数:23,代码来源:TestCLI.py

示例5: start_with_computer

# 需要导入模块: from bleachbit import FileUtilities [as 别名]
# 或者: from bleachbit.FileUtilities import delete [as 别名]
def start_with_computer(enabled):
    """If enabled, create shortcut to start application with computer.
    If disabled, then delete the shortcut."""
    if not enabled:
        # User requests to not automatically start BleachBit
        if os.path.lexists(bleachbit.autostart_path):
            # Delete the shortcut
            FileUtilities.delete(bleachbit.autostart_path)
        return
    # User requests to automatically start BleachBit
    if os.path.lexists(bleachbit.autostart_path):
        # Already automatic, so exit
        return
    if not os.path.exists(bleachbit.launcher_path):
        logger.error('%s does not exist: ', bleachbit.launcher_path)
        return
    import shutil
    General.makedirs(os.path.dirname(bleachbit.autostart_path))
    shutil.copy(bleachbit.launcher_path, bleachbit.autostart_path)
    os.chmod(bleachbit.autostart_path, 0o755)
    if General.sudo_mode():
        General.chownself(bleachbit.autostart_path)
开发者ID:JulianVolodia,项目名称:bleachbit,代码行数:24,代码来源:Unix.py

示例6: test_delete

# 需要导入模块: from bleachbit import FileUtilities [as 别名]
# 或者: from bleachbit.FileUtilities import delete [as 别名]
 def test_delete(self):
     """Unit test for --delete option"""
     (fd, filename) = tempfile.mkstemp('bleachbit-test')
     os.close(fd)
     if 'nt' == os.name:
         import win32api
         filename = os.path.normcase(win32api.GetLongPathName(filename))
     # replace delete function for testing
     save_delete = FileUtilities.delete
     deleted_paths = []
     def dummy_delete(path, shred = False):
         self.assert_(os.path.exists(path))
         deleted_paths.append(os.path.normcase(path))
     FileUtilities.delete = dummy_delete
     FileUtilities.delete(filename)
     self.assert_(os.path.exists(filename))
     operations = args_to_operations(['system.tmp'], False)
     preview_or_clean(operations, True)
     FileUtilities.delete = save_delete
     self.assert_(filename in deleted_paths, \
         "%s not found deleted" % filename)
     os.remove(filename)
     self.assert_(not os.path.exists(filename))
开发者ID:hotelzululima,项目名称:bleachbit,代码行数:25,代码来源:TestCLI.py


注:本文中的bleachbit.FileUtilities.delete方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。