Exemple #1
0
 def diagnostic_dialog(self, parent):
     """Show diagnostic information"""
     dialog = gtk.Dialog(_("System information"), parent)
     dialog.resize(600, 400)
     txtbuffer = gtk.TextBuffer()
     from bleachbit import Diagnostic
     txt = Diagnostic.diagnostic_info()
     txtbuffer.set_text(txt)
     textview = gtk.TextView(txtbuffer)
     textview.set_editable(False)
     swindow = gtk.ScrolledWindow()
     swindow.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
     swindow.add_with_viewport(textview)
     dialog.vbox.pack_start(swindow)
     dialog.add_buttons(gtk.STOCK_COPY, 100, gtk.STOCK_CLOSE,
                        gtk.RESPONSE_CLOSE)
     dialog.show_all()
     while True:
         rc = dialog.run()
         if 100 == rc:
             clipboard = gtk.clipboard_get()
             clipboard.set_text(txt)
         else:
             break
     dialog.hide()
Exemple #2
0
 def diagnostic_dialog(self, _action, _param):
     """Show diagnostic information"""
     dialog = Gtk.Dialog(_("System information"), self._window)
     dialog.set_default_size(600, 400)
     txtbuffer = Gtk.TextBuffer()
     from bleachbit import Diagnostic
     txt = Diagnostic.diagnostic_info()
     txtbuffer.set_text(txt)
     textview = Gtk.TextView.new_with_buffer(txtbuffer)
     textview.set_editable(False)
     swindow = Gtk.ScrolledWindow()
     swindow.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
     swindow.add_with_viewport(textview)
     dialog.vbox.pack_start(swindow, True, True, 0)
     dialog.add_buttons(Gtk.STOCK_COPY, 100,
                        Gtk.STOCK_CLOSE, Gtk.ResponseType.CLOSE)
     dialog.show_all()
     while True:
         rc = dialog.run()
         if rc == 100:
             clipboard = Gtk.Clipboard.get(Gdk.SELECTION_CLIPBOARD)
             clipboard.set_text(txt, -1)
         else:
             break
     dialog.hide()
Exemple #3
0
 def diagnostic_dialog(self, parent):
     """Show diagnostic information"""
     dialog = gtk.Dialog(_("System information"), parent)
     dialog.resize(600, 400)
     txtbuffer = gtk.TextBuffer()
     from bleachbit import Diagnostic
     txt = Diagnostic.diagnostic_info()
     txtbuffer.set_text(txt)
     textview = gtk.TextView(txtbuffer)
     textview.set_editable(False)
     swindow = gtk.ScrolledWindow()
     swindow.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
     swindow.add_with_viewport(textview)
     dialog.vbox.pack_start(swindow)
     dialog.add_buttons(
         gtk.STOCK_COPY, 100, gtk.STOCK_CLOSE, gtk.RESPONSE_CLOSE)
     dialog.show_all()
     while True:
         rc = dialog.run()
         if 100 == rc:
             clipboard = gtk.clipboard_get()
             clipboard.set_text(txt)
         else:
             break
     dialog.hide()
Exemple #4
0
 def get_diagnostics_dialog(self):
     """Show diagnostic information"""
     dialog = Gtk.Dialog(_("System information"), self._window)
     dialog.set_default_size(600, 400)
     txtbuffer = Gtk.TextBuffer()
     from bleachbit import Diagnostic
     txt = Diagnostic.diagnostic_info()
     txtbuffer.set_text(txt)
     textview = Gtk.TextView.new_with_buffer(txtbuffer)
     textview.set_editable(False)
     swindow = Gtk.ScrolledWindow()
     swindow.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
     swindow.add(textview)
     dialog.vbox.pack_start(swindow, True, True, 0)
     dialog.add_buttons(Gtk.STOCK_COPY, 100,
                        Gtk.STOCK_CLOSE, Gtk.ResponseType.CLOSE)
     return (dialog, txt)
Exemple #5
0
 def diagnostic_dialog(self, action, param):
     """Show diagnostic information"""
     dialog = Gtk.Dialog(_("System information"))
     dialog.set_default_size(600, 400)
     txtbuffer = Gtk.TextBuffer()
     from bleachbit import Diagnostic
     txt = Diagnostic.diagnostic_info()
     txtbuffer.set_text(txt)
     textview = Gtk.TextView.new_with_buffer(txtbuffer)
     textview.set_editable(False)
     swindow = Gtk.ScrolledWindow()
     swindow.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
     swindow.add_with_viewport(textview)
     dialog.vbox.pack_start(swindow, True, True, 0)
     dialog.add_buttons(Gtk.STOCK_COPY, 100, Gtk.STOCK_CLOSE, Gtk.ResponseType.CLOSE)
     dialog.show_all()
     while True:
         rc = dialog.run()
         if 100 == rc:
             clipboard = Gtk.Clipboard.get(Gdk.SELECTION_CLIPBOARD)
             clipboard.set_text(txt, -1)
         else:
             break
     dialog.hide()
Exemple #6
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()
Exemple #7
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()