Example #1
0
def delete_updates():
    """Returns commands for deleting Windows Updates files"""
    windir = bleachbit.expandvars('$windir')
    dirs = glob.glob(os.path.join(windir, '$NtUninstallKB*'))
    dirs += [bleachbit.expandvars('$windir\\SoftwareDistribution\\Download')]
    dirs += [bleachbit.expandvars('$windir\\ie7updates')]
    dirs += [bleachbit.expandvars('$windir\\ie8updates')]
    if not dirs:
        # if nothing to delete, then also do not restart service
        return

    import win32serviceutil
    wu_running = win32serviceutil.QueryServiceStatus('wuauserv')[1] == 4

    args = ['net', 'stop', 'wuauserv']

    def wu_service():
        General.run_external(args)
        return 0
    if wu_running:
        yield Command.Function(None, wu_service, " ".join(args))

    for path1 in dirs:
        for path2 in FileUtilities.children_in_directory(path1, True):
            yield Command.Delete(path2)
        if os.path.exists(path1):
            yield Command.Delete(path1)

    args = ['net', 'start', 'wuauserv']
    if wu_running:
        yield Command.Function(None, wu_service, " ".join(args))
Example #2
0
def delete_updates():
    """Returns commands for deleting Windows Updates files"""
    windir = bleachbit.expandvars('$windir')
    dirs = glob.glob(os.path.join(windir, '$NtUninstallKB*'))
    dirs += [bleachbit.expandvars('$windir\\SoftwareDistribution\\Download')]
    dirs += [bleachbit.expandvars('$windir\\ie7updates')]
    dirs += [bleachbit.expandvars('$windir\\ie8updates')]
    if not dirs:
        # if nothing to delete, then also do not restart service
        return

    import win32serviceutil
    wu_running = win32serviceutil.QueryServiceStatus('wuauserv')[1] == 4

    args = ['net', 'stop', 'wuauserv']

    def wu_service():
        General.run_external(args)
        return 0

    if wu_running:
        yield Command.Function(None, wu_service, " ".join(args))

    for path1 in dirs:
        for path2 in FileUtilities.children_in_directory(path1, True):
            yield Command.Delete(path2)
        if os.path.exists(path1):
            yield Command.Delete(path1)

    args = ['net', 'start', 'wuauserv']
    if wu_running:
        yield Command.Function(None, wu_service, " ".join(args))
Example #3
0
def get_recycle_bin():
    """Yield a list of files in the recycle bin"""
    pidl = shell.SHGetSpecialFolderLocation(0, shellcon.CSIDL_BITBUCKET)
    desktop = shell.SHGetDesktopFolder()
    h = desktop.BindToObject(pidl, None, shell.IID_IShellFolder)
    for item in h:
        path = h.GetDisplayNameOf(item, shellcon.SHGDN_FORPARSING)
        if os.path.isdir(path):
            # Return the contents of a normal directory, but do
            # not recurse Windows symlinks in the Recycle Bin.
            yield from FileUtilities.children_in_directory(path, True)
        yield path
Example #4
0
def get_recycle_bin():
    """Yield a list of files in the recycle bin"""
    pidl = shell.SHGetSpecialFolderLocation(0, shellcon.CSIDL_BITBUCKET)
    desktop = shell.SHGetDesktopFolder()
    h = desktop.BindToObject(pidl, None, shell.IID_IShellFolder)
    for item in h:
        path = h.GetDisplayNameOf(item, shellcon.SHGDN_FORPARSING)
        if os.path.isdir(path):
            for child in FileUtilities.children_in_directory(path, True):
                yield child
            yield path
        else:
            yield path
Example #5
0
def get_recycle_bin():
    """Yield a list of files in the recycle bin"""
    pidl = shell.SHGetSpecialFolderLocation(0, shellcon.CSIDL_BITBUCKET)
    desktop = shell.SHGetDesktopFolder()
    h = desktop.BindToObject(pidl, None, shell.IID_IShellFolder)
    for item in h:
        path = h.GetDisplayNameOf(item, shellcon.SHGDN_FORPARSING)
        if os.path.isdir(path):
            for child in FileUtilities.children_in_directory(path, True):
                yield child
            yield path
        else:
            yield path
Example #6
0
 def get_walk_all(top):
     for expanded in glob.iglob(top):
         any_match = False
         for path in FileUtilities.children_in_directory(
                 expanded, True):
             any_match = True
             yield path
         # This is a lint checker because this scenario may
         # indicate the cleaner developer made a mistake.
         if not any_match and os.path.isfile(expanded):
             logger.debug(
                 _('search="walk.all" used with regular file path="%s"'
                   ), expanded)
Example #7
0
 def get_walk_all(top):
     """Delete files and directories inside a directory but not the top directory"""
     for expanded in glob.iglob(top):
         any_match = False
         for path in FileUtilities.children_in_directory(
                 expanded, True):
             any_match = True
             yield path
         # This is a lint checker because this scenario may
         # indicate the cleaner developer made a mistake.
         if not any_match and os.path.isfile(expanded):
             logger.debug(
                 _('search="walk.all" used with regular file path="%s"'), expanded)
Example #8
0
def get_recycle_bin():
    """Yield a list of files in the recycle bin"""
    pidl = shell.SHGetSpecialFolderLocation(0, shellcon.CSIDL_BITBUCKET)
    desktop = shell.SHGetDesktopFolder()
    h = desktop.BindToObject(pidl, None, shell.IID_IShellFolder)
    for item in h:
        path = h.GetDisplayNameOf(item, shellcon.SHGDN_FORPARSING)
        if os.path.isdir(path):
            if not is_link(path):
                # Return the contents of a normal directory, but do
                # not recurse Windows symlinks in the Recycle Bin.
                for child in FileUtilities.children_in_directory(path, True):
                    yield child
        yield path
Example #9
0
 def get_walk_all(top):
     """Delete files and directories inside a directory but not the top directory"""
     for expanded in glob.iglob(top):
         path = None  # sentinel value
         for path in FileUtilities.children_in_directory(
                 expanded, True):
             yield path
         # This condition executes when there are zero iterations
         # in the loop above.
         if path is None:
             # This is a lint checker because this scenario may
             # indicate the cleaner developer made a mistake.
             if os.path.isfile(expanded):
                 logger.debug(
                     _('search="walk.all" used with regular file path="%s"'
                       ),
                     expanded,
                 )
Example #10
0
 def get_walk_all(top):
     """Delete files and directories inside a directory but not the top directory"""
     for expanded in glob.iglob(top):
         path = None  # sentinel value
         yield from FileUtilities.children_in_directory(expanded, True)
         # This condition executes when there are zero iterations
         # in the loop above.
         if path is None:
             # This is a lint checker because this scenario may
             # indicate the cleaner developer made a mistake.
             if os.path.isfile(expanded):
                 logger.debug(
                     # TRANSLATORS: This is a lint-style warning that there seems to be a
                     # mild mistake in the CleanerML file because walk.all is expected to
                     # be used with directories instead of with files.
                     _('search="walk.all" used with regular file path="%s"'
                       ),
                     expanded,
                 )
Example #11
0
def delete_updates():
    """Returns commands for deleting Windows Updates files"""
    windir = os.path.expandvars('%windir%')
    dirs = glob.glob(os.path.join(windir, '$NtUninstallKB*'))
    dirs += [os.path.expandvars(r'%windir%\SoftwareDistribution')]
    dirs += [os.path.expandvars(r'%windir%\SoftwareDistribution.old')]
    dirs += [os.path.expandvars(r'%windir%\SoftwareDistribution.bak')]
    dirs += [os.path.expandvars(r'%windir%\ie7updates')]
    dirs += [os.path.expandvars(r'%windir%\ie8updates')]
    dirs += [os.path.expandvars(r'%windir%\system32\catroot2')]
    if not dirs:
        # if nothing to delete, then also do not restart service
        return

    args = []

    def run_wu_service():
        General.run_external(args)
        return 0

    services = {}
    all_services = ('wuauserv', 'cryptsvc', 'bits', 'msiserver')
    for service in all_services:
        import win32serviceutil
        services[service] = win32serviceutil.QueryServiceStatus(service)[
            1] == 4
        logger.debug('Windows service {} has current state: {}'.format(
            service, services[service]))

        if services[service]:
            args = ['net', 'stop', service]
            yield Command.Function(None, run_wu_service, " ".join(args))

    for path1 in dirs:
        for path2 in FileUtilities.children_in_directory(path1, True):
            yield Command.Delete(path2)
        if os.path.exists(path1):
            yield Command.Delete(path1)

    for this_service in all_services:
        if services[this_service]:
            args = ['net', 'start', this_service]
            yield Command.Function(None, run_wu_service, " ".join(args))
Example #12
0
 def get_walk_files(top):
     for expanded in glob.iglob(top):
         for path in FileUtilities.children_in_directory(expanded, False):
             yield path
Example #13
0
    def get_commands(self, option_id):
        # cache
        if 'posix' == os.name and 'cache' == option_id:  # ์šด์˜์ฒด์ œ์ด๋ฆ„์ด posix์ด๊ณ  option_id๊ฐ€ ์บ์‹œ์ธ ๊ฒฝ์šฐ 
            dirname = expanduser("~/.cache/") # ~/.cache/์—์„œ "~"์„ ์‚ฌ์šฉ์ž ๋””๋ ‰ํ† ๋ฆฌ์˜ ์ ˆ๋Œ€๊ฒฝ๋กœ๋กœ ๋Œ€์ฒดํ•œ ๊ฒƒ์„ dirname์— ์ €์žฅ
                                              # dirname = C:\\Documents and Settings\\Administrator\\.cache\ ๊ฐ€ ๋œ๋‹ค.
                
            for filename in children_in_directory(dirname, True): 
                # C:\\Documents and Settings\\Administrator\\.cache\ ์˜ ํŒŒ์ผ ๋ฐ ์„ ํƒ์ ์œผ๋กœ ํ•˜์œ„ ๋””๋ ‰ํ† ๋ฆฌ๋ฅผ ๋ฐ˜๋ณต
                if not self.whitelisted(filename): # filename์ด whitelist์ธ์ง€ ํ™•์ธํ•ด์„œ true์ผ ๊ฒฝ์šฐ
                    yield Command.Delete(filename) # filename์„ ์‚ญ์ œํ•˜๋Š” ๋ฉ”์„œ๋“œ๋ฅผ return

        # custom
        if 'custom' == option_id:             # option_id๊ฐ€ custom์ธ์ง€ ํ™•์ธ custom = ์‚ฌ์šฉ์ž ์ •์˜ 
            for (c_type, c_path) in options.get_custom_paths(): # ์‚ฌ์šฉ์ž ์ •์˜ ๊ฒฝ๋กœ์˜ ํŒŒ์ผ ๋ฐ ํด๋”๋ฅผ ๋ฐ˜๋ณต 
                if 'file' == c_type: 
                    yield Command.Delete(c_path) # fileํƒ€์ž…์ผ ๊ฒฝ์šฐ ์‚ญ์ œ
                elif 'folder' == c_type:
                    yield Command.Delete(c_path) # folderํƒ€์ž…์ผ ๊ฒฝ์šฐ ์‚ญ์ œ
                    for path in children_in_directory(c_path, True):  # c_path(์‚ฌ์šฉ์ž ์ •์˜ ๊ฒฝ๋กœ)์˜ ํŒŒ์ผ ๋ฐ ์„ ํƒ์ ์œผ๋กœ ํ•˜์œ„ ๋””๋ ‰ํ† ๋ฆฌ ๋ฐ˜๋ณต
                        yield Command.Delete(path) # ๋ฐ˜๋ณต๋˜๋Š” ํŒŒ์ผ ๋ฐ ํ•˜์œ„ ๋””๋ ‰ํ† ๋ฆฌ ์‚ญ์ œ
                else:
                    raise RuntimeError(    # ํŒŒ์ผ๋„ ํด๋”๋„ ์•„๋‹๊ฒฝ์šฐ ๋Ÿฐํƒ€์ž„์—๋Ÿฌ ๋ฐœ์ƒ
                        'custom folder has invalid type %s' % c_type)

        # menu
        menu_dirs = ['~/.local/share/applications',
                     '~/.config/autostart',
                     '~/.gnome/apps/',
                     '~/.gnome2/panel2.d/default/launchers',
                     '~/.gnome2/vfolders/applications/',
                     '~/.kde/share/apps/RecentDocuments/',
                     '~/.kde/share/mimelnk',
                     '~/.kde/share/mimelnk/application/ram.desktop',
                     '~/.kde2/share/mimelnk/application/',
                     '~/.kde2/share/applnk']
        # ๋ฉ”๋‰ด ๋””๋ ‰ํ† ๋ฆฌ์— ๋‹ค์Œ ๊ฒฝ๋กœ๋“ค์„ ์„ค์ •

        if 'posix' == os.name and 'desktop_entry' == option_id:          #  ์šด์˜์ฒด์ œ๊ฐ€ posix์ด๊ณ  option_id๊ฐ€ desktop_entry์ธ ๊ฒฝ์šฐ
            for dirname in menu_dirs: # ๋ฉ”๋‰ด ๋””๋ ‰ํ† ๋ฆฌ์— ์žˆ๋Š” ๊ฒฝ๋กœ๋ฅผ ๋ฐ˜๋ณต 
                for filename in [fn for fn in children_in_directory(dirname, False)  
                                 if fn.endswith('.desktop')]: 
                    if Unix.is_broken_xdg_desktop(filename): # filename์˜ XDG ๋ฐ์Šคํฌํ†ฑ ํ•ญ๋ชฉ ํŒŒ์ผ์˜ ์†์ƒ ์—ฌ๋ถ€ ํ™•์ธ 
                        yield Command.Delete(filename) # filename ์‚ญ์ œ 

        # unwanted locales
        if 'posix' == os.name and 'localizations' == option_id: # ์šด์˜์ฒด์ œ๊ฐ€ posix๊ณ  option_id๊ฐ€ localizations์ผ๋•Œ 
            for path in Unix.locales.localization_paths(locales_to_keep=options.get_languages()):
                # ์ด์ „์— ์ถ”๊ฐ€ํ•œ xml ๊ตฌ์„ฑ๊ณผ ์ผ์น˜ํ•˜๋Š” ๋ชจ๋“  ์œ„์น˜ ์ง€์ • ํ•ญ๋ชฉ์„ ๋ฐ˜๋ณต
                if os.path.isdir(path): # path๊ฐ€ ์กด์žฌํ•˜๋Š”์ง€ ํ™•์ธ 
                    for f in FileUtilities.children_in_directory(path, True): # path์˜ ํŒŒ์ผ ๋ฐ ํ•˜์œ„ ๋””๋ ‰ํ† ๋ฆฌ ๋ฐ˜๋ณต
                        yield Command.Delete(f) # path์˜ ํŒŒ์ผ ๋ฐ ํ•˜์œ„ ๋””๋ ‰ํ† ๋ฆฌ ์‚ญ์ œ
                yield Command.Delete(path) # path์‚ญ์ œ

        # Windows logs
        if 'nt' == os.name and 'logs' == option_id:   # os๊ฐ€ ์œˆ๋„์šฐ๊ณ  option_id๊ฐ€ ๋กœ๊ทธ์ผ๋•Œ 
            paths = (
                '$ALLUSERSPROFILE\\Application Data\\Microsoft\\Dr Watson\\*.log',
                '$ALLUSERSPROFILE\\Application Data\\Microsoft\\Dr Watson\\user.dmp',
                '$LocalAppData\\Microsoft\\Windows\\WER\\ReportArchive\\*\\*',
                '$LocalAppData\\Microsoft\\Windows\WER\\ReportQueue\\*\\*',
                '$programdata\\Microsoft\\Windows\\WER\\ReportArchive\\*\\*',
                '$programdata\\Microsoft\\Windows\\WER\\ReportQueue\\*\\*',
                '$localappdata\\Microsoft\\Internet Explorer\\brndlog.bak',
                '$localappdata\\Microsoft\\Internet Explorer\\brndlog.txt',
                '$windir\\*.log',
                '$windir\\imsins.BAK',
                '$windir\\OEWABLog.txt',
                '$windir\\SchedLgU.txt',
                '$windir\\ntbtlog.txt',
                '$windir\\setuplog.txt',
                '$windir\\REGLOCS.OLD',
                '$windir\\Debug\\*.log',
                '$windir\\Debug\\Setup\\UpdSh.log',
                '$windir\\Debug\\UserMode\\*.log',
                '$windir\\Debug\\UserMode\\ChkAcc.bak',
                '$windir\\Debug\\UserMode\\userenv.bak',
                '$windir\\Microsoft.NET\Framework\*\*.log',
                '$windir\\pchealth\\helpctr\\Logs\\hcupdate.log',
                '$windir\\security\\logs\\*.log',
                '$windir\\security\\logs\\*.old',
                '$windir\\SoftwareDistribution\\*.log',
                '$windir\\SoftwareDistribution\\DataStore\\Logs\\*',
                '$windir\\system32\\TZLog.log',
                '$windir\\system32\\config\\systemprofile\\Application Data\\Microsoft\\Internet Explorer\\brndlog.bak',
                '$windir\\system32\\config\\systemprofile\\Application Data\\Microsoft\\Internet Explorer\\brndlog.txt',
                '$windir\\system32\\LogFiles\\AIT\\AitEventLog.etl.???',
                '$windir\\system32\\LogFiles\\Firewall\\pfirewall.log*',
                '$windir\\system32\\LogFiles\\Scm\\SCM.EVM*',
                '$windir\\system32\\LogFiles\\WMI\\Terminal*.etl',
                '$windir\\system32\\LogFiles\\WMI\\RTBackup\EtwRT.*etl',
                '$windir\\system32\\wbem\\Logs\\*.lo_',
                '$windir\\system32\\wbem\\Logs\\*.log', )
               
            for path in paths: # paths์— ์žˆ๋Š” ๊ฒฝ๋กœ ๋ฐ˜๋ณต
                expanded = expandvars(path) # ๊ฒฝ๋กœ์— ํ™˜๊ฒฝ๋ณ€์ˆ˜๊ฐ€ ํฌํ•จ๋˜์–ด์žˆ์œผ๋ฉด ํ™•์žฅ
                for globbed in glob.iglob(expanded): # ํ™•์žฅํ•œ ๊ฒฝ๋กœ์˜ ํŒŒ์ผ๋ฐ ๋””๋ ‰ํ† ๋ฆฌ๋ฅผ ๋ฐ˜๋ณต
                    yield Command.Delete(globbed) # ์‚ญ์ œ

        # memory
        if sys.platform.startswith('linux') and 'memory' == option_id: # ์‹œ์Šคํ…œ์˜ ํ”Œ๋žซํผ์ด lunux๋กœ ์‹œ์ž‘ํ•˜๊ณ  option_id๊ฐ€ ๋ฉ”๋ชจ๋ฆฌ์ด๋ฉด
            yield Command.Function(None, Memory.wipe_memory, _('Memory')) # ๋ฉ”๋ชจ๋ฆฌ๋ฅผ ์ง€์šฐ๋Š” ๊ฐ„๋‹จํ•œ ํŒŒ์ด์ฌ ํ•จ์ˆ˜๋ฅผ ๋งŒ๋“ฌ

        # memory dump
        # how to manually create this file
        # http://www.pctools.com/guides/registry/detail/856/
        if 'nt' == os.name and 'memory_dump' == option_id: # os๊ฐ€ ์œˆ๋„์šฐ๊ณ  option_id๊ฐ€ memory_dump ์ผ๋•Œ
            fname = expandvars('$windir\\memory.dmp') # $windir\\memory.dmp์— ํ™˜๊ฒฝ๋ณ€์ˆ˜๊ฐ€ ์žˆ์œผ๋ฉด ํ™•์žฅ
            if os.path.exists(fname): # ํ™•์žฅํ•œ ๊ฒฝ๋กœ๊ฐ€ ์กด์žฌํ•˜๋Š”์ง€ ํ™•์ธ
                yield Command.Delete(fname) # ์กด์žฌํ•˜๋ฉด ์‚ญ์ œ
            for fname in glob.iglob(expandvars('$windir\\Minidump\\*.dmp')): # $windir\\Minidump\\*.dmp ๋ฅผ ํ™•์žฅํ•˜๊ณ  ํŒŒ์ผ ๋ฐ ๋””๋ ‰ํ† ๋ฆฌ ๋ฐ˜๋ณต
                yield Command.Delete(fname) # $windir\\Minidump\\*.dmp'์˜ ํŒŒ์ผ ๋ฐ ๋””๋ ‰ํ† ๋ฆฌ๋“ค์„ ์‚ญ์ œ

        # most recently used documents list
        if 'posix' == os.name and 'recent_documents' == option_id: # os๊ฐ€ posix๊ณ  option_id๊ฐ€ ์ตœ๊ทผ ๋ฌธ์„œ์ผ ๊ฒฝ์šฐ
            ru_fn = expanduser("~/.recently-used") # ~/.recently-used ์—์„œ "~"์„ ์‚ฌ์šฉ์ž ๋””๋ ‰ํ† ๋ฆฌ์˜ ๊ฒฝ๋กœ๋กœ ๋Œ€์ฒด
            if os.path.lexists(ru_fn): # ์‚ฌ์šฉ์ž ๋””๋ ‰ํ† ๋ฆฌ/.recently-used ๊ฐ€ ์กด์žฌํ•˜๋Š”์ง€ ํ™•์ธ
                yield Command.Delete(ru_fn) # ์กด์žฌํ•˜๋ฉด ์‚ญ์ œ
            # GNOME 2.26 (as seen on Ubuntu 9.04) will retain the list
            # in memory if it is simply deleted, so it must be shredded
            # (or at least truncated).
            #
            # GNOME 2.28.1 (Ubuntu 9.10) and 2.30 (10.04) do not re-read
            # the file after truncation, but do re-read it after
            # shredding.
            #
            # https://bugzilla.gnome.org/show_bug.cgi?id=591404

            def gtk_purge_items(): 
                """Purge GTK items"""                      # GTK ํ•ญ๋ชฉ ์ œ๊ฑฐ
                gtk.RecentManager().purge_items()
                yield 0

            for pathname in ["~/.recently-used.xbel", "~/.local/share/recently-used.xbel"]:
                pathname = expanduser(pathname) # ๊ฒฝ๋กœ์—์„œ "~"์„ ์‚ฌ์šฉ์ž ๋””๋ ‰ํ† ๋ฆฌ๋กœ ๋Œ€์ฒด
                if os.path.lexists(pathname): # ๊ฒฝ๋กœ์˜ ํŒŒ์ผ์ด ์กด์žฌํ•˜๋Š”์ง€ ํ™•์ธ
                    yield Command.Shred(pathname) # ์žˆ์œผ๋ฉด pathname ์ž˜๋ผ๋‚ด๊ธฐ
            if HAVE_GTK:
                # Use the Function to skip when in preview mode
                yield Command.Function(None, gtk_purge_items, _('Recent documents list'))
                      # GTK ๋ชจ๋“ˆ์„ ๋ถˆ๋Ÿฌ์˜ค๋Š”๋ฐ ์„ฑ๊ณตํ–ˆ์œผ๋ฉด ์ตœ๊ทผ ๋ฌธ์„œ ๋ชฉ๋ก์„ ๋‚˜ํƒ€๋‚ด๋Š” ๊ฐ„๋‹จํ•œ ํ•จ์ˆ˜ ์ƒ์„ฑ

        if 'posix' == os.name and 'rotated_logs' == option_id: # ์šด์˜์ฒด์ œ๊ฐ€ posix๊ณ  option_id ๊ฐ€ ์ˆœํ™˜๋กœ๊ทธ์ผ๋•Œ 
            for path in Unix.rotated_logs():  #  /var/log/์—์„œ ์ˆœํ™˜ ๋กœ๊ทธ(์˜ˆ: ์ด์ „ ๋กœ๊ทธ) ๋ชฉ๋ก์„ ๋ฐ˜๋ณต 
                yield Command.Delete(path) # ์‚ญ์ œ

        # temporary files
        if 'posix' == os.name and 'tmp' == option_id: # ์šด์˜์ฒด์ œ๊ฐ€ posix์ด๊ณ  option_id๊ฐ€ tmp ( ์ž„์‹œํŒŒ์ผ) ์ผ๋•Œ
            dirnames = ['/tmp', '/var/tmp'] # ๊ฒฝ๋กœ ์ €์žฅ
            for dirname in dirnames: # ์ž„์‹œํŒŒ์ผ์˜ ๊ฒฝ๋กœ ๋ฐ˜๋ณต
                for path in children_in_directory(dirname, True): # ๊ฒฝ๋กœ์˜ ํŒŒ์ผ ๋ฐ ํ•˜์œ„ ๋””๋ ‰ํ† ๋ฆฌ ๋ฐ˜๋ณต
                    is_open = FileUtilities.openfiles.is_open(path)  # path์˜ ํŒŒ์ผ์ด ์—ด๋ ค์žˆ๋Š”์ง€ ์—ฌ๋ถ€ 
                    ok = not is_open and os.path.isfile(path) and # path์˜ ํŒŒ์ผ์ด ์—ด๋ ค์žˆ์ง€ ์•Š๊ณ  path๊ฐ€ ์กด์žฌํ•˜๋ฉฐ
                        not os.path.islink(path) and \ # path๊ฐ€ linkํŒŒ์ผ ํ˜น์€ ํด๋”๊ฐ€ ์•„๋‹ˆ๊ณ 
                        FileUtilities.ego_owner(path) and \ # ํ˜„์žฌ ์‚ฌ์šฉ์ž๊ฐ€ ํŒŒ์ผ์„ ์†Œ์œ ํ•˜๊ณ  ์žˆ๊ณ 
                        not self.whitelisted(path) # path๊ฐ€ ํ™”์ดํŠธ๋ฆฌ์ŠคํŠธ์ธ์ง€ ํ™•์ธ 
                    if ok:
                        yield Command.Delete(path) # path ์‚ญ์ œ
Example #14
0
    def get_commands(self, option_id):
        # cache
        if 'posix' == os.name and 'cache' == option_id:
            dirname = expanduser("~/.cache/")
            for filename in children_in_directory(dirname, True):
                if not self.whitelisted(filename):
                    yield Command.Delete(filename)

        # custom
        if 'custom' == option_id:
            for (c_type, c_path) in options.get_custom_paths():
                if 'file' == c_type:
                    yield Command.Delete(c_path)
                elif 'folder' == c_type:
                    yield Command.Delete(c_path)
                    for path in children_in_directory(c_path, True):
                        yield Command.Delete(path)
                else:
                    raise RuntimeError(
                        'custom folder has invalid type %s' % c_type)

        # menu
        menu_dirs = ['~/.local/share/applications',
                     '~/.config/autostart',
                     '~/.gnome/apps/',
                     '~/.gnome2/panel2.d/default/launchers',
                     '~/.gnome2/vfolders/applications/',
                     '~/.kde/share/apps/RecentDocuments/',
                     '~/.kde/share/mimelnk',
                     '~/.kde/share/mimelnk/application/ram.desktop',
                     '~/.kde2/share/mimelnk/application/',
                     '~/.kde2/share/applnk']

        if 'posix' == os.name and 'desktop_entry' == option_id:
            for dirname in menu_dirs:
                for filename in [fn for fn in children_in_directory(dirname, False)
                                 if fn.endswith('.desktop')]:
                    if Unix.is_broken_xdg_desktop(filename):
                        yield Command.Delete(filename)

        # unwanted locales
        if 'posix' == os.name and 'localizations' == option_id:
            for path in Unix.locales.localization_paths(locales_to_keep=options.get_languages()):
                if os.path.isdir(path):
                    for f in FileUtilities.children_in_directory(path, True):
                        yield Command.Delete(f)
                yield Command.Delete(path)

        # Windows logs
        if 'nt' == os.name and 'logs' == option_id:
            paths = (
                '$ALLUSERSPROFILE\\Application Data\\Microsoft\\Dr Watson\\*.log',
                '$ALLUSERSPROFILE\\Application Data\\Microsoft\\Dr Watson\\user.dmp',
                '$LocalAppData\\Microsoft\\Windows\\WER\\ReportArchive\\*\\*',
                '$LocalAppData\\Microsoft\\Windows\WER\\ReportQueue\\*\\*',
                '$programdata\\Microsoft\\Windows\\WER\\ReportArchive\\*\\*',
                '$programdata\\Microsoft\\Windows\\WER\\ReportQueue\\*\\*',
                '$localappdata\\Microsoft\\Internet Explorer\\brndlog.bak',
                '$localappdata\\Microsoft\\Internet Explorer\\brndlog.txt',
                '$windir\\*.log',
                '$windir\\imsins.BAK',
                '$windir\\OEWABLog.txt',
                '$windir\\SchedLgU.txt',
                '$windir\\ntbtlog.txt',
                '$windir\\setuplog.txt',
                '$windir\\REGLOCS.OLD',
                '$windir\\Debug\\*.log',
                '$windir\\Debug\\Setup\\UpdSh.log',
                '$windir\\Debug\\UserMode\\*.log',
                '$windir\\Debug\\UserMode\\ChkAcc.bak',
                '$windir\\Debug\\UserMode\\userenv.bak',
                '$windir\\Microsoft.NET\Framework\*\*.log',
                '$windir\\pchealth\\helpctr\\Logs\\hcupdate.log',
                '$windir\\security\\logs\\*.log',
                '$windir\\security\\logs\\*.old',
                '$windir\\SoftwareDistribution\\*.log',
                '$windir\\SoftwareDistribution\\DataStore\\Logs\\*',
                '$windir\\system32\\TZLog.log',
                '$windir\\system32\\config\\systemprofile\\Application Data\\Microsoft\\Internet Explorer\\brndlog.bak',
                '$windir\\system32\\config\\systemprofile\\Application Data\\Microsoft\\Internet Explorer\\brndlog.txt',
                '$windir\\system32\\LogFiles\\AIT\\AitEventLog.etl.???',
                '$windir\\system32\\LogFiles\\Firewall\\pfirewall.log*',
                '$windir\\system32\\LogFiles\\Scm\\SCM.EVM*',
                '$windir\\system32\\LogFiles\\WMI\\Terminal*.etl',
                '$windir\\system32\\LogFiles\\WMI\\RTBackup\EtwRT.*etl',
                '$windir\\system32\\wbem\\Logs\\*.lo_',
                '$windir\\system32\\wbem\\Logs\\*.log', )

            for path in paths:
                expanded = expandvars(path)
                for globbed in glob.iglob(expanded):
                    yield Command.Delete(globbed)

        # memory
        if sys.platform.startswith('linux') and 'memory' == option_id:
            yield Command.Function(None, Memory.wipe_memory, _('Memory'))

        # memory dump
        # how to manually create this file
        # http://www.pctools.com/guides/registry/detail/856/
        if 'nt' == os.name and 'memory_dump' == option_id:
            fname = expandvars('$windir\\memory.dmp')
            if os.path.exists(fname):
                yield Command.Delete(fname)
            for fname in glob.iglob(expandvars('$windir\\Minidump\\*.dmp')):
                yield Command.Delete(fname)

        # most recently used documents list
        if 'posix' == os.name and 'recent_documents' == option_id:
            ru_fn = expanduser("~/.recently-used")
            if os.path.lexists(ru_fn):
                yield Command.Delete(ru_fn)
            # GNOME 2.26 (as seen on Ubuntu 9.04) will retain the list
            # in memory if it is simply deleted, so it must be shredded
            # (or at least truncated).
            #
            # GNOME 2.28.1 (Ubuntu 9.10) and 2.30 (10.04) do not re-read
            # the file after truncation, but do re-read it after
            # shredding.
            #
            # https://bugzilla.gnome.org/show_bug.cgi?id=591404

            def gtk_purge_items():
                """Purge GTK items"""
                gtk.RecentManager().purge_items()
                yield 0

            for pathname in ["~/.recently-used.xbel", "~/.local/share/recently-used.xbel"]:
                pathname = expanduser(pathname)
                if os.path.lexists(pathname):
                    yield Command.Shred(pathname)
            if HAVE_GTK:
                # Use the Function to skip when in preview mode
                yield Command.Function(None, gtk_purge_items, _('Recent documents list'))

        if 'posix' == os.name and 'rotated_logs' == option_id:
            for path in Unix.rotated_logs():
                yield Command.Delete(path)

        # temporary files
        if 'posix' == os.name and 'tmp' == option_id:
            dirnames = ['/tmp', '/var/tmp']
            for dirname in dirnames:
                for path in children_in_directory(dirname, True):
                    is_open = FileUtilities.openfiles.is_open(path)
                    ok = not is_open and os.path.isfile(path) and \
                        not os.path.islink(path) and \
                        FileUtilities.ego_owner(path) and \
                        not self.whitelisted(path)
                    if ok:
                        yield Command.Delete(path)

        # temporary files
        if 'nt' == os.name and 'tmp' == option_id:
            dirname1 = expandvars(
                "$USERPROFILE\\Local Settings\\Temp\\")
            dirname2 = expandvars(r'%temp%')
            dirname3 = expandvars("%windir%\\temp\\")
            dirnames = []
            if Windows.get_windows_version() >= 6.0:
                # Windows Vista or later
                dirnames.append(dirname2)
            else:
                # Windows XP
                dirnames.append(dirname1)
            dirnames.append(dirname3)
            # whitelist the folder %TEMP%\Low but not its contents
            # https://bugs.launchpad.net/bleachbit/+bug/1421726
            for dirname in dirnames:
                low = os.path.join(dirname, 'low').lower()
                for filename in children_in_directory(dirname, True):
                    if not low == filename.lower():
                        yield Command.Delete(filename)

        # trash
        if 'posix' == os.name and 'trash' == option_id:
            dirname = expanduser("~/.Trash")
            for filename in children_in_directory(dirname, False):
                yield Command.Delete(filename)
            # fixme http://www.ramendik.ru/docs/trashspec.html
            # http://standards.freedesktop.org/basedir-spec/basedir-spec-0.6.html
            # ~/.local/share/Trash
            # * GNOME 2.22, Fedora 9
            # * KDE 4.1.3, Ubuntu 8.10
            dirname = expanduser("~/.local/share/Trash/files")
            for filename in children_in_directory(dirname, True):
                yield Command.Delete(filename)
            dirname = expanduser("~/.local/share/Trash/info")
            for filename in children_in_directory(dirname, True):
                yield Command.Delete(filename)
            dirname = expanduser("~/.local/share/Trash/expunged")
            # [email protected] tells me that the trash
            # backend puts files in here temporary, but in some situations
            # the files are stuck.
            for filename in children_in_directory(dirname, True):
                yield Command.Delete(filename)

        # clipboard
        if HAVE_GTK and 'clipboard' == option_id:
            def clear_clipboard():
                gtk.gdk.threads_enter()
                clipboard = gtk.clipboard_get()
                clipboard.set_text("")
                gtk.gdk.threads_leave()
                return 0
            yield Command.Function(None, clear_clipboard, _('Clipboard'))

        # overwrite free space
        shred_drives = options.get_list('shred_drives')
        if 'free_disk_space' == option_id and shred_drives:
            for pathname in shred_drives:
                # TRANSLATORS: 'Free' means 'unallocated.'
                # %s expands to a path such as C:\ or /tmp/
                display = _("Overwrite free disk space %s") % pathname

                def wipe_path_func():
                    for ret in FileUtilities.wipe_path(pathname, idle=True):
                        # Yield control to GTK idle because this process
                        # is very slow.  Also display progress.
                        yield ret
                    yield 0
                yield Command.Function(None, wipe_path_func, display)

        # MUICache
        if 'nt' == os.name and 'muicache' == option_id:
            keys = (
                'HKCU\\Software\\Microsoft\\Windows\\ShellNoRoam\\MUICache',
                'HKCU\\Software\\Classes\\Local Settings\\Software\\Microsoft\\Windows\\Shell\\MuiCache')
            for key in keys:
                yield Command.Winreg(key, None)

        # prefetch
        if 'nt' == os.name and 'prefetch' == option_id:
            for path in glob.iglob(expandvars('$windir\\Prefetch\\*.pf')):
                yield Command.Delete(path)

        # recycle bin
        if 'nt' == os.name and 'recycle_bin' == option_id:
            # This method allows shredding
            recycled_any = False
            for path in Windows.get_recycle_bin():
                recycled_any = True
                yield Command.Delete(path)
            # If there were any files deleted, Windows XP will show the
            # wrong icon for the recycle bin indicating it is not empty.
            # The icon will be incorrect until logging in to Windows again
            # or until it is emptied using the Windows API call for emptying
            # the recycle bin.

            # Windows 10 refreshes the recycle bin icon when the user
            # opens the recycle bin folder.

            # This is a hack to refresh the icon.
            def empty_recycle_bin_func():
                import tempfile
                tmpdir = tempfile.mkdtemp()
                Windows.move_to_recycle_bin(tmpdir)
                try:
                    Windows.empty_recycle_bin(None, True)
                except:
                    logging.getLogger(__name__).info('error in empty_recycle_bin()', exc_info=True)
                yield 0
            # Using the Function Command prevents emptying the recycle bin
            # when in preview mode.
            if recycled_any:
                yield Command.Function(None, empty_recycle_bin_func, _('Empty the recycle bin'))

        # Windows Updates
        if 'nt' == os.name and 'updates' == option_id:
            for wu in Windows.delete_updates():
                yield wu
Example #15
0
    def get_commands(self, option_id):
        # cache
        if 'posix' == os.name and 'cache' == option_id:
            dirname = expanduser("~/.cache/")
            for filename in children_in_directory(dirname, True):
                if not self.whitelisted(filename):
                    yield Command.Delete(filename)

        # custom
        if 'custom' == option_id:
            for (c_type, c_path) in options.get_custom_paths():
                if 'file' == c_type:
                    yield Command.Delete(c_path)
                elif 'folder' == c_type:
                    yield Command.Delete(c_path)
                    for path in children_in_directory(c_path, True):
                        yield Command.Delete(path)
                else:
                    raise RuntimeError('custom folder has invalid type %s' %
                                       c_type)

        # menu
        menu_dirs = [
            '~/.local/share/applications', '~/.config/autostart',
            '~/.gnome/apps/', '~/.gnome2/panel2.d/default/launchers',
            '~/.gnome2/vfolders/applications/',
            '~/.kde/share/apps/RecentDocuments/', '~/.kde/share/mimelnk',
            '~/.kde/share/mimelnk/application/ram.desktop',
            '~/.kde2/share/mimelnk/application/', '~/.kde2/share/applnk'
        ]

        if 'posix' == os.name and 'desktop_entry' == option_id:
            for dirname in menu_dirs:
                for filename in [
                        fn for fn in children_in_directory(dirname, False)
                        if fn.endswith('.desktop')
                ]:
                    if Unix.is_broken_xdg_desktop(filename):
                        yield Command.Delete(filename)

        # unwanted locales
        if 'posix' == os.name and 'localizations' == option_id:
            for path in Unix.locales.localization_paths(
                    locales_to_keep=options.get_languages()):
                if os.path.isdir(path):
                    for f in FileUtilities.children_in_directory(path, True):
                        yield Command.Delete(f)
                yield Command.Delete(path)

        # Windows logs
        if 'nt' == os.name and 'logs' == option_id:
            paths = (
                '$ALLUSERSPROFILE\\Application Data\\Microsoft\\Dr Watson\\*.log',
                '$ALLUSERSPROFILE\\Application Data\\Microsoft\\Dr Watson\\user.dmp',
                '$LocalAppData\\Microsoft\\Windows\\WER\\ReportArchive\\*\\*',
                '$LocalAppData\\Microsoft\\Windows\WER\\ReportQueue\\*\\*',
                '$programdata\\Microsoft\\Windows\\WER\\ReportArchive\\*\\*',
                '$programdata\\Microsoft\\Windows\\WER\\ReportQueue\\*\\*',
                '$localappdata\\Microsoft\\Internet Explorer\\brndlog.bak',
                '$localappdata\\Microsoft\\Internet Explorer\\brndlog.txt',
                '$windir\\*.log',
                '$windir\\imsins.BAK',
                '$windir\\OEWABLog.txt',
                '$windir\\SchedLgU.txt',
                '$windir\\ntbtlog.txt',
                '$windir\\setuplog.txt',
                '$windir\\REGLOCS.OLD',
                '$windir\\Debug\\*.log',
                '$windir\\Debug\\Setup\\UpdSh.log',
                '$windir\\Debug\\UserMode\\*.log',
                '$windir\\Debug\\UserMode\\ChkAcc.bak',
                '$windir\\Debug\\UserMode\\userenv.bak',
                '$windir\\Microsoft.NET\Framework\*\*.log',
                '$windir\\pchealth\\helpctr\\Logs\\hcupdate.log',
                '$windir\\security\\logs\\*.log',
                '$windir\\security\\logs\\*.old',
                '$windir\\SoftwareDistribution\\*.log',
                '$windir\\SoftwareDistribution\\DataStore\\Logs\\*',
                '$windir\\system32\\TZLog.log',
                '$windir\\system32\\config\\systemprofile\\Application Data\\Microsoft\\Internet Explorer\\brndlog.bak',
                '$windir\\system32\\config\\systemprofile\\Application Data\\Microsoft\\Internet Explorer\\brndlog.txt',
                '$windir\\system32\\LogFiles\\AIT\\AitEventLog.etl.???',
                '$windir\\system32\\LogFiles\\Firewall\\pfirewall.log*',
                '$windir\\system32\\LogFiles\\Scm\\SCM.EVM*',
                '$windir\\system32\\LogFiles\\WMI\\Terminal*.etl',
                '$windir\\system32\\LogFiles\\WMI\\RTBackup\EtwRT.*etl',
                '$windir\\system32\\wbem\\Logs\\*.lo_',
                '$windir\\system32\\wbem\\Logs\\*.log',
            )

            for path in paths:
                expanded = expandvars(path)
                for globbed in glob.iglob(expanded):
                    yield Command.Delete(globbed)

        # memory
        if sys.platform.startswith('linux') and 'memory' == option_id:
            yield Command.Function(None, Memory.wipe_memory, _('Memory'))

        # memory dump
        # how to manually create this file
        # http://www.pctools.com/guides/registry/detail/856/
        if 'nt' == os.name and 'memory_dump' == option_id:
            fname = expandvars('$windir\\memory.dmp')
            if os.path.exists(fname):
                yield Command.Delete(fname)
            for fname in glob.iglob(expandvars('$windir\\Minidump\\*.dmp')):
                yield Command.Delete(fname)

        # most recently used documents list
        if 'posix' == os.name and 'recent_documents' == option_id:
            ru_fn = expanduser("~/.recently-used")
            if os.path.lexists(ru_fn):
                yield Command.Delete(ru_fn)
            # GNOME 2.26 (as seen on Ubuntu 9.04) will retain the list
            # in memory if it is simply deleted, so it must be shredded
            # (or at least truncated).
            #
            # GNOME 2.28.1 (Ubuntu 9.10) and 2.30 (10.04) do not re-read
            # the file after truncation, but do re-read it after
            # shredding.
            #
            # https://bugzilla.gnome.org/show_bug.cgi?id=591404

            def gtk_purge_items():
                """Purge GTK items"""
                gtk.RecentManager().purge_items()
                yield 0

            for pathname in [
                    "~/.recently-used.xbel",
                    "~/.local/share/recently-used.xbel"
            ]:
                pathname = expanduser(pathname)
                if os.path.lexists(pathname):
                    yield Command.Shred(pathname)
            if HAVE_GTK:
                # Use the Function to skip when in preview mode
                yield Command.Function(None, gtk_purge_items,
                                       _('Recent documents list'))

        if 'posix' == os.name and 'rotated_logs' == option_id:
            for path in Unix.rotated_logs():
                yield Command.Delete(path)

        # temporary files
        if 'posix' == os.name and 'tmp' == option_id:
            dirnames = ['/tmp', '/var/tmp']
            for dirname in dirnames:
                for path in children_in_directory(dirname, True):
                    is_open = FileUtilities.openfiles.is_open(path)
                    ok = not is_open and os.path.isfile(path) and \
                        not os.path.islink(path) and \
                        FileUtilities.ego_owner(path) and \
                        not self.whitelisted(path)
                    if ok:
                        yield Command.Delete(path)

        # temporary files
        if 'nt' == os.name and 'tmp' == option_id:
            dirname1 = expandvars("$USERPROFILE\\Local Settings\\Temp\\")
            dirname2 = expandvars(r'%temp%')
            dirname3 = expandvars("%windir%\\temp\\")
            dirnames = []
            if Windows.get_windows_version() >= 6.0:
                # Windows Vista or later
                dirnames.append(dirname2)
            else:
                # Windows XP
                dirnames.append(dirname1)
            dirnames.append(dirname3)
            # whitelist the folder %TEMP%\Low but not its contents
            # https://bugs.launchpad.net/bleachbit/+bug/1421726
            for dirname in dirnames:
                low = os.path.join(dirname, 'low').lower()
                for filename in children_in_directory(dirname, True):
                    if not low == filename.lower():
                        yield Command.Delete(filename)

        # trash
        if 'posix' == os.name and 'trash' == option_id:
            dirname = expanduser("~/.Trash")
            for filename in children_in_directory(dirname, False):
                yield Command.Delete(filename)
            # fixme http://www.ramendik.ru/docs/trashspec.html
            # http://standards.freedesktop.org/basedir-spec/basedir-spec-0.6.html
            # ~/.local/share/Trash
            # * GNOME 2.22, Fedora 9
            # * KDE 4.1.3, Ubuntu 8.10
            dirname = expanduser("~/.local/share/Trash/files")
            for filename in children_in_directory(dirname, True):
                yield Command.Delete(filename)
            dirname = expanduser("~/.local/share/Trash/info")
            for filename in children_in_directory(dirname, True):
                yield Command.Delete(filename)
            dirname = expanduser("~/.local/share/Trash/expunged")
            # [email protected] tells me that the trash
            # backend puts files in here temporary, but in some situations
            # the files are stuck.
            for filename in children_in_directory(dirname, True):
                yield Command.Delete(filename)

        # clipboard
        if HAVE_GTK and 'clipboard' == option_id:

            def clear_clipboard():
                gtk.gdk.threads_enter()
                clipboard = gtk.clipboard_get()
                clipboard.set_text("")
                gtk.gdk.threads_leave()
                return 0

            yield Command.Function(None, clear_clipboard, _('Clipboard'))

        # overwrite free space
        shred_drives = options.get_list('shred_drives')
        if 'free_disk_space' == option_id and shred_drives:
            for pathname in shred_drives:
                # TRANSLATORS: 'Free' means 'unallocated.'
                # %s expands to a path such as C:\ or /tmp/
                display = _("Overwrite free disk space %s") % pathname

                def wipe_path_func():
                    for ret in FileUtilities.wipe_path(pathname, idle=True):
                        # Yield control to GTK idle because this process
                        # is very slow.  Also display progress.
                        yield ret
                    yield 0

                yield Command.Function(None, wipe_path_func, display)

        # MUICache
        if 'nt' == os.name and 'muicache' == option_id:
            keys = (
                'HKCU\\Software\\Microsoft\\Windows\\ShellNoRoam\\MUICache',
                'HKCU\\Software\\Classes\\Local Settings\\Software\\Microsoft\\Windows\\Shell\\MuiCache'
            )
            for key in keys:
                yield Command.Winreg(key, None)

        # prefetch
        if 'nt' == os.name and 'prefetch' == option_id:
            for path in glob.iglob(expandvars('$windir\\Prefetch\\*.pf')):
                yield Command.Delete(path)

        # recycle bin
        if 'nt' == os.name and 'recycle_bin' == option_id:
            # This method allows shredding
            recycled_any = False
            for path in Windows.get_recycle_bin():
                recycled_any = True
                yield Command.Delete(path)
            # If there were any files deleted, Windows XP will show the
            # wrong icon for the recycle bin indicating it is not empty.
            # The icon will be incorrect until logging in to Windows again
            # or until it is emptied using the Windows API call for emptying
            # the recycle bin.

            # Windows 10 refreshes the recycle bin icon when the user
            # opens the recycle bin folder.

            # This is a hack to refresh the icon.
            def empty_recycle_bin_func():
                import tempfile
                tmpdir = tempfile.mkdtemp()
                Windows.move_to_recycle_bin(tmpdir)
                try:
                    Windows.empty_recycle_bin(None, True)
                except:
                    logging.getLogger(__name__).info(
                        'error in empty_recycle_bin()', exc_info=True)
                yield 0

            # Using the Function Command prevents emptying the recycle bin
            # when in preview mode.
            if recycled_any:
                yield Command.Function(None, empty_recycle_bin_func,
                                       _('Empty the recycle bin'))

        # Windows Updates
        if 'nt' == os.name and 'updates' == option_id:
            for wu in Windows.delete_updates():
                yield wu
Example #16
0
 def get_walk_files(top):
     """Delete files inside a directory but not any directories"""
     for expanded in glob.iglob(top):
         for path in FileUtilities.children_in_directory(
                 expanded, False):
             yield path
Example #17
0
 def get_walk_files(top):
     for expanded in glob.iglob(top):
         for path in FileUtilities.children_in_directory(expanded, False):
             yield path
Example #18
0
 def get_walk_files(top):
     """Delete files inside a directory but not any directories"""
     for expanded in glob.iglob(top):
         for path in FileUtilities.children_in_directory(expanded, False):
             yield path