mirror of
https://gitlab.com/dslackw/slpkg.git
synced 2024-11-17 07:48:18 +01:00
added queue options
This commit is contained in:
parent
0a154ed181
commit
356a149a90
3 changed files with 184 additions and 3 deletions
|
@ -41,6 +41,7 @@ def initialization():
|
|||
'''
|
||||
sbo_log = log_path + "sbo/"
|
||||
sbo_lib = lib_path + "sbo_repo/"
|
||||
pkg_que = lib_path + "queue"
|
||||
if not os.path.exists(log_path):
|
||||
os.mkdir(log_path)
|
||||
if not os.path.exists(lib_path):
|
||||
|
@ -49,6 +50,8 @@ def initialization():
|
|||
os.mkdir(sbo_log)
|
||||
if not os.path.exists(sbo_lib):
|
||||
os.mkdir(sbo_lib)
|
||||
if not os.path.exists(pkg_que):
|
||||
os.mkdir(pkg_que)
|
||||
sbo_url = ("http://slackbuilds.org/slackbuilds/{0}/".format(slack_ver()))
|
||||
# Read SLACKBUILDS.TXT from slackbuilds.org and write in /var/lib/slpkg/sbo_repo/
|
||||
# directory if not exist
|
||||
|
|
|
@ -25,6 +25,7 @@ import sys
|
|||
import getpass
|
||||
|
||||
from colors import *
|
||||
from queue import QueuePkgs
|
||||
from messages import s_user
|
||||
from blacklist import BlackList
|
||||
from version import prog_version
|
||||
|
@ -53,6 +54,8 @@ def main():
|
|||
" -v, --version print version and exit",
|
||||
" -a, script [source...] auto build packages",
|
||||
" -b, --list, [package...] --add, --remove add, remove packages in blacklist",
|
||||
" -q, --list, [package...] --add, --remove add, remove packages in queue",
|
||||
" --build, --install, --build-install build or install from queue",
|
||||
" -l, all, sbo, slack, noarch list of installed packages",
|
||||
" -c, <repository> --upgrade --current check for updated packages",
|
||||
" -s, <repository> <package> --current download, build & install",
|
||||
|
@ -72,6 +75,8 @@ def main():
|
|||
"slpkg - version {0}\n".format(__version__),
|
||||
"Usage: slpkg [-h] [-v] [-a script [sources...]]",
|
||||
" [-b --list, [...] --add, --remove]",
|
||||
" [-q --list, [...] --add, --remove]",
|
||||
" [-q <repository> --build --install]",
|
||||
" [-l all, sbo, slack, noarch]",
|
||||
" [-c <repository> --upgrade --current]",
|
||||
" [-s <repository> <package> --current]",
|
||||
|
@ -82,6 +87,8 @@ def main():
|
|||
args = sys.argv
|
||||
args.pop(0)
|
||||
repository = ["sbo", "slack"]
|
||||
blacklist = BlackList()
|
||||
queue = QueuePkgs()
|
||||
if len(args) == 0:
|
||||
for opt in usage: print(opt)
|
||||
elif len(args) == 1 and args[0] == "-h" or args[0] == "--help" and args[1:] == []:
|
||||
|
@ -127,11 +134,24 @@ def main():
|
|||
elif len(args) == 2 and args[0] == "-n":
|
||||
sbo_network(args[1])
|
||||
elif len(args) == 2 and args[0] == "-b" and args[1] == "--list":
|
||||
BlackList().listed()
|
||||
blacklist.listed()
|
||||
elif len(args) > 2 and args[0] == "-b" and args[-1] == "--add":
|
||||
BlackList().add(args[1:-1])
|
||||
blacklist.add(args[1:-1])
|
||||
elif len(args) > 2 and args[0] == "-b" and args[-1] == "--remove":
|
||||
BlackList().remove(args[1:-1])
|
||||
blacklist.remove(args[1:-1])
|
||||
elif len(args) == 2 and args[0] == "-q" and args[1] == "--list":
|
||||
queue.listed()
|
||||
elif len(args) > 2 and args[0] == "-q" and args[-1] == "--add":
|
||||
queue.add(args[1:-1])
|
||||
elif len(args) > 2 and args[0] == "-q" and args[-1] == "--remove":
|
||||
queue.remove(args[1:-1])
|
||||
elif len(args) == 2 and args[0] =="-q" and args[1] == "--build":
|
||||
queue.build()
|
||||
elif len(args) == 2 and args[0] =="-q" and args[1] == "--install":
|
||||
queue.install()
|
||||
elif len(args) == 2 and args[0] =="-q" and args[1] == "--build-install":
|
||||
queue.build()
|
||||
queue.install()
|
||||
elif len(args) > 1 and args[0] == "-i":
|
||||
PackageManager(args[1:]).install()
|
||||
elif len(args) > 1 and args[0] == "-u":
|
||||
|
|
158
slpkg/queue.py
Executable file
158
slpkg/queue.py
Executable file
|
@ -0,0 +1,158 @@
|
|||
#!/usr/bin/python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# queue.py file is part of slpkg.
|
||||
|
||||
# Copyright 2014 Dimitris Zlatanidis <d.zlatanidis@gmail.com>
|
||||
# All rights reserved.
|
||||
|
||||
# Utility for easy management packages in Slackware
|
||||
|
||||
# https://github.com/dslackw/slpkg
|
||||
|
||||
# Slpkg 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 os
|
||||
import sys
|
||||
from __metadata__ import lib_path, build_path, tmp
|
||||
from downloader import Download
|
||||
|
||||
from pkg.find import find_package
|
||||
from pkg.manager import PackageManager
|
||||
from pkg.build import build_package
|
||||
from sbo.greps import SBoGrep
|
||||
from sbo.download import sbo_slackbuild_dwn
|
||||
from sbo.search import sbo_search_pkg
|
||||
|
||||
|
||||
class QueuePkgs(object):
|
||||
'''
|
||||
Class to list, add or remove packages in queue.
|
||||
'''
|
||||
def __init__(self):
|
||||
queue_file = [
|
||||
"# In this file you can create a list of\n",
|
||||
"# packages you want to build or install.\n",
|
||||
"#\n"
|
||||
]
|
||||
self.queue = lib_path + "queue/"
|
||||
self.queue_list = self.queue + "queue_list"
|
||||
if not os.path.exists(lib_path):
|
||||
os.mkdir(lib_path)
|
||||
if not os.path.exists(self.queue):
|
||||
os.mkdir(self.queue)
|
||||
if not os.path.isfile(self.queue_list):
|
||||
with open(self.queue_list, "w") as queue:
|
||||
for line in queue_file:
|
||||
queue.write(line)
|
||||
queue.close()
|
||||
|
||||
def packages(self):
|
||||
'''
|
||||
Return queue list from /var/lib/queue/queue_list
|
||||
file.
|
||||
'''
|
||||
queue_list = []
|
||||
with open(self.queue_list, "r") as queue:
|
||||
for read in queue:
|
||||
read = read.lstrip()
|
||||
if not read.startswith("#"):
|
||||
queue_list.append(read.replace("\n", ""))
|
||||
queue.close()
|
||||
return queue_list
|
||||
|
||||
def listed(self):
|
||||
'''
|
||||
Print packages from queue
|
||||
'''
|
||||
exit = 0
|
||||
print("\nPackages in queue:\n")
|
||||
for pkg in self.packages():
|
||||
if pkg:
|
||||
print(pkg)
|
||||
exit = 1
|
||||
if exit == 1:
|
||||
print # new line at exit
|
||||
|
||||
def add(self, pkgs):
|
||||
'''
|
||||
Add packages in queue if not exist
|
||||
'''
|
||||
exit = 0
|
||||
queue_list = self.packages()
|
||||
print("\nAdd packages in queue:\n")
|
||||
with open(self.queue_list, "a") as queue:
|
||||
for pkg in pkgs:
|
||||
if pkg not in queue_list:
|
||||
print(pkg)
|
||||
queue.write(pkg + "\n")
|
||||
exit = 1
|
||||
queue.close()
|
||||
if exit == 1:
|
||||
print # new line at exit
|
||||
|
||||
def remove(self, pkgs):
|
||||
'''
|
||||
Remove packages from queue
|
||||
'''
|
||||
exit = 0
|
||||
print("\nRemove packages from queue:\n")
|
||||
with open(self.queue_list, "r") as queue:
|
||||
lines = queue.read()
|
||||
queue.close()
|
||||
if pkgs == ["all"]: pkgs = self.packages()
|
||||
with open(self.queue_list, "w") as queue:
|
||||
for line in lines.splitlines():
|
||||
if line not in pkgs:
|
||||
queue.write(line + "\n")
|
||||
else:
|
||||
print(line)
|
||||
exit = 1
|
||||
queue.close()
|
||||
if exit == 1:
|
||||
print # new line at exit
|
||||
|
||||
def build(self):
|
||||
'''
|
||||
Build packages from queue
|
||||
'''
|
||||
packages = self.packages()
|
||||
if packages:
|
||||
for pkg in packages:
|
||||
if not os.path.exists(build_path):
|
||||
os.mkdir(build_path)
|
||||
sbo_url = sbo_search_pkg(pkg)
|
||||
sbo_dwn = sbo_slackbuild_dwn(sbo_url)
|
||||
source_dwn = SBoGrep(pkg).source().split()
|
||||
sources = []
|
||||
os.chdir(build_path)
|
||||
script = sbo_dwn.split("/")[-1] # get file from script link
|
||||
Download(build_path, sbo_dwn).start()
|
||||
for src in source_dwn:
|
||||
Download(build_path, src).start()
|
||||
sources.append(src.split("/")[-1]) # get file from source link
|
||||
build_package(script, sources, build_path)
|
||||
else:
|
||||
print("\nPackages not found in the queue\n")
|
||||
|
||||
def install(self):
|
||||
packages = self.packages()
|
||||
if packages:
|
||||
for pkg in packages:
|
||||
find = find_package(pkg, tmp)
|
||||
if find:
|
||||
find = max(find)
|
||||
if pkg in find:
|
||||
binary = "{0}{1}".format(tmp, find)
|
||||
PackageManager(binary.split()).install()
|
||||
else:
|
||||
print("\nPackages not found in the queue\n")
|
Loading…
Reference in a new issue