Last active
November 28, 2024 01:15
-
-
Save lidgnulinux/5573b688806f9a214f8e1bad41df318d to your computer and use it in GitHub Desktop.
(WIP) simple qi frontend written using python.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3 | |
import glob, os | |
import argparse | |
import shutil | |
import subprocess | |
import re | |
# from urllib.request import urlretrieve | |
# import requests | |
parser=argparse.ArgumentParser(description="simple qi wrapper.") | |
parser.add_argument("opt1") | |
parser.add_argument("opt2") | |
args=parser.parse_args() | |
def packages(keyword): | |
os.chdir("/var/lib/qi") | |
for file in sorted(glob.glob("*_*." + keyword)): | |
package = file.rstrip('\n').split('_')[:2] | |
print(*package, sep=" ") | |
# to get the "installed_packages.list" file, generate the list using this command : | |
# find /var/lib/qi/ -name "*_*.recipe" -printf '%f\n' | sort | sed 's/.recipe$//' > /var/qi/installed_packages.list | |
def search(keyword): | |
with open("/var/qi/installed_packages.list", 'r') as f: | |
for line in f.readlines(): | |
if keyword in line: | |
package=line.split('_')[:2] | |
print(*package, sep=" ") | |
def info(keyword): | |
package = glob.glob("/var/lib/qi/"+keyword+"_"+"*.txt") | |
pkg = '/'.join(package) | |
with open(pkg, 'r') as f: | |
for line in f.readlines(): | |
if not re.match("QI", line): | |
print(line, end="") | |
def get_source(keyword): | |
package = glob.glob("/var/lib/qi/"+keyword+"_"+"*.txt") | |
pkg = '/'.join(package) | |
with open(pkg, 'r') as f: | |
for line in f.readlines(): | |
if 'fetch' in line: | |
print("Download the" + " " + keyword + " " + "source code") | |
url=line.split('"')[1] | |
file=url.split('/')[-1] | |
subprocess.call(["wget", "-c", url]) | |
def pkg_contents(keyword): | |
package = glob.glob("/usr/pkg/"+keyword+"_*") | |
pkg = '/'.join(package) | |
for root, dirs, files in os.walk(pkg): | |
for file in files: | |
list_contents=os.path.join(root, file).split("/usr/pkg/")[1] | |
package_name_vers=pkg.split("/usr/pkg/")[1] | |
print(package_name_vers, ":", "/"+list_contents.split(package_name_vers + "/")[1]) | |
# To get "content_pkgs.index" file, generate the index using command : find /usr/pkg > /var/qi/content_pkgs.index | |
def pkg_file(keyword): | |
with open("/var/qi/content_pkgs.index", 'r') as f: | |
for line in f.readlines(): | |
if keyword in line: | |
lines=line.rstrip('\n') | |
print(*lines, sep="") | |
def get_template(keyword): | |
if keyword=="meson": | |
shutil.copy("/var/qi/meson_build.recipe", "recipe") | |
elif keyword=="make": | |
shutil.copy("/var/qi/make_build.recipe", "recipe") | |
elif keyword=="cmake": | |
shutil.copy("/var/qi/cmake_build.recipe", "recipe") | |
else: | |
print ("specify template you want !") | |
if args.opt1=="list": | |
packages(args.opt2) | |
elif args.opt1=="search": | |
search(args.opt2) | |
elif args.opt1=="info": | |
info(args.opt2) | |
elif args.opt1=="source": | |
get_source(args.opt2) | |
elif args.opt1=="template": | |
get_template(args.opt2) | |
elif args.opt1=="content": | |
pkg_contents(args.opt2) | |
elif args.opt1=="file": | |
pkg_file(args.opt2) | |
else: | |
print ("Use \"list recipe\", \"info <package name>\" or \"search <pattern>\" as option !") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Build recipe for . | |
# | |
# Exit immediately on any error | |
set -e | |
program= | |
version= | |
release= | |
description="" | |
homepage="" | |
license="" | |
tarname= | |
fetch="" | |
srcdir= | |
build() | |
{ | |
unpack "${tardir}/$tarname" | |
cd "$srcdir" | |
# Set sane permissions | |
chmod -R u+w,go-w,a+rX-s . | |
cmake -B build -G Ninja \ | |
-DBUILD_SHARED_LIBS=ON \ | |
-DCMAKE_BUILD_TYPE=MinSizeRel \ | |
-DCMAKE_INSTALL_PREFIX=/usr \ | |
-DBUILD_TESTING=OFF | |
cmake --build build-shared | |
DESTDIR="$destdir" cmake --install build | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Build recipe for . | |
# | |
# Exit immediately on any error | |
set -e | |
program= | |
version= | |
release=0 | |
description="" | |
homepage="" | |
license="" | |
tarname= | |
fetch="" | |
build() | |
{ | |
unpack "${tardir}/$tarname" | |
cd "$srcdir" | |
# Set sane permissions | |
chmod -R u+w,go-w,a+rX-s . | |
rm -rf BUILD | |
mkdir BUILD | |
cd BUILD | |
CPPFLAGS="$QICPPFLAGS" CFLAGS="$QICFLAGS" LDFLAGS="$QILDFLAGS" \ | |
meson setup $configure_args \ | |
-Dorc-test=disabled \ | |
.. | |
ninja -j2 | |
DESTDIR="$destdir" ninja -j2 install | |
cd .. | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Build recipe for . | |
# | |
# Exit immediately on any error | |
set -e | |
program= | |
version= | |
release= | |
description="" | |
homepage="" | |
license="" | |
tarname= | |
fetch="" | |
srcdir= | |
build() | |
{ | |
unpack "${tardir}/$tarname" | |
cd "$srcdir" | |
# Set sane permissions | |
chmod -R u+w,go-w,a+rX-s . | |
autoreconf -vif | |
./configure \ | |
--disable-static \ | |
--prefix=/usr \ | |
--sysconfdir=/etc \ | |
--mandir=/usr/share/man \ | |
--infodir=/usr/share/info \ | |
--prefix=/usr | |
make | |
make DESTDIR="$destdir" install | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Build recipe for $PKG. | |
# | |
# Exit immediately on any error | |
set -e | |
program= | |
version= | |
release=0 | |
description="" | |
homepage="" | |
license="" | |
tarname= | |
fetch="" | |
build() | |
{ | |
unpack "${tardir}/$tarname" | |
cd "$srcdir" | |
# Set sane permissions | |
chmod -R u+w,go-w,a+rX-s . | |
rm -rf BUILD | |
mkdir BUILD | |
cd BUILD | |
CPPFLAGS="$QICPPFLAGS" CFLAGS="$QICFLAGS" LDFLAGS="$QILDFLAGS" \ | |
meson setup $configure_args \ | |
-Dorc-test=disabled \ | |
.. | |
ninja -j2 | |
DESTDIR="$destdir" ninja -j2 install | |
cd .. | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment