123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167 |
- #!/usr/bin/env python3
- # uruk cleaner
- # to clean your system
- # Copyright (c) 2016, 2022 ali miracle <alimiracle@riseup.net>
- # This Program is free software: you can redistribute it and/or modify
- # it under the terms of the GNU General Public License as published by
- # the Free Software Foundation, either version 3 of the License, or
- # (at your option) any later version.
- # This Program is distributed in the hope that it will be useful,
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- # GNU General Public License for more details.
- # You should have received a copy of the GNU General Public License
- # along with this program. If not, see <http://www.gnu.org/licenses/>.
- import gi
- gi.require_version("Gtk", "3.0")
- from gi.repository import Gtk
- gi.require_version('Gdk', '3.0')
- from gi.repository import Gdk
- import dbus
- from _dbus_bindings import BUS_DAEMON_IFACE, BUS_DAEMON_NAME, BUS_DAEMON_PATH
- import os
- class Cleaner:
- def __init__(self):
- timeout = 60
- flags = 0
- bus_name = "org.dbus.ucleaner"
- opath = "/org/ucleaner"
- #get the system bus
- bus = dbus.SystemBus()
- bus.call_blocking(BUS_DAEMON_NAME, BUS_DAEMON_PATH, BUS_DAEMON_IFACE,'StartServiceByName', 'su', (bus_name, flags), timeout=timeout)
- #get the object
- dbus_object = bus.get_object(bus_name, opath)
- #get the interface
- self.dbus_interface = dbus.Interface(dbus_object, "org.ucleaner")
- def clean_apt_cach(self):
- self.dbus_interface.clean_apt_cache()
- def clean_logs(self):
- self.dbus_interface.clean_logs()
- def remove_unused_pkgs(self):
- self.dbus_interface.remove_unused_packages()
- def remove_thumbnails(self):
- os.system("rm -rf ~/.cache/thumbnails/*")
- def clean_firefox_cach(self):
- os.system("rm ~/.mozilla/firefox/*.default*/*.sqlite ~/.mozilla/firefox/*default*/sessionstore.js")
- os.system("rm -r ~/.cache/mozilla/firefox/*.default*/*")
- class MessageBox:
- def __init__(self,message_title,message_content):
- self.__load_css()
- self.__init_builder()
- self.__extract_widget()
- self.set_content(message_content)
- self.set_title(message_title)
- def set_title(self,title):
- self.title_label.set_text(title)
- def set_content(self,content):
- self.content_label.set_text(content)
- pass
- def __init_builder(self):
- self.gladefile = "/usr/share/uruk-cleaner/messagebox.glade"
- self.builder = Gtk.Builder()
- try:
- self.builder.add_from_file(self.gladefile)
- except:
- print("Cant find The glade File", file = sys.stderr)
- exit(1)
- self.builder.connect_signals(self)
- def __extract_widget(self):
- self.window = self.builder.get_object("TopWindow")
- self.title_label = self.builder.get_object("TitleLabel")
- self.content_label = self.builder.get_object("MessageLabel")
- def show(self):
- self.window.show()
- def __load_css(self):
- screen = Gdk.Screen.get_default()
- provider = Gtk.CssProvider()
- provider.load_from_path("/usr/share/uruk-cleaner/messagebox.css")
- Gtk.StyleContext.add_provider_for_screen(screen, provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION)
- def ok_btn_click(self, *args):
- self.window.close()
- class GUI:
- IsWindowMaximized=False
- def __init__(self):
- self.__lode_css()
- self.cleaner=Cleaner()
- self.__init_builder()
- self.show_windo()
- def __lode_css(self):
- screen = Gdk.Screen.get_default()
- provider = Gtk.CssProvider()
- try:
- provider.load_from_path("/usr/share/uruk-cleaner/cleaner.css")
- except:
- print("Cant find The CSS File", file = sys.stderr)
- exit(1)
- Gtk.StyleContext.add_provider_for_screen(screen, provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION)
- def __init_builder(self):
- self.gladefile = "/usr/share/uruk-cleaner/cleaner.glade"
- self.builder = Gtk.Builder()
- try:
- self.builder.add_from_file(self.gladefile)
- except:
- print("Cant find The glade File", file = sys.stderr)
- exit(1)
- self.builder.connect_signals(self)
- def show_windo(self):
- self.window = self.builder.get_object("TopWindow")
- self.window.show()
- def maximize(self, button):
- if IsWindowMaximized:
- Gtk.Window.normlize(self.window)
- IsWindowMaximized=False
- return
- Gtk.Window.maximize(self.window)
- def minimize(self, button):
- Gtk.Window.minimize(self.window)
- def close(self, *args):
- Gtk.main_quit()
- exit(0)
- def about(self, button):
- MessageBox("About", "Free and Open Source System Cleaner \nto Clean and remove unnecessary files on\n your system \n \nby ali miracle <alimiracle@riseup.net>").show()
- def Clean(self, button):
- if self.builder.get_object("AptCacheChk").get_active():
- self.cleaner.clean_apt_cach()
- if self.builder.get_object("LogsChk").get_active():
- self.cleaner.clean_logs()
- if self.builder.get_object("UnUsedPkgsChk").get_active():
- self.cleaner.remove_unused_pkgs()
- if self.builder.get_object("ThumbnailsChk").get_active():
- self.cleaner.remove_thumbnails()
- if self.builder.get_object("FireFoxChk").get_active():
- self.cleaner.clean_firefox_cach()
- status = self.builder.get_object("AptCacheChk").get_active() or self.builder.get_object("LogsChk").get_active() or self.builder.get_object("UnUsedPkgsChk").get_active() or self.builder.get_object("ThumbnailsChk").get_active() or self.builder.get_object("FireFoxChk").get_active()
- if status:
- MessageBox("Result","The cleaning was completed successfully").show()
- return
- MessageBox("Error","Select At Least one Task").show()
- if __name__ == "__main__":
- main = GUI()
- Gtk.main()
|