Exemplo n.º 1
0
 def check_online_updates(self):
     """Check for software updates in background"""
     from bleachbit import Update
     try:
         updates = Update.check_updates(
             options.get('check_beta'), options.get('update_winapp2'),
             self.append_text,
             lambda: GLib.idle_add(self.cb_refresh_operations))
         if updates:
             GLib.idle_add(lambda: Update.update_dialog(self, updates))
     except Exception:
         logger.exception(_("Error when checking for updates: "))
Exemplo n.º 2
0
 def check_online_updates(self):
     """Check for software updates in background"""
     from bleachbit import Update
     try:
         updates = Update.check_updates(options.get('check_beta'),
                                        options.get('update_winapp2'),
                                        self.append_text,
                                        lambda: gobject.idle_add(self.cb_refresh_operations))
         if updates:
             gobject.idle_add(
                 lambda: Update.update_dialog(self.window, updates))
     except Exception:
         logger.exception(_("Error when checking for updates: "))
Exemplo n.º 3
0
def process_cmd_line():
    """Parse the command line and execute given commands."""
    # TRANSLATORS: This is the command line usage.  Don't translate
    # %prog, but do translate usage, options, cleaner, and option.
    # More information about the command line is here
    # https://www.bleachbit.org/documentation/command-line
    usage = _("usage: %prog [options] cleaner.option1 cleaner.option2")
    parser = optparse.OptionParser(usage)
    parser.add_option("-l",
                      "--list-cleaners",
                      action="store_true",
                      help=_("list cleaners"))
    parser.add_option(
        "-c",
        "--clean",
        action="store_true",
        # TRANSLATORS: predefined cleaners are for applications, such as Firefox and Flash.
        # This is different than cleaning an arbitrary file, such as a
        # spreadsheet on the desktop.
        help=_(
            "run cleaners to delete files and make other permanent changes"))
    parser.add_option('--debug-log', help='log debug messages to file')
    parser.add_option("-s",
                      "--shred",
                      action="store_true",
                      help=_("shred specific files or folders"))
    parser.add_option("--sysinfo",
                      action="store_true",
                      help=_("show system information"))
    parser.add_option("--gui",
                      action="store_true",
                      help=_("launch the graphical interface"))
    parser.add_option('--exit',
                      action='store_true',
                      help=optparse.SUPPRESS_HELP)
    if 'nt' == os.name:
        uac_help = _("do not prompt for administrator privileges")
    else:
        uac_help = optparse.SUPPRESS_HELP
    parser.add_option("--no-uac", action="store_true", help=uac_help)
    parser.add_option("-p",
                      "--preview",
                      action="store_true",
                      help=_("preview files to be deleted and other changes"))
    parser.add_option('--pot',
                      action='store_true',
                      help=optparse.SUPPRESS_HELP)
    parser.add_option("--preset",
                      action="store_true",
                      help=_("use options set in the graphical interface"))
    if 'nt' == os.name:
        parser.add_option(
            "--update-winapp2",
            action="store_true",
            help=_("update winapp2.ini, if a new version is available"))
    parser.add_option("-w",
                      "--wipe-free-space",
                      action="store_true",
                      help=_("wipe free space in the given paths"))
    parser.add_option("-v",
                      "--version",
                      action="store_true",
                      help=_("output version information and exit"))
    parser.add_option('-o',
                      '--overwrite',
                      action='store_true',
                      help=_('overwrite files to hide contents'))
    (options, args) = parser.parse_args()

    cmd_list = (options.list_cleaners, options.wipe_free_space,
                options.preview, options.clean)
    cmd_count = sum(x is True for x in cmd_list)
    if cmd_count > 1:
        logger.error(
            _('Specify only one of these commands: --list-cleaners, --wipe-free-space, --preview, --cleaner'
              ))
        sys.exit(1)

    did_something = False
    if options.debug_log:
        logger.addHandler(logging.FileHandler(options.debug_log))
        logger.info('BleachBit version %s', APP_VERSION)
        logger.info(Diagnostic.diagnostic_info())
    if options.version:
        print("""
BleachBit version %s
Copyright (C) 2008-2018 Andrew Ziem.  All rights reserved.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.""" % APP_VERSION)
        sys.exit(0)
    if 'nt' == os.name and options.update_winapp2:
        from bleachbit import Update
        logger.info("Checking online for updates to winapp2.ini")
        Update.check_updates(False, True,
                             lambda x: sys.stdout.write("%s\n" % x),
                             lambda: None)
        # updates can be combined with --list-cleaners, --preview, --clean
        did_something = True
    if options.list_cleaners:
        list_cleaners()
        sys.exit(0)
    if options.pot:
        from bleachbit.CleanerML import create_pot
        create_pot()
        sys.exit(0)
    if options.wipe_free_space:
        if len(args) < 1:
            logger.error('No directories given for --wipe-free-space')
            sys.exit(1)
        for wipe_path in args:
            if not os.path.isdir(wipe_path):
                logger.error('Path to wipe must be an existing directory: %s',
                             wipe_path)
                sys.exit(1)
        logger.info('Wiping free space can take a long time.')
        for wipe_path in args:
            logger.info('Wiping free space in path: %s', wipe_path)
            import bleachbit.FileUtilities
            for ret in bleachbit.FileUtilities.wipe_path(wipe_path):
                pass
        sys.exit(0)
    if options.preview or options.clean:
        operations = args_to_operations(args, options.preset)
        if not operations:
            logger.error('No work to do. Specify options.')
            sys.exit(1)
    if options.preview:
        preview_or_clean(operations, False)
        sys.exit(0)
    if options.overwrite:
        if not options.clean or options.shred:
            logger.warning('--overwrite is intended only for use with --clean')
        Options.options.set('shred', True, commit=False)
    if options.clean:
        preview_or_clean(operations, True)
        sys.exit(0)
    if options.gui:
        import gtk
        from bleachbit import GUI
        shred_paths = args if options.shred else None
        GUI.GUI(uac=not options.no_uac,
                shred_paths=shred_paths,
                exit=options.exit)
        gtk.main()
        if options.exit:
            # For automated testing of Windows build
            print('Success')
        sys.exit(0)
    if options.shred:
        # delete arbitrary files without GUI
        # create a temporary cleaner object
        backends['_gui'] = create_simple_cleaner(args)
        operations = {'_gui': ['files']}
        preview_or_clean(operations, True)
        sys.exit(0)
    if options.sysinfo:
        print(Diagnostic.diagnostic_info())
        sys.exit(0)
    if not did_something:
        parser.print_help()
Exemplo n.º 4
0
def process_cmd_line():
    """Parse the command line and execute given commands."""
    # TRANSLATORS: This is the command line usage.  Don't translate
    # %prog, but do translate usage, options, cleaner, and option.
    # More information about the command line is here
    # https://www.bleachbit.org/documentation/command-line
    usage = _("usage: %prog [options] cleaner.option1 cleaner.option2")
    parser = optparse.OptionParser(usage)
    parser.add_option("-l", "--list-cleaners", action="store_true",
                      help=_("list cleaners"))
    parser.add_option("-c", "--clean", action="store_true",
                      # TRANSLATORS: predefined cleaners are for applications, such as Firefox and Flash.
                      # This is different than cleaning an arbitrary file, such as a
                      # spreadsheet on the desktop.
                      help=_("run cleaners to delete files and make other permanent changes"))
    parser.add_option('--debug-log', help='log debug messages to file')
    parser.add_option("-s", "--shred", action="store_true",
                      help=_("shred specific files or folders"))
    parser.add_option("--sysinfo", action="store_true",
                      help=_("show system information"))
    parser.add_option("--gui", action="store_true",
                      help=_("launch the graphical interface"))
    parser.add_option('--exit', action='store_true',
                      help=optparse.SUPPRESS_HELP)
    if 'nt' == os.name:
        uac_help = _("do not prompt for administrator privileges")
    else:
        uac_help = optparse.SUPPRESS_HELP
    parser.add_option("--no-uac", action="store_true", help=uac_help)
    parser.add_option("-p", "--preview", action="store_true",
                      help=_("preview files to be deleted and other changes"))
    parser.add_option('--pot', action='store_true',
                      help=optparse.SUPPRESS_HELP)
    parser.add_option("--preset", action="store_true",
                      help=_("use options set in the graphical interface"))
    if 'nt' == os.name:
        parser.add_option("--update-winapp2", action="store_true",
                          help=_("update winapp2.ini, if a new version is available"))
    parser.add_option("-v", "--version", action="store_true",
                      help=_("output version information and exit"))
    parser.add_option('-o', '--overwrite', action='store_true',
                      help=_('overwrite files to hide contents'))
    (options, args) = parser.parse_args()
    did_something = False
    if options.debug_log:
        logger.addHandler(logging.FileHandler(options.debug_log))
        logger.info('BleachBit version %s', APP_VERSION)
        logger.info(Diagnostic.diagnostic_info())
    if options.version:
        print("""
BleachBit version %s
Copyright (C) 2008-2017 Andrew Ziem.  All rights reserved.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.""" % APP_VERSION)
        sys.exit(0)
    if 'nt' == os.name and options.update_winapp2:
        from bleachbit import Update
        logger.info("Checking online for updates to winapp2.ini")
        Update.check_updates(False, True,
                             lambda x: sys.stdout.write("%s\n" % x),
                             lambda: None)
        # updates can be combined with --list, --preview, --clean
        did_something = True
    if options.list_cleaners:
        list_cleaners()
        sys.exit(0)
    if options.pot:
        from bleachbit.CleanerML import create_pot
        create_pot()
        sys.exit(0)
    if options.preview or options.clean:
        operations = args_to_operations(args, options.preset)
        if not operations:
            logger.error('No work to do. Specify options.')
            sys.exit(1)
    if options.preview:
        preview_or_clean(operations, False)
        sys.exit(0)
    if options.overwrite:
        if not options.clean or options.shred:
            logger.warning('--overwrite is intended only for use with --clean')
        Options.options.set('shred', True, commit=False)
    if options.clean:
        preview_or_clean(operations, True)
        sys.exit(0)
    if options.gui:
        import gtk
        from bleachbit import GUI
        shred_paths = args if options.shred else None
        GUI.GUI(uac=not options.no_uac,
                shred_paths=shred_paths, exit=options.exit)
        gtk.main()
        if options.exit:
            # For automated testing of Windows build
            print('Success')
        sys.exit(0)
    if options.shred:
        # delete arbitrary files without GUI
        # create a temporary cleaner object
        backends['_gui'] = create_simple_cleaner(args)
        operations = {'_gui': ['files']}
        preview_or_clean(operations, True)
        sys.exit(0)
    if options.sysinfo:
        print(Diagnostic.diagnostic_info())
        sys.exit(0)
    if not did_something:
        parser.print_help()