Merge branch 'Snigdha-OS:master' into master

This commit is contained in:
Abhiraj Roy (iconized)
2024-04-25 15:53:33 +05:30
committed by GitHub
6 changed files with 346 additions and 14 deletions

23
.github/workflows/pylint.yml vendored Normal file
View File

@@ -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')

View File

@@ -1 +1,2 @@
# BlackBox
## _>

View File

@@ -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__))
@@ -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:
@@ -1625,3 +1625,276 @@ 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
)
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
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
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
)
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
)

View File

@@ -1,12 +1 @@
#!/bin/python
'''
NOTE: Don't use any virtual environment as we need gi and Gtk
'''
# Module Import
import os
import sys
import time
import subprocess

View File

@@ -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()

View File

@@ -1 +1,17 @@
<!CODE>
<svg version="1.2" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512" width="512" height="512">
<title>snigdhaos-face</title>
<style>
.s0 { fill: #ffffff }
.s1 { fill: #754ffe }
</style>
<filter id="f0">
<feFlood flood-color="#754ffe" flood-opacity="1" />
<feBlend mode="normal" in2="SourceGraphic"/>
<feComposite in2="SourceAlpha" operator="in" />
</filter>
<g id="Folder 1" filter="url(#f0)">
<path id="Layer" fill-rule="evenodd" class="s0" d="m224.1 312.9l31.7-31.7 31.7 31.7 31.7 31.7-63.4 63.4q-92.4-92.4-184.8-184.8 0-95.1 0-190.2l121.4 121.4-31.7 31.7-44.9-44.9v63.5l108.3 108.2z"/>
<path id="Layer" fill-rule="evenodd" class="s0" d="m319.2 154.4l121.4-121.4q0 95.1 0 190.2-44.9 44.9-89.7 89.7l-95.1-95.1-31.7 31.7-31.7-31.7 63.4-63.4 95.1 95.1 44.8-44.8v-63.5l-44.8 44.9z"/>
</g>
<path id="SNIGDHA OS" class="s1" aria-label="SNIGDHA OS" d="m101.5 425.5h0.7v17.3q0 0.9 0.4 1.4 0.5 0.4 2.1 0.4h4.5v5.7h-7.7q-3.4 0-5.5-0.7-2.1-0.7-3.1-2.5-1-1.9-1.3-4-0.2-2.1-0.2-5.7 0-3.6 0.2-5.5 0.3-1.8 1.3-3.5 1-1.6 3.1-2.3 2.1-0.6 5.5-0.6zm10.1 43.5v-24.4h0.7q2.6 0 4 0.1 1.4 0.1 2.7 0.6 1.4 0.4 1.9 1 0.5 0.6 0.9 2.1 0.5 1.4 0.6 3.1 0 1.7 0 4.8 0 3.2 0 5-0.1 1.9-0.6 3.5-0.4 1.7-0.9 2.3-0.5 0.7-1.9 1.2-1.3 0.5-2.7 0.6-1.4 0.1-4 0.1zm-19.4-13.4h7.6q0.9 0 1.1 0.2 0.1 0.2 0.1 1v4.7q0 1 0.3 1.4 0.3 0.4 1.4 0.4h6.5v5.7h-8.9q-4.4 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