Exemple #1
0
def init_configuration():
    """Initialize an empty configuration, if necessary"""
    if not os.path.exists(bleachbit.options_dir):
        General.makedirs(bleachbit.options_dir)
    if os.path.lexists(bleachbit.options_file):
        logger.debug('Deleting configuration: %s ' % bleachbit.options_file)
        os.remove(bleachbit.options_file)
    with open(bleachbit.options_file, 'w', encoding='utf-8-sig') as f_ini:
        f_ini.write('[bleachbit]\n')
        if os.name == 'nt' and bleachbit.portable_mode:
            f_ini.write('[Portable]\n')
    for section in options.config.sections():
        options.config.remove_section(section)
    options.restore()
Exemple #2
0
 def __flush(self):
     """Write information to disk"""
     if not self.purged:
         self.__purge()
     if not os.path.exists(bleachbit.options_dir):
         General.makedirs(bleachbit.options_dir)
     mkfile = not os.path.exists(bleachbit.options_file)
     _file = open(bleachbit.options_file, 'wb')
     try:
         self.config.write(_file)
     except IOError as e:
         print(e)
         from errno import ENOSPC
         if e.errno == ENOSPC:
             logger.error("disk is full writing configuration '%s'", bleachbit.options_file)
         else:
             raise
     if mkfile and General.sudo_mode():
         General.chownself(bleachbit.options_file)
Exemple #3
0
 def __flush(self):
    
     if not self.purged:
         self.__purge()
     if not os.path.exists(bleachbit.options_dir):
         General.makedirs(bleachbit.options_dir)
     mkfile = not os.path.exists(bleachbit.options_file)
     _file = open(bleachbit.options_file, 'wb')
     try:
         self.config.write(_file)
     except IOError as e:
         print(e)
         from errno import ENOSPC
         if e.errno == ENOSPC:
             logger.error("disk is full writing configuration '%s'", bleachbit.options_file)
         else:
             raise
     if mkfile and General.sudo_mode():
         General.chownself(bleachbit.options_file)
Exemple #4
0
 def __flush(self):
     """Write information to disk"""
     if not self.purged:
         self.__purge()
     if not os.path.exists(bleachbit.options_dir):
         General.makedirs(bleachbit.options_dir)
     mkfile = not os.path.exists(bleachbit.options_file)
     with open(bleachbit.options_file, 'w', encoding='utf-8-sig') as _file:
         try:
             self.config.write(_file)
         except IOError as e:
             from errno import ENOSPC
             if e.errno == ENOSPC:
                 logger.error(
                     _("Disk was full when writing configuration to file %s"), bleachbit.options_file)
             else:
                 raise
     if mkfile and General.sudo_mode():
         General.chownself(bleachbit.options_file)
Exemple #5
0
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)
Exemple #6
0
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)