uruk-cleaner 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. #!/usr/bin/env python3
  2. # uruk cleaner
  3. # to clean your system
  4. # Copyright (c) 2016, 2022 ali miracle <alimiracle@riseup.net>
  5. # This Program is free software: you can redistribute it and/or modify
  6. # it under the terms of the GNU General Public License as published by
  7. # the Free Software Foundation, either version 3 of the License, or
  8. # (at your option) any later version.
  9. # This Program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU General Public License for more details.
  13. # You should have received a copy of the GNU General Public License
  14. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. import gi
  16. gi.require_version("Gtk", "3.0")
  17. from gi.repository import Gtk
  18. gi.require_version('Gdk', '3.0')
  19. from gi.repository import Gdk
  20. import dbus
  21. from _dbus_bindings import BUS_DAEMON_IFACE, BUS_DAEMON_NAME, BUS_DAEMON_PATH
  22. import os
  23. class Cleaner:
  24. def __init__(self):
  25. timeout = 60
  26. flags = 0
  27. bus_name = "org.dbus.ucleaner"
  28. opath = "/org/ucleaner"
  29. #get the system bus
  30. bus = dbus.SystemBus()
  31. bus.call_blocking(BUS_DAEMON_NAME, BUS_DAEMON_PATH, BUS_DAEMON_IFACE,'StartServiceByName', 'su', (bus_name, flags), timeout=timeout)
  32. #get the object
  33. dbus_object = bus.get_object(bus_name, opath)
  34. #get the interface
  35. self.dbus_interface = dbus.Interface(dbus_object, "org.ucleaner")
  36. def clean_apt_cach(self):
  37. self.dbus_interface.clean_apt_cache()
  38. def clean_logs(self):
  39. self.dbus_interface.clean_logs()
  40. def remove_unused_pkgs(self):
  41. self.dbus_interface.remove_unused_packages()
  42. def remove_thumbnails(self):
  43. os.system("rm -rf ~/.cache/thumbnails/*")
  44. def clean_firefox_cach(self):
  45. os.system("rm ~/.mozilla/firefox/*.default*/*.sqlite ~/.mozilla/firefox/*default*/sessionstore.js")
  46. os.system("rm -r ~/.cache/mozilla/firefox/*.default*/*")
  47. class MessageBox:
  48. def __init__(self,message_title,message_content):
  49. self.__load_css()
  50. self.__init_builder()
  51. self.__extract_widget()
  52. self.set_content(message_content)
  53. self.set_title(message_title)
  54. def set_title(self,title):
  55. self.title_label.set_text(title)
  56. def set_content(self,content):
  57. self.content_label.set_text(content)
  58. pass
  59. def __init_builder(self):
  60. self.gladefile = "/usr/share/uruk-cleaner/messagebox.glade"
  61. self.builder = Gtk.Builder()
  62. try:
  63. self.builder.add_from_file(self.gladefile)
  64. except:
  65. print("Cant find The glade File", file = sys.stderr)
  66. exit(1)
  67. self.builder.connect_signals(self)
  68. def __extract_widget(self):
  69. self.window = self.builder.get_object("TopWindow")
  70. self.title_label = self.builder.get_object("TitleLabel")
  71. self.content_label = self.builder.get_object("MessageLabel")
  72. def show(self):
  73. self.window.show()
  74. def __load_css(self):
  75. screen = Gdk.Screen.get_default()
  76. provider = Gtk.CssProvider()
  77. provider.load_from_path("/usr/share/uruk-cleaner/messagebox.css")
  78. Gtk.StyleContext.add_provider_for_screen(screen, provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION)
  79. def ok_btn_click(self, *args):
  80. self.window.close()
  81. class GUI:
  82. IsWindowMaximized=False
  83. def __init__(self):
  84. self.__lode_css()
  85. self.cleaner=Cleaner()
  86. self.__init_builder()
  87. self.show_windo()
  88. def __lode_css(self):
  89. screen = Gdk.Screen.get_default()
  90. provider = Gtk.CssProvider()
  91. try:
  92. provider.load_from_path("/usr/share/uruk-cleaner/cleaner.css")
  93. except:
  94. print("Cant find The CSS File", file = sys.stderr)
  95. exit(1)
  96. Gtk.StyleContext.add_provider_for_screen(screen, provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION)
  97. def __init_builder(self):
  98. self.gladefile = "/usr/share/uruk-cleaner/cleaner.glade"
  99. self.builder = Gtk.Builder()
  100. try:
  101. self.builder.add_from_file(self.gladefile)
  102. except:
  103. print("Cant find The glade File", file = sys.stderr)
  104. exit(1)
  105. self.builder.connect_signals(self)
  106. def show_windo(self):
  107. self.window = self.builder.get_object("TopWindow")
  108. self.window.show()
  109. def maximize(self, button):
  110. if IsWindowMaximized:
  111. Gtk.Window.normlize(self.window)
  112. IsWindowMaximized=False
  113. return
  114. Gtk.Window.maximize(self.window)
  115. def minimize(self, button):
  116. Gtk.Window.minimize(self.window)
  117. def close(self, *args):
  118. Gtk.main_quit()
  119. exit(0)
  120. def about(self, button):
  121. 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()
  122. def Clean(self, button):
  123. if self.builder.get_object("AptCacheChk").get_active():
  124. self.cleaner.clean_apt_cach()
  125. if self.builder.get_object("LogsChk").get_active():
  126. self.cleaner.clean_logs()
  127. if self.builder.get_object("UnUsedPkgsChk").get_active():
  128. self.cleaner.remove_unused_pkgs()
  129. if self.builder.get_object("ThumbnailsChk").get_active():
  130. self.cleaner.remove_thumbnails()
  131. if self.builder.get_object("FireFoxChk").get_active():
  132. self.cleaner.clean_firefox_cach()
  133. 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()
  134. if status:
  135. MessageBox("Result","The cleaning was completed successfully").show()
  136. return
  137. MessageBox("Error","Select At Least one Task").show()
  138. if __name__ == "__main__":
  139. main = GUI()
  140. Gtk.main()