From 21fbb8a3709f61d9b385a05c076ca892a33200ca Mon Sep 17 00:00:00 2001
From: "Eshan Roy (Eshanized)" <148610067+eshanized@users.noreply.github.com>
Date: Wed, 24 Apr 2024 22:37:24 +0530
Subject: [PATCH 01/11] Update blackbox.svg
---
icons/hicolor/scalable/apps/blackbox.svg | 18 +++++++++++++++++-
1 file changed, 17 insertions(+), 1 deletion(-)
diff --git a/icons/hicolor/scalable/apps/blackbox.svg b/icons/hicolor/scalable/apps/blackbox.svg
index e80e091..be8bd6a 100644
--- a/icons/hicolor/scalable/apps/blackbox.svg
+++ b/icons/hicolor/scalable/apps/blackbox.svg
@@ -1 +1,17 @@
-
\ No newline at end of file
+
From 62a35d05dca48a62ebc3f5d429a0bc5dbe2d4c5c Mon Sep 17 00:00:00 2001
From: "Eshan Roy (Eshanized)" <148610067+eshanized@users.noreply.github.com>
Date: Wed, 24 Apr 2024 22:38:45 +0530
Subject: [PATCH 02/11] Create pylint.yml
---
.github/workflows/pylint.yml | 23 +++++++++++++++++++++++
1 file changed, 23 insertions(+)
create mode 100644 .github/workflows/pylint.yml
diff --git a/.github/workflows/pylint.yml b/.github/workflows/pylint.yml
new file mode 100644
index 0000000..383e65c
--- /dev/null
+++ b/.github/workflows/pylint.yml
@@ -0,0 +1,23 @@
+name: Pylint
+
+on: [push]
+
+jobs:
+ build:
+ runs-on: ubuntu-latest
+ strategy:
+ matrix:
+ python-version: ["3.8", "3.9", "3.10"]
+ steps:
+ - uses: actions/checkout@v3
+ - name: Set up Python ${{ matrix.python-version }}
+ uses: actions/setup-python@v3
+ with:
+ python-version: ${{ matrix.python-version }}
+ - name: Install dependencies
+ run: |
+ python -m pip install --upgrade pip
+ pip install pylint
+ - name: Analysing the code with pylint
+ run: |
+ pylint $(git ls-files '*.py')
From e3c7f723a90f60755275e6d0afea73a72d5e6aa8 Mon Sep 17 00:00:00 2001
From: "Eshan Roy (Eshanized)"
Date: Wed, 24 Apr 2024 23:03:45 +0530
Subject: [PATCH 03/11] en
---
blackbox/Functions.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/blackbox/Functions.py b/blackbox/Functions.py
index c028c6f..971c438 100644
--- a/blackbox/Functions.py
+++ b/blackbox/Functions.py
@@ -22,8 +22,8 @@ from distro import id # DOCS : https://github.com/python-distro/distro
import Functions as fn
import gi # DOCS : https://askubuntu.com/questions/80448/what-would-cause-the-gi-module-to-be-missing-from-python
-gi.require_version("Gtk" "3.0")
from gi.repository import GLib, Gtk
+gi.require_version("Gtk" "3.0")
# NOTE: Base Directory
base_dir = os.path.dirname(os.path.realpath(__file__))
From c37e5d93ef766f46d7d190b476cc8853ce9ce749 Mon Sep 17 00:00:00 2001
From: "Eshan Roy (Eshanized)"
Date: Thu, 25 Apr 2024 09:18:14 +0530
Subject: [PATCH 04/11] [update] #search functions for user
---
blackbox/Functions.py | 77 +++++++++++++++++++++++++++++++++++++++++++
1 file changed, 77 insertions(+)
diff --git a/blackbox/Functions.py b/blackbox/Functions.py
index 971c438..28ddee5 100644
--- a/blackbox/Functions.py
+++ b/blackbox/Functions.py
@@ -1625,3 +1625,80 @@ def verify_snigdhaos_pacman_conf():
except Exception as e:
logger.error("Exception in LOC1604: %s" % e)
+def update_textview_pacmanlog(self):
+ lines = self.pacmanlog_queue.get()
+ try:
+ buffer = self.textbuffer_pacmanlog
+ if len(lines) > 0:
+ # DOCS : https://askubuntu.com/questions/435629/how-to-get-text-buffer-from-file-and-loading-into-textview-using-python-and-gtk
+ end_iter = buffer.get_end_iter()
+ for line in lines:
+ if len(line) > 0:
+ buffer.insert(
+ end_iter,
+ line.decode("UTF-8"),
+ len(line),
+ )
+ except Exception as e:
+ logger.error(
+ "Found Exception in LOC1628: %s" % e
+ )
+ finally:
+ # DOCS : https://stackoverflow.com/questions/49637086/python-what-is-queue-task-done-used-for
+ self.pacmanlog_queue.task_done()
+
+def search(self, term):
+ try:
+ logger.info('Searching: "%s"' % term)
+ pkg_matches = []
+ category_dict = {}
+ whitespace = False
+ if term.strip():
+ whitespace = True
+ for pkg_list in self.packages.values():
+ for pkg in pkg_list:
+ if whitespace:
+ for te in term.split(" "):
+ if(
+ te.lower() in pkg.name.lower() or te.lower() in pkg.description.lower()
+ ):
+ if pkg not in pkg_matches:
+ pkg_matches.append(
+ pkg,
+ )
+ else:
+ if (
+ te.lower() in pkg.name.lower() or te.lower() in pkg.description.lower()
+ ):
+ pkg_matches.append(
+ pkg,
+ )
+
+ category_name = None
+ packages_cat = []
+ for pkg_match in pkg_matches:
+ if category_name == pkg_match.category:
+ packages_cat.append(pkg_match)
+ category_dict[category_name] = packages_cat
+ elif category_name is None:
+ packages_cat.append(pkg_match)
+ else:
+ packages_cat = []
+ packages_cat.append(pkg_match)
+ category_dict[pkg_match.category] = packages_cat
+ category_name = pkg_match.category
+ sorted_dict = None
+ if len(category_dict) > 0:
+ sorted_dict = dict(sorted(category_dict.items()))
+ self.search_queue.put(
+ sorted_dict,
+ )
+ else:
+ self.search_queue.put(
+ None,
+ )
+ except Exception as e:
+ logger.error(
+ "Found Exception in LOC1650: %s" % e
+ )
+
\ No newline at end of file
From 5fb1760c4bb8448c5e5f2fca0a61bb2f44582274 Mon Sep 17 00:00:00 2001
From: "Eshan Roy (Eshanized)"
Date: Thu, 25 Apr 2024 09:45:02 +0530
Subject: [PATCH 05/11] [update] pacman config
---
blackbox/Functions.py | 98 ++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 96 insertions(+), 2 deletions(-)
diff --git a/blackbox/Functions.py b/blackbox/Functions.py
index 28ddee5..5b0fc8b 100644
--- a/blackbox/Functions.py
+++ b/blackbox/Functions.py
@@ -1525,7 +1525,7 @@ def remove_snigdhaos_mirrorlist():
result_err["output"] = e
return result_err
-def add_snigdha_repos():
+def add_snigdhaos_repos():
logger.info("Adding Snigdha OS Repos on %s" % distr)
try:
if verify_snigdhaos_pacman_conf() is False:
@@ -1701,4 +1701,98 @@ def search(self, term):
logger.error(
"Found Exception in LOC1650: %s" % e
)
-
\ No newline at end of file
+
+def remove_snigdhaos_repos():
+ try:
+ if verify_snigdhaos_pacman_conf() is True:
+ if os.path.exists(pacman_conf):
+ shutil.copy(
+ pacman_conf,
+ pacman_conf_backup,
+ )
+ logger.info(
+ "Reading From: %s" % pacman_conf
+ )
+ lines = []
+ with open(
+ pacman_conf, "r", encoding="UTF-8"
+ ) as r:
+ lines = r.readlines()
+ if len(lines) > 0:
+ index = 0
+ for line in lines:
+ if "%s\n" % snigdhaos_core[0] == line:
+ index = line.index("%s\n" % snigdhaos_core[0])
+ if index > 0:
+ if distr != "snigdhaos":
+ del lines[index]
+ del lines[index]
+ del lines[index]
+ else:
+ lines[index] = "#%s\n" % snigdhaos_core[0]
+ lines[index + 1] = "#%s\n" % snigdhaos_core[1]
+ lines[index + 2] = "#%s\n" % snigdhaos_core[2]
+ elif (
+ "#" in line.strip()
+ and snigdhaos_core[0] == line.replace("#", "").strip()
+ and distr != "snigdhaos"
+ ):
+ index = lines.index(line)
+ del lines[index]
+ del lines[index]
+ del lines[index]
+ if "%s\n" %snigdhaos_extra[0] == line:
+ index = lines.index("%s\n" % snigdhaos_extra[0])
+ if index > 0:
+ if distr != "snigdhaos":
+ del lines[index]
+ del lines[index]
+ del lines[index]
+ else:
+ lines[index] = "#%s\n" % snigdhaos_extra[0]
+ lines[index + 1] = "#%s\n" % snigdhaos_extra[1]
+ lines[index + 2] = "#%s\n" % snigdhaos_extra[2]
+ elif (
+ "#" in line.strip()
+ and snigdhaos_extra[0] == line.replace("#", "").strip()
+ and distr != "snigdhaos"
+ ):
+ index = lines.index(line)
+ del lines[index]
+ del lines[index]
+ del lines[index]
+ if distr != "snigdhaos":
+ if lines[-1] == "\n":
+ del lines[-1]
+ if lines[-2] == "\n":
+ del lines[-2]
+ if lines[-3] == "\n":
+ del lines[-3]
+ if lines[-4] == "\n":
+ del lines[-4]
+ logger.info(
+ "[Remove Snigdha OS Repos] Writing to %s" % pacman_conf
+ )
+ if len(lines) > 0:
+ with open(pacman_conf, "w") as w:
+ w.writelines(lines)
+ w.flush() # DOCS : https://www.geeksforgeeks.org/file-flush-method-in-python/
+ return 0
+ else:
+ logger.error(
+ "Failed to process: %s" % pacman_conf
+ )
+ else:
+ logger.error(
+ "Failed to read %s" % pacman_conf
+ )
+ else:
+ logger.info(
+ "No Snigdha OS Repos inside Pacman Config!"
+ )
+ return 0
+ except Exception as e:
+ logger.error(
+ "Found Exception in LOC1705: %s" % e
+ )
+ return e
From dc0cc59684cfc4335ab7a2a351dfcd52602ef58a Mon Sep 17 00:00:00 2001
From: "Eshan Roy (Eshanized)"
Date: Thu, 25 Apr 2024 09:52:05 +0530
Subject: [PATCH 06/11] [update] Functions ->
check_if_another_process_running()
---
blackbox/Functions.py | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/blackbox/Functions.py b/blackbox/Functions.py
index 5b0fc8b..a14513a 100644
--- a/blackbox/Functions.py
+++ b/blackbox/Functions.py
@@ -1796,3 +1796,13 @@ def remove_snigdhaos_repos():
"Found Exception in LOC1705: %s" % e
)
return e
+def check_if_process_running(process_name):
+ # DOCS : https://psutil.readthedocs.io/en/latest/#psutil.process_iter
+ for proc in psutil.process_iter():
+ try:
+ pinfo = proc.as_dict(attrs=["pid", "name", "create_time"])
+ if process_name == pinfo["pid"]:
+ return True
+ except (psutil.NoSuchProcess, psutil.AccessDenied, psutil.ZombieProcess):
+ pass
+ return False
From 5499d6e9bd88f96ed902f37204058f18a7475374 Mon Sep 17 00:00:00 2001
From: "Eshan Roy (Eshanized)"
Date: Thu, 25 Apr 2024 10:15:58 +0530
Subject: [PATCH 07/11] [update] termination
---
blackbox/Functions.py | 49 +++++++++++++++++++++++++++++++++++++++++++
blackbox/blackbox.py | 6 ------
2 files changed, 49 insertions(+), 6 deletions(-)
diff --git a/blackbox/Functions.py b/blackbox/Functions.py
index a14513a..ff3aa84 100644
--- a/blackbox/Functions.py
+++ b/blackbox/Functions.py
@@ -1806,3 +1806,52 @@ def check_if_process_running(process_name):
except (psutil.NoSuchProcess, psutil.AccessDenied, psutil.ZombieProcess):
pass
return False
+
+def terminate_pacman():
+ try:
+ process_found = False
+ for proc in psutil.process_iter():
+ try:
+ pinfo = proc.as_dict(attrs=["pid", "name", "create_time"])
+ if pinfo["name"] == "pacman":
+ process_found = True
+ logger.debug(
+ "Killing Pacman Process: %s" %pinfo["name"]
+ )
+ proc.kill()
+ except (psutil.NoSuchProcess, psutil.AccessDenied):
+ continue
+ if process_found == True:
+ if check_pacman_lockfile():
+ os.unlink(pacman_lockfile)
+ except Exception as e:
+ logger.error(
+ "Found Exception in LOC1810: %s" % e
+ )
+
+def check_pacman_lockfile():
+ try:
+ if os.path.exists(pacman_lockfile):
+ return True
+ else:
+ return False
+ except Exception as e:
+ logger.error(
+ "Found Exception in LOC1832: %s" % e
+ )
+
+def is_thread_alive(thread_name):
+ for thread in threading.enumerate():
+ if thread.name == thread_name and thread.is_alive():
+ return True
+ return False
+
+def print_running_threads():
+ threads_alive = []
+ for thread in threading.enumerate():
+ if thread.is_alive():
+ threads_alive.append(thread.name)
+ for th in threads_alive:
+ logger.debug(
+ "Thread: %s Status: Alive" % th
+ )
\ No newline at end of file
diff --git a/blackbox/blackbox.py b/blackbox/blackbox.py
index 0979a02..8acee96 100644
--- a/blackbox/blackbox.py
+++ b/blackbox/blackbox.py
@@ -1,11 +1,5 @@
#!/bin/python
-'''
-NOTE: Don't use any virtual environment as we need gi and Gtk
-'''
-
-# Module Import
-
import os
import sys
import time
From a8b21f622fa06e683a80059b5d7f9f6a662800cf Mon Sep 17 00:00:00 2001
From: "Eshan Roy (Eshanized)"
Date: Thu, 25 Apr 2024 10:30:58 +0530
Subject: [PATCH 08/11] update
---
blackbox/Functions.py | 43 +++++++++++++++++++++++++++++++++++++++++++
1 file changed, 43 insertions(+)
diff --git a/blackbox/Functions.py b/blackbox/Functions.py
index ff3aa84..27271f9 100644
--- a/blackbox/Functions.py
+++ b/blackbox/Functions.py
@@ -1854,4 +1854,47 @@ def print_running_threads():
for th in threads_alive:
logger.debug(
"Thread: %s Status: Alive" % th
+ )
+
+def check_holding_queue(self):
+ while True:
+ (
+ package,
+ action,
+ widget,
+ cmd_str,
+ progress_dialog,
+ ) = self.pkg_holding_queue.get()
+ try:
+ while check_pacman_lockfile() is True:
+ time.sleep(0.2)
+ th_subprocess = Thread(
+ name = "thread_subprocess",
+ target = start_subprocess,
+ args=(
+ self,
+ cmd_str,
+ progress_dialog,
+ action,
+ package,
+ widget,
+ ),
+ daemon=True
+ )
+ th_subprocess.start()
+ finally:
+ self.pkg_holding_queue.task_done()
+
+def get_pacman_process():
+ try:
+ for proc in psutil.process_iter():
+ try:
+ pinfo = proc.as_dict(attrs=["pid", "name", "create_time"])
+ if pinfo["name"] == "pacman":
+ return " ".join(proc.cmdline)
+ except (psutil.NoSuchProcess, psutil.AccessDenied, psutil.ZombieProcess):
+ pass
+ except Exception as e:
+ logger.error(
+ "Found Exception in LOC1888: %s" % e
)
\ No newline at end of file
From c7dc423eeea5eb2e96f6d59152b8434b69899eab Mon Sep 17 00:00:00 2001
From: D3V1L0N <167227445+D3V1L0N@users.noreply.github.com>
Date: Thu, 25 Apr 2024 10:35:56 +0530
Subject: [PATCH 09/11] Contribution on ui SplashScreen.py
---
blackbox/ui/SplashScreen.py | 30 ++++++++++++++++++++++++++++++
1 file changed, 30 insertions(+)
create mode 100644 blackbox/ui/SplashScreen.py
diff --git a/blackbox/ui/SplashScreen.py b/blackbox/ui/SplashScreen.py
new file mode 100644
index 0000000..f2ad00d
--- /dev/null
+++ b/blackbox/ui/SplashScreen.py
@@ -0,0 +1,30 @@
+import gi
+from Functions import os
+
+gi.require_version("Gtk", "3.0")
+from gi.repository import Gtk, GdkPixbuf, Gdk # noqa
+
+base_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))
+# base_dir = os.path.dirname(os.path.realpath(__file__))
+
+
+class SplashScreen(Gtk.Window):
+ def __init__(self):
+ Gtk.Window.__init__(self, Gtk.WindowType.POPUP, title="")
+ self.set_decorated(False)
+ self.set_resizable(False)
+ self.set_size_request(600, 400)
+ self.set_position(Gtk.WindowPosition.CENTER)
+
+ main_vbox = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=1)
+ self.add(main_vbox)
+
+ self.image = Gtk.Image()
+ pimage = GdkPixbuf.Pixbuf().new_from_file_at_size(
+ base_dir + "/images/splash.png", 600, 400
+ )
+ self.image.set_from_pixbuf(pimage)
+
+ main_vbox.pack_start(self.image, True, True, 0)
+
+ self.show_all()
From f3dc4b588dc2eaf0c198aeeb5ffa9ea5bc3de00c Mon Sep 17 00:00:00 2001
From: "Eshan Roy (Eshanized)"
Date: Thu, 25 Apr 2024 10:42:53 +0530
Subject: [PATCH 10/11] empty >
---
README.md | 1 +
1 file changed, 1 insertion(+)
diff --git a/README.md b/README.md
index 370ede2..9d5f094 100644
--- a/README.md
+++ b/README.md
@@ -1 +1,2 @@
# BlackBox
+## _>
\ No newline at end of file
From 92aa5473c6d67d091629a052588c6b457e79c192 Mon Sep 17 00:00:00 2001
From: Sukanto Kundu
Date: Thu, 25 Apr 2024 13:10:32 +0530
Subject: [PATCH 11/11] cleanup
---
blackbox/blackbox.py | 5 -----
1 file changed, 5 deletions(-)
diff --git a/blackbox/blackbox.py b/blackbox/blackbox.py
index 8acee96..5ceb5fa 100644
--- a/blackbox/blackbox.py
+++ b/blackbox/blackbox.py
@@ -1,6 +1 @@
#!/bin/python
-
-import os
-import sys
-import time
-import subprocess