2014-05-23 07:46:51 +02:00
|
|
|
#!/usr/bin/python
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
|
2014-06-24 04:40:21 +02:00
|
|
|
''' Utility to help package management in Slackware.
|
2014-05-28 16:35:41 +02:00
|
|
|
Slpkg is a terminal tool in order to easy use Slackware packages.
|
|
|
|
|
|
|
|
|
|
|
|
It's a quick and easy way to manage your packages in Slackware to a command.
|
|
|
|
|
2014-05-23 07:46:51 +02:00
|
|
|
|
|
|
|
|
|
|
|
usage: slpkg [-h] [-v] [-s script [source ...]] [-l all, sbo [all, sbo ...]]
|
2014-05-28 16:35:41 +02:00
|
|
|
[-t] [-n] [-c] [-b] [-i [...]] [-u [...]] [-a [...]]
|
|
|
|
[-r [...]] [-f [...]] [-d [...]]
|
2014-05-23 07:46:51 +02:00
|
|
|
|
|
|
|
Utility to help package management in Slackware
|
|
|
|
|
|
|
|
optional arguments:
|
|
|
|
-h, --help show this help message and exit
|
|
|
|
-v, --verbose print version and exit
|
|
|
|
-s script [source ...]
|
|
|
|
auto build package
|
|
|
|
-l all, sbo [all, sbo ...]
|
|
|
|
list of installed packages
|
|
|
|
-t tracking dependencies
|
|
|
|
-n find from SBo repositority
|
|
|
|
-c check if your package is up to date
|
2014-05-28 16:35:41 +02:00
|
|
|
-b download, build & install pkg from SBo
|
2014-05-23 07:46:51 +02:00
|
|
|
-i [ ...] install binary packages
|
|
|
|
-u [ ...] install-upgrade packages with new
|
|
|
|
-a [ ...] reinstall the same packages
|
|
|
|
-r [ ...] remove packages
|
|
|
|
-f [ ...] find if packages installed
|
2014-06-24 04:40:21 +02:00
|
|
|
-d [ ...] display the contents of the packages
|
|
|
|
|
|
|
|
'''
|
2014-05-23 07:46:51 +02:00
|
|
|
|
|
|
|
|
|
|
|
import os
|
|
|
|
import re
|
|
|
|
import sys
|
|
|
|
import shutil
|
|
|
|
import tarfile
|
|
|
|
import getpass
|
|
|
|
import urllib2
|
|
|
|
import argparse
|
|
|
|
import subprocess
|
|
|
|
|
|
|
|
|
|
|
|
__author__ = "dslackw"
|
2014-06-26 05:51:29 +02:00
|
|
|
__version__ = "1.5.3"
|
2014-05-23 07:46:51 +02:00
|
|
|
__license__ = "GNU General Public License v3 (GPLv3)"
|
|
|
|
__email__ = "d.zlatanidis@gmail.com"
|
|
|
|
|
|
|
|
|
|
|
|
# grep computer architecture
|
|
|
|
uname = os.uname()
|
|
|
|
arch = (uname[4])
|
|
|
|
|
2014-05-30 15:46:43 +02:00
|
|
|
|
2014-06-05 02:23:14 +02:00
|
|
|
# SBo fietype binary packages for install
|
|
|
|
SBo_arch = "*"
|
2014-05-30 15:46:43 +02:00
|
|
|
SBo_tag = "?_SBo"
|
|
|
|
SBo_filetype = ".tgz"
|
|
|
|
|
|
|
|
|
2014-05-23 07:46:51 +02:00
|
|
|
# create tmp directory
|
|
|
|
os.system("mkdir -p /tmp/slpkg/readme/")
|
|
|
|
|
|
|
|
|
|
|
|
# path file record
|
|
|
|
packages = "/var/log/packages/"
|
|
|
|
tmp = "/tmp/"
|
|
|
|
|
|
|
|
|
|
|
|
# create dependencies list
|
|
|
|
dep_results = []
|
2014-05-28 16:35:41 +02:00
|
|
|
dep_links_results = []
|
|
|
|
|
2014-05-23 07:46:51 +02:00
|
|
|
|
|
|
|
# SlackBuilds repository link
|
2014-05-30 11:27:34 +02:00
|
|
|
SBo_url = "http://slackbuilds.org/repository/14.1/"
|
2014-05-23 07:46:51 +02:00
|
|
|
|
|
|
|
|
|
|
|
# create repository list
|
2014-06-06 14:49:33 +02:00
|
|
|
repository = [
|
2014-06-20 03:43:40 +02:00
|
|
|
'academic',
|
|
|
|
'business',
|
|
|
|
'games',
|
|
|
|
'ham',
|
|
|
|
'misc',
|
|
|
|
'office',
|
|
|
|
'ruby',
|
|
|
|
'accessibility',
|
|
|
|
'desktop',
|
|
|
|
'gis',
|
|
|
|
'haskell',
|
|
|
|
'multimedia',
|
|
|
|
'perl',
|
|
|
|
'system',
|
|
|
|
'audio',
|
|
|
|
'development',
|
|
|
|
'graphics',
|
|
|
|
'libraries',
|
|
|
|
'network',
|
|
|
|
'python'
|
2014-06-06 14:49:33 +02:00
|
|
|
]
|
2014-05-23 07:46:51 +02:00
|
|
|
|
|
|
|
|
|
|
|
# print out colors class
|
|
|
|
class colors:
|
2014-06-20 03:43:40 +02:00
|
|
|
RED = "\x1b[31m"
|
|
|
|
GREEN = "\x1b[32m"
|
|
|
|
YELLOW = "\x1b[33m"
|
|
|
|
CYAN = "\x1b[36m"
|
|
|
|
ENDC = "\x1b[0m"
|
2014-05-23 07:46:51 +02:00
|
|
|
|
|
|
|
|
|
|
|
# check if user is root
|
|
|
|
def s_user(user):
|
2014-06-20 03:43:40 +02:00
|
|
|
if user != "root":
|
|
|
|
print
|
|
|
|
print (
|
|
|
|
"{}Must have {}`root`{} privileges ...{}\n".format(
|
|
|
|
colors.RED,
|
|
|
|
colors.GREEN,
|
|
|
|
colors.RED,
|
|
|
|
colors.ENDC))
|
|
|
|
sys.exit()
|
2014-05-23 07:46:51 +02:00
|
|
|
|
|
|
|
|
|
|
|
# remove unused chars
|
|
|
|
def rmv_unused(name):
|
2014-06-20 03:43:40 +02:00
|
|
|
rmv = "><"
|
|
|
|
for ch in rmv:
|
|
|
|
name = name.replace(ch, "")
|
2014-05-23 07:46:51 +02:00
|
|
|
|
2014-06-20 03:43:40 +02:00
|
|
|
return name
|
2014-06-06 11:42:44 +02:00
|
|
|
|
|
|
|
|
2014-05-23 07:46:51 +02:00
|
|
|
# get filename from links
|
2014-05-30 15:46:43 +02:00
|
|
|
def get_file(link, char):
|
2014-06-26 05:49:22 +02:00
|
|
|
i = 0
|
2014-06-20 03:43:40 +02:00
|
|
|
results = []
|
2014-06-26 05:49:22 +02:00
|
|
|
for file in range(len(link)):
|
|
|
|
i -= 1
|
|
|
|
results.append(link[i])
|
|
|
|
if link[i] == char:
|
|
|
|
break
|
|
|
|
|
|
|
|
return ''.join(results[::-1]).replace('/', '').strip(' ')
|
2014-05-23 07:46:51 +02:00
|
|
|
|
|
|
|
|
|
|
|
# this fuction return if the package exist
|
|
|
|
def find_package(find_pkg, directory):
|
2014-06-20 03:43:40 +02:00
|
|
|
results = []
|
2014-05-23 07:46:51 +02:00
|
|
|
|
2014-06-20 03:43:40 +02:00
|
|
|
for file in os.listdir(directory):
|
|
|
|
if file.startswith(find_pkg):
|
|
|
|
results.append(file)
|
2014-05-23 07:46:51 +02:00
|
|
|
|
2014-06-20 03:43:40 +02:00
|
|
|
return results
|
2014-05-23 07:46:51 +02:00
|
|
|
|
|
|
|
|
|
|
|
# open url and read page
|
|
|
|
def url_read(name):
|
2014-06-24 04:40:21 +02:00
|
|
|
try:
|
|
|
|
f = urllib2.urlopen(name)
|
|
|
|
return f.read()
|
|
|
|
except urllib2.URLError:
|
|
|
|
print
|
|
|
|
print "slpkg: error: connection refused"
|
|
|
|
sys.exit()
|
2014-05-23 07:46:51 +02:00
|
|
|
|
|
|
|
|
2014-06-20 03:43:40 +02:00
|
|
|
# read SBo README
|
2014-05-30 11:27:34 +02:00
|
|
|
def read_readme(SBo_url, name, site):
|
2014-06-24 16:06:01 +02:00
|
|
|
s_user(getpass.getuser())
|
2014-06-20 03:43:40 +02:00
|
|
|
readme = url_read((SBo_url + site).replace("repository", "slackbuilds"))
|
2014-05-23 07:46:51 +02:00
|
|
|
|
2014-06-20 03:43:40 +02:00
|
|
|
file = open("/tmp/slpkg/readme/" + name + "." + site, "w")
|
|
|
|
file.write(readme)
|
|
|
|
file.close()
|
2014-05-23 07:46:51 +02:00
|
|
|
|
|
|
|
|
2014-06-20 03:43:40 +02:00
|
|
|
# read SBo .info
|
2014-05-30 11:27:34 +02:00
|
|
|
def read_info_slackbuild(SBo_url, name, site):
|
2014-06-24 16:06:01 +02:00
|
|
|
s_user(getpass.getuser())
|
2014-06-20 03:43:40 +02:00
|
|
|
info = url_read(
|
|
|
|
(SBo_url +
|
|
|
|
name +
|
|
|
|
site).replace(
|
|
|
|
"repository",
|
|
|
|
"slackbuilds"))
|
2014-05-23 07:46:51 +02:00
|
|
|
|
2014-06-20 03:43:40 +02:00
|
|
|
file = open("/tmp/slpkg/readme/" + name + site, "w")
|
|
|
|
file.write(info)
|
|
|
|
file.close()
|
2014-05-23 07:46:51 +02:00
|
|
|
|
|
|
|
|
|
|
|
# search and found slackbuilds packages links from http://slackbuilds.org
|
2014-05-30 11:27:34 +02:00
|
|
|
def SBo_search_pkg(name):
|
2014-06-20 03:43:40 +02:00
|
|
|
search_name = re.escape(name)
|
|
|
|
search_name = ">" + search_name + "<"
|
2014-05-23 07:46:51 +02:00
|
|
|
|
2014-06-20 03:43:40 +02:00
|
|
|
toolbar_width = len(repository)
|
|
|
|
sys.stdout.write(
|
|
|
|
"Searching `" + name + "` from slackbuilds.org .%s " %
|
|
|
|
(" " * toolbar_width))
|
2014-05-23 07:46:51 +02:00
|
|
|
|
2014-06-20 03:43:40 +02:00
|
|
|
sys.stdout.flush()
|
|
|
|
sys.stdout.write("\b" * (toolbar_width + 1))
|
|
|
|
for kind in repository:
|
|
|
|
sys.stdout.write(".")
|
|
|
|
sys.stdout.flush()
|
|
|
|
SBo_url_sub = SBo_url + kind + "/"
|
|
|
|
find_SBo = re.findall(search_name, url_read(SBo_url_sub))
|
2014-05-23 07:46:51 +02:00
|
|
|
|
2014-06-20 03:43:40 +02:00
|
|
|
find_SBo = rmv_unused(" ".join(find_SBo))
|
2014-05-23 07:46:51 +02:00
|
|
|
|
2014-06-20 03:43:40 +02:00
|
|
|
if name in find_SBo:
|
|
|
|
return SBo_url_sub + name + "/"
|
2014-05-23 07:46:51 +02:00
|
|
|
|
|
|
|
|
|
|
|
# find slackbuild download
|
2014-05-30 11:27:34 +02:00
|
|
|
def SBo_slackbuild_dwn(SBo_url, name):
|
2014-06-20 03:43:40 +02:00
|
|
|
SBo_url = SBo_url.replace(name + "/", name + ".tar.gz")
|
2014-05-23 07:46:51 +02:00
|
|
|
|
2014-06-20 03:43:40 +02:00
|
|
|
return SBo_url.replace("repository", "slackbuilds")
|
2014-05-23 07:46:51 +02:00
|
|
|
|
|
|
|
|
|
|
|
# find source downloads
|
2014-05-30 11:27:34 +02:00
|
|
|
def SBo_source_dwn(SBo_url, name):
|
2014-06-20 03:43:40 +02:00
|
|
|
read_info = url_read(
|
|
|
|
(SBo_url +
|
|
|
|
name +
|
|
|
|
".info").replace(
|
|
|
|
"repository",
|
|
|
|
"slackbuilds"))
|
2014-06-06 14:49:33 +02:00
|
|
|
|
2014-06-20 03:43:40 +02:00
|
|
|
if arch == "x86_64":
|
|
|
|
for line in read_info.splitlines():
|
|
|
|
if line.startswith('DOWNLOAD_x86_64='):
|
|
|
|
if len(line) > 18:
|
2014-05-23 07:46:51 +02:00
|
|
|
|
2014-06-20 03:43:40 +02:00
|
|
|
return line[17:-1]
|
2014-05-23 07:46:51 +02:00
|
|
|
|
2014-06-20 03:43:40 +02:00
|
|
|
for line in read_info.splitlines():
|
|
|
|
if line.startswith('DOWNLOAD='):
|
2014-05-23 07:46:51 +02:00
|
|
|
|
2014-06-20 03:43:40 +02:00
|
|
|
return line[10:-1]
|
2014-05-23 07:46:51 +02:00
|
|
|
|
|
|
|
|
|
|
|
# find extra source downloads
|
2014-05-30 11:27:34 +02:00
|
|
|
def SBo_extra_dwn(SBo_url, name):
|
2014-06-20 03:43:40 +02:00
|
|
|
read_info = url_read(
|
|
|
|
(SBo_url +
|
|
|
|
name +
|
|
|
|
".info").replace(
|
|
|
|
"repository",
|
|
|
|
"slackbuilds"))
|
2014-06-07 15:46:06 +02:00
|
|
|
|
2014-06-20 03:43:40 +02:00
|
|
|
results = []
|
2014-05-23 07:46:51 +02:00
|
|
|
|
2014-06-20 03:43:40 +02:00
|
|
|
for line in read_info.splitlines():
|
|
|
|
if line.startswith(' '):
|
|
|
|
line = line[:-1].replace(" ", "")
|
2014-06-06 14:49:33 +02:00
|
|
|
|
2014-06-20 03:43:40 +02:00
|
|
|
if line.startswith('http'):
|
|
|
|
results.append(line)
|
2014-06-06 14:49:33 +02:00
|
|
|
|
2014-06-20 03:43:40 +02:00
|
|
|
if line.startswith('ftp'):
|
|
|
|
results.append(line)
|
2014-05-23 07:46:51 +02:00
|
|
|
|
2014-06-20 03:43:40 +02:00
|
|
|
return results
|
2014-05-23 07:46:51 +02:00
|
|
|
|
|
|
|
|
|
|
|
# search for package requirements
|
2014-05-30 11:27:34 +02:00
|
|
|
def SBo_requires_pkg(SBo_url, name):
|
2014-06-20 03:43:40 +02:00
|
|
|
read_info = url_read(
|
|
|
|
(SBo_url +
|
|
|
|
name +
|
|
|
|
".info").replace(
|
|
|
|
"repository",
|
|
|
|
"slackbuilds"))
|
2014-05-23 07:46:51 +02:00
|
|
|
|
2014-06-20 03:43:40 +02:00
|
|
|
for line in read_info.splitlines():
|
|
|
|
if line.startswith('REQUIRES="'):
|
2014-05-23 07:46:51 +02:00
|
|
|
|
2014-06-20 03:43:40 +02:00
|
|
|
return line[10:-1]
|
2014-05-23 07:46:51 +02:00
|
|
|
|
|
|
|
|
|
|
|
# search for package dependencies
|
2014-05-30 11:27:34 +02:00
|
|
|
def SBo_dependencies_pkg(name):
|
2014-06-20 03:43:40 +02:00
|
|
|
if name != "%README%":
|
|
|
|
SBo_url = SBo_search_pkg(name)
|
|
|
|
|
|
|
|
if SBo_url is None:
|
|
|
|
print ("\n")
|
|
|
|
print (
|
|
|
|
"{}The {}'{}'{} not found{}\n".format(
|
|
|
|
colors.RED,
|
|
|
|
colors.CYAN,
|
|
|
|
name,
|
|
|
|
colors.RED,
|
|
|
|
colors.ENDC))
|
2014-05-28 16:35:41 +02:00
|
|
|
|
2014-06-20 03:43:40 +02:00
|
|
|
else:
|
|
|
|
SBo_req = SBo_requires_pkg(SBo_url, name)
|
|
|
|
dependencies = SBo_req.split()
|
2014-05-28 16:35:41 +02:00
|
|
|
|
2014-06-20 03:43:40 +02:00
|
|
|
if dependencies != []:
|
|
|
|
dep_results.append(dependencies)
|
2014-05-28 16:35:41 +02:00
|
|
|
|
2014-06-20 03:43:40 +02:00
|
|
|
for line in dependencies:
|
|
|
|
print
|
|
|
|
SBo_dependencies_pkg(line)
|
2014-05-28 16:35:41 +02:00
|
|
|
|
2014-06-20 03:43:40 +02:00
|
|
|
return dep_results
|
2014-05-28 16:35:41 +02:00
|
|
|
|
|
|
|
|
|
|
|
# search for package dependencies
|
2014-05-30 11:27:34 +02:00
|
|
|
def SBo_dependencies_links_pkg(name):
|
2014-06-20 03:43:40 +02:00
|
|
|
if name != "%README%":
|
|
|
|
SBo_url = SBo_search_pkg(name)
|
|
|
|
|
|
|
|
if SBo_url is None:
|
|
|
|
print ("\n")
|
|
|
|
print (
|
|
|
|
"{}The {}`{}`{} not found{}\n".format(
|
|
|
|
colors.RED,
|
|
|
|
colors.CYAN,
|
|
|
|
name,
|
|
|
|
colors.RED,
|
|
|
|
colors.ENDC))
|
2014-05-23 07:46:51 +02:00
|
|
|
|
2014-06-20 03:43:40 +02:00
|
|
|
else:
|
|
|
|
version = ("@" + SBo_version_pkg(SBo_url, name)).split()
|
|
|
|
SBo_dwn = SBo_slackbuild_dwn(SBo_url, name).split()
|
|
|
|
source_dwn = SBo_source_dwn(SBo_url, name).split()
|
|
|
|
extra_dwn = SBo_extra_dwn(SBo_url, name)
|
|
|
|
SBo_req = SBo_requires_pkg(SBo_url, name).split()
|
2014-05-23 07:46:51 +02:00
|
|
|
|
2014-06-20 03:43:40 +02:00
|
|
|
if extra_dwn != []:
|
|
|
|
flag = ("extra" + str(len(extra_dwn))).split()
|
|
|
|
dep_links_results.append(flag)
|
2014-05-29 15:10:01 +02:00
|
|
|
|
2014-06-20 03:43:40 +02:00
|
|
|
dep_links_results.append(extra_dwn)
|
|
|
|
dep_links_results.append(version)
|
|
|
|
dep_links_results.append(source_dwn)
|
|
|
|
dep_links_results.append(SBo_dwn)
|
2014-05-23 07:46:51 +02:00
|
|
|
|
2014-06-20 03:43:40 +02:00
|
|
|
if SBo_req != []:
|
|
|
|
dep_links_results.append(SBo_req)
|
2014-05-23 07:46:51 +02:00
|
|
|
|
2014-06-20 03:43:40 +02:00
|
|
|
for line in SBo_req:
|
|
|
|
print
|
|
|
|
SBo_dependencies_links_pkg(line)
|
2014-05-23 07:46:51 +02:00
|
|
|
|
2014-06-20 03:43:40 +02:00
|
|
|
return dep_links_results
|
2014-05-23 07:46:51 +02:00
|
|
|
|
|
|
|
|
|
|
|
# find from www.slackbuilds.org the version of the package
|
2014-05-30 11:27:34 +02:00
|
|
|
def SBo_version_pkg(SBo_url, name):
|
2014-06-20 03:43:40 +02:00
|
|
|
read_info = url_read(
|
|
|
|
(SBo_url +
|
|
|
|
name +
|
|
|
|
".info").replace(
|
|
|
|
"repository",
|
|
|
|
"slackbuilds"))
|
2014-05-23 07:46:51 +02:00
|
|
|
|
2014-06-20 03:43:40 +02:00
|
|
|
for line in read_info.splitlines():
|
|
|
|
if line.startswith('VERSION="'):
|
|
|
|
return line[9:-1]
|
2014-05-23 07:46:51 +02:00
|
|
|
|
|
|
|
|
2014-06-03 21:33:49 +02:00
|
|
|
# build packages with extra source
|
|
|
|
def build_extra_pkg(script, source, extra):
|
2014-06-20 03:43:40 +02:00
|
|
|
pkg_name = script.replace(".tar.gz", "")
|
|
|
|
|
|
|
|
path = subprocess.check_output(["pwd"], shell=True).replace("\n", "/")
|
|
|
|
try:
|
|
|
|
tar = tarfile.open(script)
|
|
|
|
tar.extractall()
|
|
|
|
tar.close()
|
|
|
|
shutil.copy2(source, pkg_name)
|
|
|
|
|
|
|
|
for es in extra:
|
|
|
|
shutil.copy2(es, pkg_name)
|
|
|
|
|
|
|
|
os.chdir(path + pkg_name)
|
|
|
|
os.system(
|
|
|
|
"sh {}{}{}".format(
|
|
|
|
path,
|
|
|
|
pkg_name +
|
|
|
|
"/",
|
|
|
|
pkg_name +
|
|
|
|
".SlackBuild"))
|
|
|
|
except (OSError, IOError):
|
|
|
|
print
|
|
|
|
print (
|
|
|
|
"{}Wrong file name, Please try again...{}\n".format(
|
|
|
|
colors.RED,
|
|
|
|
colors.ENDC))
|
2014-06-03 21:33:49 +02:00
|
|
|
|
2014-05-23 07:46:51 +02:00
|
|
|
|
|
|
|
# auto build package from slackbuild script
|
|
|
|
def build_package(script, source):
|
2014-06-20 03:43:40 +02:00
|
|
|
pkg_name = script.replace(".tar.gz", "")
|
|
|
|
|
|
|
|
path = subprocess.check_output(["pwd"], shell=True).replace("\n", "/")
|
|
|
|
try:
|
|
|
|
tar = tarfile.open(script)
|
|
|
|
tar.extractall()
|
|
|
|
tar.close()
|
|
|
|
shutil.copy2(source, pkg_name)
|
|
|
|
os.chdir(path + pkg_name)
|
|
|
|
os.system(
|
|
|
|
"sh {}{}{}".format(
|
|
|
|
path,
|
|
|
|
pkg_name +
|
|
|
|
"/",
|
|
|
|
pkg_name +
|
|
|
|
".SlackBuild"))
|
|
|
|
os.chdir(path)
|
|
|
|
except (OSError, IOError):
|
|
|
|
print
|
|
|
|
print (
|
|
|
|
"{}Wrong file name, Please try again...{}\n".format(
|
|
|
|
colors.RED,
|
|
|
|
colors.ENDC))
|
2014-05-23 07:46:51 +02:00
|
|
|
|
|
|
|
|
|
|
|
# print version
|
|
|
|
def pkg_version():
|
2014-06-24 16:06:01 +02:00
|
|
|
print ("Version : {}".format(__version__))
|
|
|
|
print ("Licence : {}".format(__license__))
|
|
|
|
print ("Email : {}".format(__email__))
|
2014-05-23 07:46:51 +02:00
|
|
|
|
|
|
|
|
2014-06-20 03:43:40 +02:00
|
|
|
# build packages
|
2014-05-23 07:46:51 +02:00
|
|
|
def pkg_slackbuild(name):
|
2014-06-20 03:43:40 +02:00
|
|
|
s_user(getpass.getuser())
|
|
|
|
if len(name) == 2:
|
|
|
|
build_package(name[0], name[1])
|
|
|
|
elif len(name) > 2:
|
|
|
|
build_extra_pkg(name[0],
|
|
|
|
name[1], name[2:])
|
|
|
|
else:
|
|
|
|
print
|
|
|
|
print ("{}Must enter at least two arguments{}\n".format(colors.RED,
|
|
|
|
colors.ENDC))
|
2014-05-23 07:46:51 +02:00
|
|
|
|
|
|
|
|
|
|
|
# view list of installed packages
|
|
|
|
def pkg_list(name):
|
2014-06-20 03:43:40 +02:00
|
|
|
if "all" in name:
|
|
|
|
print
|
|
|
|
os.chdir(packages)
|
|
|
|
os.system("ls * | more")
|
|
|
|
print
|
2014-05-23 07:46:51 +02:00
|
|
|
|
2014-06-20 03:43:40 +02:00
|
|
|
if "sbo" in name:
|
|
|
|
print
|
|
|
|
os.chdir(packages)
|
|
|
|
os.system("ls * | grep 'SBo' | more")
|
|
|
|
print
|
2014-05-23 07:46:51 +02:00
|
|
|
|
|
|
|
|
|
|
|
# find all dependencies
|
|
|
|
def pkg_tracking(name):
|
2014-06-20 03:43:40 +02:00
|
|
|
dependencies = SBo_dependencies_pkg(name)
|
|
|
|
if dependencies is None:
|
|
|
|
pass
|
|
|
|
|
|
|
|
elif dependencies == []:
|
|
|
|
print ("\n")
|
|
|
|
print ("{}No dependencies\n{}".format(colors.GREEN, colors.ENDC))
|
|
|
|
else:
|
|
|
|
print ("\n")
|
|
|
|
pkg_len = len(name) + 18
|
|
|
|
print ("+" + "=" * pkg_len)
|
|
|
|
print (
|
|
|
|
"| {}`{}` {}dependencies :{}".format(
|
|
|
|
colors.CYAN,
|
|
|
|
name,
|
|
|
|
colors.YELLOW,
|
|
|
|
colors.ENDC))
|
|
|
|
print ("+" + "=" * pkg_len)
|
|
|
|
dependencies.reverse()
|
|
|
|
|
|
|
|
print (" |")
|
|
|
|
for i in range(len(dependencies)):
|
|
|
|
found = " --", str(len(dependencies[i])), " ".join(dependencies[i])
|
|
|
|
print (" |")
|
|
|
|
print " ".join(found)
|
|
|
|
print
|
2014-05-24 09:09:34 +02:00
|
|
|
|
2014-05-23 07:46:51 +02:00
|
|
|
|
2014-06-20 03:43:40 +02:00
|
|
|
# find from SBo repositority www.slackbuild.org
|
|
|
|
def SBo_network(name):
|
|
|
|
SBo_url = SBo_search_pkg(name)
|
|
|
|
if SBo_url is None:
|
|
|
|
print ("\n")
|
|
|
|
print (
|
|
|
|
"{}The {}`{}`{} not found{}\n".format(
|
|
|
|
colors.RED,
|
|
|
|
colors.CYAN,
|
|
|
|
name,
|
|
|
|
colors.RED,
|
|
|
|
colors.ENDC))
|
|
|
|
else:
|
|
|
|
|
|
|
|
SBo_req = SBo_requires_pkg(SBo_url, name)
|
|
|
|
SBo_dwn = SBo_slackbuild_dwn(SBo_url, name)
|
|
|
|
SBo_version = SBo_version_pkg(SBo_url, name)
|
|
|
|
source_dwn = SBo_source_dwn(SBo_url, name)
|
|
|
|
extra_dwn = " ".join(SBo_extra_dwn(SBo_url, name))
|
|
|
|
|
|
|
|
SBo_name_len = len(name)
|
|
|
|
SBo_url_len = (len(SBo_url) + SBo_name_len + 21)
|
|
|
|
|
|
|
|
print ("\n")
|
|
|
|
print ("+" + "=" * SBo_url_len)
|
|
|
|
print ("| {}The {}`{}`{} found in --> {}".format(colors.GREEN,
|
|
|
|
colors.CYAN,
|
|
|
|
name,
|
|
|
|
colors.GREEN,
|
|
|
|
colors.ENDC + SBo_url))
|
|
|
|
print ("+" + "=" * SBo_url_len)
|
|
|
|
print ("| {}Download SlackBuild : {}{}".format(colors.GREEN,
|
|
|
|
colors.ENDC, SBo_dwn))
|
|
|
|
print ("| {}Source Downloads : {}{}".format(colors.GREEN,
|
|
|
|
colors.ENDC, source_dwn))
|
|
|
|
print ("| {}Extra Downloads : {}{}".format(colors.GREEN,
|
|
|
|
colors.ENDC, extra_dwn))
|
|
|
|
print ("| {}Package requirements : {}{}".format(colors.YELLOW,
|
|
|
|
colors.ENDC, SBo_req))
|
|
|
|
print ("+" + "=" * SBo_url_len)
|
|
|
|
print (
|
|
|
|
" {}R{}EADME View the README file".format(
|
|
|
|
colors.RED,
|
|
|
|
colors.ENDC))
|
|
|
|
print (
|
|
|
|
" {}S{}lackBuild View the SlackBuild file".format(
|
|
|
|
colors.RED,
|
|
|
|
colors.ENDC))
|
|
|
|
print (
|
|
|
|
" In{}f{}o View the Info file".format(
|
|
|
|
colors.RED,
|
|
|
|
colors.ENDC))
|
|
|
|
print (
|
|
|
|
" {}D{}ownload Download this package".format(
|
|
|
|
colors.RED,
|
|
|
|
colors.ENDC))
|
|
|
|
print (
|
|
|
|
" {}B{}uild Download and build".format(
|
|
|
|
colors.RED,
|
|
|
|
colors.ENDC))
|
|
|
|
print (
|
|
|
|
" {}I{}nstall Download/Build/Install\n".format(colors.RED, colors.ENDC))
|
|
|
|
|
|
|
|
while True:
|
|
|
|
read = raw_input("_ ")
|
|
|
|
|
|
|
|
if read == "D" or read == "d":
|
|
|
|
print
|
|
|
|
print ("{}Start -->{}\n".format(colors.GREEN, colors.ENDC))
|
|
|
|
os.system("wget -N " + SBo_dwn)
|
|
|
|
os.system("wget -N " + source_dwn)
|
|
|
|
|
|
|
|
if extra_dwn != "":
|
|
|
|
os.system("wget " + extra_dwn)
|
|
|
|
|
|
|
|
break
|
|
|
|
|
|
|
|
elif read == "R" or read == "r":
|
|
|
|
site = "README"
|
|
|
|
read_readme(SBo_url, name, site)
|
|
|
|
os.system(
|
|
|
|
"less /tmp/slpkg/readme/" +
|
|
|
|
name +
|
|
|
|
".{}".format(site))
|
|
|
|
|
|
|
|
elif read == "F" or read == "f":
|
|
|
|
site = ".info"
|
|
|
|
read_info_slackbuild(SBo_url, name, site)
|
|
|
|
os.system("less /tmp/slpkg/readme/" + name + "{}".format(site))
|
|
|
|
|
|
|
|
elif read == "S" or read == "s":
|
|
|
|
site = ".SlackBuild"
|
|
|
|
read_info_slackbuild(SBo_url, name, site)
|
|
|
|
os.system("less /tmp/slpkg/readme/" + name + "{}".format(site))
|
|
|
|
|
|
|
|
elif read == "B" or read == "b":
|
|
|
|
s_user(getpass.getuser())
|
|
|
|
script = get_file(SBo_dwn, "/")
|
|
|
|
source = get_file(source_dwn, "/")
|
|
|
|
print
|
|
|
|
print ("{}Start -->{}\n".format(colors.GREEN, colors.ENDC))
|
|
|
|
os.system("wget -N " + SBo_dwn)
|
|
|
|
os.system("wget -N " + source_dwn)
|
|
|
|
|
|
|
|
extra = []
|
|
|
|
if extra_dwn != "":
|
|
|
|
os.system("wget -N " + extra_dwn)
|
|
|
|
extra_dwn = extra_dwn.split()
|
|
|
|
for link in extra_dwn:
|
|
|
|
extra.append(get_file(link, "/"))
|
|
|
|
|
|
|
|
build_extra_pkg(script, source, extra)
|
|
|
|
break
|
|
|
|
|
|
|
|
build_package(script, source)
|
|
|
|
break
|
|
|
|
|
|
|
|
elif read == "I" or read == "i":
|
|
|
|
s_user(getpass.getuser())
|
|
|
|
pkg_for_install = name + "-" + SBo_version
|
|
|
|
|
|
|
|
if find_package(pkg_for_install, packages) == []:
|
|
|
|
script = get_file(SBo_dwn, "/")
|
|
|
|
source = get_file(source_dwn, "/")
|
|
|
|
print
|
|
|
|
print ("{}Start -->{}\n".format(colors.GREEN, colors.ENDC))
|
|
|
|
os.system("wget -N " + SBo_dwn)
|
|
|
|
os.system("wget -N " + source_dwn)
|
|
|
|
|
|
|
|
extra = []
|
|
|
|
if extra_dwn != "":
|
|
|
|
os.system("wget -N " + extra_dwn)
|
|
|
|
extra_dwn = extra_dwn.split()
|
|
|
|
for link in extra_dwn:
|
|
|
|
extra.append(get_file(link, "/"))
|
|
|
|
|
|
|
|
build_extra_pkg(script, source, extra)
|
|
|
|
|
|
|
|
install_pkg = tmp + pkg_for_install + \
|
|
|
|
SBo_arch + SBo_tag + SBo_filetype
|
|
|
|
os.system(
|
|
|
|
"upgradepkg --install-new {}".format(install_pkg))
|
|
|
|
break
|
|
|
|
|
|
|
|
build_package(script, source)
|
|
|
|
|
|
|
|
install_pkg = tmp + pkg_for_install + \
|
|
|
|
SBo_arch + SBo_tag + SBo_filetype
|
|
|
|
os.system(
|
|
|
|
"upgradepkg --install-new {}".format(install_pkg))
|
|
|
|
break
|
|
|
|
else:
|
|
|
|
print
|
|
|
|
print (
|
|
|
|
"{}The package {}`{}`{} is arlready installed{}".format(
|
|
|
|
colors.YELLOW,
|
|
|
|
colors.CYAN,
|
|
|
|
pkg_for_install,
|
|
|
|
colors.YELLOW,
|
|
|
|
colors.ENDC))
|
|
|
|
print
|
|
|
|
break
|
2014-05-28 16:35:41 +02:00
|
|
|
|
2014-06-20 03:43:40 +02:00
|
|
|
else:
|
|
|
|
break
|
2014-05-23 07:46:51 +02:00
|
|
|
|
|
|
|
|
2014-06-20 03:43:40 +02:00
|
|
|
# check if packages from www.slackbuilds.org is up to date
|
|
|
|
def SBo_check(name):
|
|
|
|
SBo_file = " ".join(find_package(name, packages))
|
|
|
|
|
|
|
|
if SBo_file == "":
|
|
|
|
print
|
|
|
|
print (
|
|
|
|
" {}The package {}`{}`{} not found on your system{}\n".format(
|
|
|
|
colors.RED,
|
|
|
|
colors.CYAN,
|
|
|
|
name,
|
|
|
|
colors.RED,
|
|
|
|
colors.ENDC))
|
|
|
|
|
|
|
|
else:
|
|
|
|
SBo_url = SBo_search_pkg(name)
|
|
|
|
|
|
|
|
if SBo_url is None:
|
|
|
|
print ("\n")
|
|
|
|
print (
|
|
|
|
"{}The {}`{}`{} not found{}\n".format(
|
|
|
|
colors.RED,
|
|
|
|
colors.CYAN,
|
|
|
|
name,
|
|
|
|
colors.RED,
|
|
|
|
colors.ENDC))
|
2014-05-23 07:46:51 +02:00
|
|
|
|
|
|
|
else:
|
2014-06-20 03:43:40 +02:00
|
|
|
SBo_version = SBo_version_pkg(SBo_url, name)
|
|
|
|
SBo_dwn = SBo_slackbuild_dwn(SBo_url, name)
|
|
|
|
source_dwn = SBo_source_dwn(SBo_url, name)
|
|
|
|
extra_dwn = " ".join(SBo_extra_dwn(SBo_url, name))
|
2014-06-06 11:42:44 +02:00
|
|
|
|
2014-06-20 03:43:40 +02:00
|
|
|
name_len = len(name)
|
|
|
|
arch_len = len(arch)
|
|
|
|
SBo_file = SBo_file[name_len + 1:-arch_len - 7]
|
2014-06-07 15:46:06 +02:00
|
|
|
|
2014-06-20 03:43:40 +02:00
|
|
|
if SBo_version > SBo_file:
|
2014-05-23 07:46:51 +02:00
|
|
|
print ("\n")
|
2014-06-20 03:43:40 +02:00
|
|
|
print (
|
|
|
|
"{} New version is available !!!{}".format(
|
|
|
|
colors.YELLOW,
|
|
|
|
colors.ENDC))
|
|
|
|
print ("+" + "=" * 50)
|
|
|
|
print ("| {} {}".format(name, SBo_version))
|
|
|
|
print ("+" + "=" * 50)
|
|
|
|
print
|
2014-05-23 07:46:51 +02:00
|
|
|
|
2014-06-20 03:43:40 +02:00
|
|
|
read = raw_input("Would you like to install ? [Y/y] ")
|
2014-05-23 07:46:51 +02:00
|
|
|
|
2014-06-20 03:43:40 +02:00
|
|
|
if read == "Y" or read == "y":
|
|
|
|
s_user(getpass.getuser())
|
|
|
|
pkg_for_install = name + "-" + SBo_version
|
|
|
|
script = get_file(SBo_dwn, "/")
|
|
|
|
source = get_file(source_dwn, "/")
|
|
|
|
print
|
|
|
|
print ("{}Start -->{}\n".format(colors.GREEN, colors.ENDC))
|
|
|
|
os.system("wget -N " + SBo_dwn)
|
|
|
|
os.system("wget -N " + source_dwn)
|
2014-06-05 12:25:50 +02:00
|
|
|
|
2014-06-20 03:43:40 +02:00
|
|
|
extra = []
|
|
|
|
if extra_dwn != "":
|
|
|
|
os.system("wget -N " + extra_dwn)
|
|
|
|
extra_dwn = extra_dwn.split()
|
|
|
|
for link in extra_dwn:
|
|
|
|
extra.append(get_file(link, "/"))
|
2014-05-23 07:46:51 +02:00
|
|
|
|
2014-06-20 03:43:40 +02:00
|
|
|
build_extra_pkg(script, source, extra)
|
2014-06-05 12:25:50 +02:00
|
|
|
|
2014-06-20 03:43:40 +02:00
|
|
|
install_pkg = tmp + pkg_for_install + \
|
|
|
|
SBo_arch + SBo_tag + SBo_filetype
|
|
|
|
os.system(
|
|
|
|
"upgradepkg --install-new {}".format(install_pkg))
|
|
|
|
sys.exit()
|
2014-05-23 07:46:51 +02:00
|
|
|
|
2014-06-20 03:43:40 +02:00
|
|
|
build_package(script, source)
|
2014-05-23 07:46:51 +02:00
|
|
|
|
2014-06-20 03:43:40 +02:00
|
|
|
install_pkg = tmp + pkg_for_install + \
|
|
|
|
SBo_arch + SBo_tag + SBo_filetype
|
|
|
|
os.system(
|
|
|
|
"upgradepkg --install-new {}".format(install_pkg))
|
2014-06-05 12:25:50 +02:00
|
|
|
|
2014-06-20 03:43:40 +02:00
|
|
|
print
|
2014-06-05 12:25:50 +02:00
|
|
|
|
2014-06-20 03:43:40 +02:00
|
|
|
else:
|
|
|
|
print ("\n")
|
|
|
|
print (
|
|
|
|
"{}Your package is up to date{}\n".format(
|
|
|
|
colors.GREEN,
|
|
|
|
colors.ENDC))
|
2014-06-05 12:25:50 +02:00
|
|
|
|
|
|
|
|
2014-06-20 03:43:40 +02:00
|
|
|
# find package and dependencies download, build and install
|
|
|
|
def SBo_build(name):
|
|
|
|
s_user(getpass.getuser())
|
|
|
|
dependencies_links = SBo_dependencies_links_pkg(name)
|
|
|
|
|
|
|
|
''' crate one list for all '''
|
|
|
|
if dependencies_links is None:
|
|
|
|
sys.exit()
|
|
|
|
|
|
|
|
elif dependencies_links != []:
|
|
|
|
results = []
|
|
|
|
for i in range(len(dependencies_links)):
|
|
|
|
for j in range(len(dependencies_links[i])):
|
|
|
|
results.append(dependencies_links[i][j])
|
|
|
|
|
|
|
|
''' grep only links from list '''
|
|
|
|
dwn_link = []
|
|
|
|
for link in results:
|
|
|
|
if link.startswith('http'):
|
|
|
|
dwn_link.append(link)
|
|
|
|
if link.startswith('ftp'):
|
|
|
|
dwn_link.append(link)
|
|
|
|
|
|
|
|
''' grep the version '''
|
|
|
|
version = []
|
|
|
|
for ver in results:
|
|
|
|
if ver.startswith("@"):
|
|
|
|
ver = ver.replace("@", "")
|
|
|
|
version.append(ver)
|
|
|
|
|
|
|
|
''' upside-down lists '''
|
|
|
|
version .reverse()
|
|
|
|
dwn_link.reverse()
|
|
|
|
|
|
|
|
''' get tar archives from link '''
|
|
|
|
files = []
|
|
|
|
for i in range(len(dwn_link)):
|
|
|
|
files.append(get_file(dwn_link[i], "/"))
|
|
|
|
|
|
|
|
''' removes archive type and store the package name '''
|
|
|
|
filename = []
|
|
|
|
y = 0
|
|
|
|
for i in range(len(files) / 2):
|
|
|
|
if files[y].endswith("tar.gz"):
|
|
|
|
file = files[y]
|
|
|
|
file = file[:-7]
|
|
|
|
filename.append(file)
|
|
|
|
y += 2
|
|
|
|
|
|
|
|
''' link sbo filename with version to create package installation '''
|
|
|
|
filename_version = []
|
|
|
|
for i in range(len(filename)):
|
|
|
|
filename_version.append(filename[i] + "-" + version[i])
|
|
|
|
|
|
|
|
''' remove links and files if packages already installed
|
|
|
|
and keep lists for report'''
|
|
|
|
i = 0
|
|
|
|
pkg_for_install = []
|
|
|
|
pkg_already_installed = []
|
2014-06-05 12:25:50 +02:00
|
|
|
|
2014-06-20 03:43:40 +02:00
|
|
|
for file in filename_version:
|
|
|
|
if find_package(file, packages) == []:
|
|
|
|
i += 2
|
|
|
|
pkg_for_install.append(file)
|
2014-06-06 14:49:33 +02:00
|
|
|
|
2014-06-20 03:43:40 +02:00
|
|
|
else:
|
|
|
|
pkg_already_installed.append(file)
|
|
|
|
for j in range(0, 2):
|
|
|
|
dwn_link.pop(i)
|
|
|
|
files.pop(i)
|
|
|
|
|
|
|
|
''' remove double links '''
|
|
|
|
dwn_link = set(dwn_link)
|
|
|
|
|
|
|
|
''' download links if not exist or previously than server'''
|
|
|
|
for link in dwn_link:
|
|
|
|
print
|
|
|
|
print ("{}Start --> \n{}".format(colors.GREEN, colors.ENDC))
|
|
|
|
os.system("wget -N {}".format(link))
|
|
|
|
|
|
|
|
print ("\n")
|
|
|
|
|
|
|
|
''' build packages and install slackware packages '''
|
|
|
|
if pkg_for_install == []:
|
|
|
|
for pkg in filename_version:
|
|
|
|
print (
|
|
|
|
"{}The package {}`{}`{} is already installed{}".format(
|
|
|
|
colors.YELLOW,
|
|
|
|
colors.CYAN,
|
|
|
|
pkg,
|
|
|
|
colors.YELLOW,
|
|
|
|
colors.ENDC))
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
''' check for extra sources '''
|
|
|
|
if results[0].startswith("extra"):
|
|
|
|
extra_Num = int(results[0].replace("extra", ""))
|
|
|
|
i = 0
|
|
|
|
for i in range(len(files) / 2):
|
|
|
|
if len(files) == extra_Num + 2:
|
|
|
|
script = files[0]
|
|
|
|
source = files[1]
|
|
|
|
extra = files[2:]
|
|
|
|
build_extra_pkg(script, source, extra)
|
|
|
|
|
|
|
|
install_pkg = tmp + \
|
|
|
|
pkg_for_install[i] + SBo_arch + SBo_tag + SBo_filetype
|
|
|
|
os.system(
|
|
|
|
"upgradepkg --install-new {}".format(install_pkg))
|
|
|
|
break
|
2014-06-05 12:25:50 +02:00
|
|
|
|
2014-06-20 03:43:40 +02:00
|
|
|
else:
|
2014-06-05 12:25:50 +02:00
|
|
|
|
2014-06-20 03:43:40 +02:00
|
|
|
script = files[0]
|
|
|
|
source = files[1]
|
|
|
|
build_package(script, source)
|
2014-06-05 12:25:50 +02:00
|
|
|
|
2014-06-20 03:43:40 +02:00
|
|
|
install_pkg = tmp + \
|
|
|
|
pkg_for_install[i] + SBo_arch + SBo_tag + SBo_filetype
|
|
|
|
os.system(
|
|
|
|
"upgradepkg --install-new {}".format(install_pkg))
|
2014-05-23 07:46:51 +02:00
|
|
|
|
2014-06-20 03:43:40 +02:00
|
|
|
for j in range(0, 2):
|
|
|
|
files.pop(0)
|
2014-05-23 07:46:51 +02:00
|
|
|
|
2014-06-20 03:43:40 +02:00
|
|
|
else:
|
2014-05-23 07:46:51 +02:00
|
|
|
|
2014-06-20 03:43:40 +02:00
|
|
|
i = 0
|
|
|
|
for i in range(len(files) / 2):
|
|
|
|
script = files[0]
|
|
|
|
source = files[1]
|
|
|
|
build_package(script, source)
|
|
|
|
|
|
|
|
install_pkg = tmp + \
|
|
|
|
pkg_for_install[i] + SBo_arch + SBo_tag + SBo_filetype
|
|
|
|
os.system("upgradepkg --install-new {}".format(install_pkg))
|
|
|
|
|
|
|
|
for j in range(0, 2):
|
|
|
|
files.pop(0)
|
|
|
|
|
|
|
|
for pkg in pkg_for_install:
|
|
|
|
if find_package(pkg, packages) != []:
|
|
|
|
print (
|
|
|
|
"{}The package {}`{}`{} was installed{}".format(
|
|
|
|
colors.GREEN,
|
|
|
|
colors.CYAN,
|
|
|
|
pkg,
|
|
|
|
colors.GREEN,
|
|
|
|
colors.ENDC))
|
|
|
|
for pkg in pkg_already_installed:
|
|
|
|
if find_package(pkg, packages) != []:
|
|
|
|
print (
|
|
|
|
"{}The package {}`{}`{} is arlready installed{}".format(
|
|
|
|
colors.YELLOW,
|
|
|
|
colors.CYAN,
|
|
|
|
pkg,
|
|
|
|
colors.YELLOW,
|
|
|
|
colors.ENDC))
|
2014-06-03 04:22:11 +02:00
|
|
|
|
2014-06-20 03:43:40 +02:00
|
|
|
print
|
2014-06-03 04:22:11 +02:00
|
|
|
|
|
|
|
|
2014-05-23 07:46:51 +02:00
|
|
|
# install binary package
|
|
|
|
def pkg_install(name):
|
2014-06-20 03:43:40 +02:00
|
|
|
s_user(getpass.getuser())
|
|
|
|
for i in range(len(name)):
|
|
|
|
try:
|
|
|
|
print
|
|
|
|
print subprocess.check_output('installpkg %s' % name[i], shell=True)
|
|
|
|
except subprocess.CalledProcessError:
|
|
|
|
print (
|
|
|
|
"{}Cannot install {}`{}`{} file not found\n{}".format(
|
|
|
|
colors.RED,
|
|
|
|
colors.CYAN,
|
|
|
|
name[i],
|
|
|
|
colors.RED,
|
|
|
|
colors.ENDC))
|
2014-05-23 07:46:51 +02:00
|
|
|
|
|
|
|
|
|
|
|
# upgrade package with new
|
|
|
|
def pkg_upgrade(name):
|
2014-06-20 03:43:40 +02:00
|
|
|
s_user(getpass.getuser())
|
|
|
|
for i in range(len(name)):
|
|
|
|
try:
|
|
|
|
print subprocess.check_output('upgradepkg --install-new %s' % name[i], shell=True)
|
|
|
|
except subprocess.CalledProcessError:
|
|
|
|
print
|
|
|
|
print (
|
|
|
|
"{}Cannot install {}`{}`{} file not found\n{}".format(
|
|
|
|
colors.RED,
|
|
|
|
colors.CYAN,
|
|
|
|
name[i],
|
|
|
|
colors.RED,
|
|
|
|
colors.ENDC))
|
2014-05-23 07:46:51 +02:00
|
|
|
|
|
|
|
|
|
|
|
# upgrade package with the same
|
|
|
|
def pkg_reinstall(name):
|
2014-06-20 03:43:40 +02:00
|
|
|
s_user(getpass.getuser())
|
|
|
|
for i in range(len(name)):
|
|
|
|
try:
|
|
|
|
print subprocess.check_output('upgradepkg --reinstall %s' % name[i], shell=True)
|
|
|
|
except subprocess.CalledProcessError:
|
|
|
|
print
|
|
|
|
print (
|
|
|
|
"{}Cannot install {}`{}`{} file not found\n{}".format(
|
|
|
|
colors.RED,
|
|
|
|
colors.CYAN,
|
|
|
|
name[i],
|
|
|
|
colors.RED,
|
|
|
|
colors.ENDC))
|
2014-05-23 07:46:51 +02:00
|
|
|
|
|
|
|
|
|
|
|
# uninstall package
|
|
|
|
def pkg_remove(name):
|
2014-06-20 03:43:40 +02:00
|
|
|
s_user(getpass.getuser())
|
|
|
|
print ("{}!!! WARNING !!!{}".format(colors.RED, colors.ENDC))
|
|
|
|
remove_pkg = raw_input("Are you sure to remove this package(s) [Y/y] ")
|
|
|
|
if remove_pkg == "y" or remove_pkg == "Y":
|
|
|
|
results_removed = []
|
|
|
|
not_found = []
|
|
|
|
for i in range(len(name)):
|
|
|
|
if find_package(name[i], packages) == []:
|
|
|
|
not_found.append(name[i])
|
|
|
|
|
|
|
|
else:
|
|
|
|
os.system("removepkg {}".format(name[i]))
|
|
|
|
results_removed.append(name[i])
|
|
|
|
|
|
|
|
print
|
|
|
|
for file in results_removed:
|
|
|
|
if find_package(file, packages) == []:
|
|
|
|
print (
|
|
|
|
"{}The package {}`{}`{} removed{}".format(
|
|
|
|
colors.YELLOW,
|
|
|
|
colors.CYAN,
|
|
|
|
file,
|
|
|
|
colors.YELLOW,
|
|
|
|
colors.ENDC))
|
|
|
|
for file in not_found:
|
|
|
|
print (
|
|
|
|
"{}The package {}`{}`{} not found{}".format(
|
|
|
|
colors.RED,
|
|
|
|
colors.CYAN,
|
|
|
|
file,
|
|
|
|
colors.RED,
|
|
|
|
colors.ENDC))
|
|
|
|
print
|
2014-05-23 07:46:51 +02:00
|
|
|
|
|
|
|
|
|
|
|
# print find if package installed on your system
|
|
|
|
def pkg_find(name):
|
2014-06-20 03:43:40 +02:00
|
|
|
print
|
|
|
|
for i in range(len(name)):
|
|
|
|
if find_package(name[i], packages) == []:
|
|
|
|
print (
|
|
|
|
"{}The package {}`{}`{} not found{}".format(
|
|
|
|
colors.RED,
|
|
|
|
colors.CYAN,
|
|
|
|
name[i],
|
|
|
|
colors.RED,
|
|
|
|
colors.ENDC))
|
2014-05-23 07:46:51 +02:00
|
|
|
|
2014-06-20 03:43:40 +02:00
|
|
|
else:
|
|
|
|
print (
|
|
|
|
colors.GREEN +
|
|
|
|
"found --> " +
|
|
|
|
colors.ENDC +
|
|
|
|
"\n".join(
|
|
|
|
find_package(
|
|
|
|
name[i],
|
|
|
|
packages)))
|
|
|
|
print
|
2014-05-23 07:46:51 +02:00
|
|
|
|
|
|
|
|
|
|
|
# print the package contents
|
|
|
|
def pkg_display(name):
|
2014-06-20 03:43:40 +02:00
|
|
|
print
|
|
|
|
for i in range(len(name)):
|
|
|
|
if find_package(name[i], packages) == []:
|
|
|
|
print (
|
|
|
|
"{}The package {}`{}`{} not found{}".format(
|
|
|
|
colors.RED,
|
|
|
|
colors.CYAN,
|
|
|
|
name[i],
|
|
|
|
colors.RED,
|
|
|
|
colors.ENDC))
|
2014-05-23 07:46:51 +02:00
|
|
|
|
2014-06-20 03:43:40 +02:00
|
|
|
else:
|
|
|
|
os.system(
|
|
|
|
"cat {}{}".format(
|
|
|
|
packages,
|
|
|
|
"\n".join(
|
|
|
|
find_package(
|
|
|
|
name[i],
|
|
|
|
packages))))
|
|
|
|
print
|
2014-05-23 07:46:51 +02:00
|
|
|
|
|
|
|
|
|
|
|
# main function
|
|
|
|
def main():
|
2014-06-20 03:43:40 +02:00
|
|
|
description = "Utility to help package management in Slackware"
|
|
|
|
parser = argparse.ArgumentParser(description=description)
|
2014-05-28 16:35:41 +02:00
|
|
|
|
2014-06-20 03:43:40 +02:00
|
|
|
parser.add_argument("-v", "--verbose", help="print version and exit",
|
|
|
|
action="store_true")
|
2014-05-28 16:35:41 +02:00
|
|
|
|
2014-06-20 03:43:40 +02:00
|
|
|
parser.add_argument("-a", help="auto build package",
|
|
|
|
type=str, nargs="+", metavar=('script', 'source'))
|
2014-05-28 16:35:41 +02:00
|
|
|
|
2014-06-24 16:06:01 +02:00
|
|
|
parser.add_argument("-l", help="list of installed packages", nargs="+",
|
|
|
|
choices="all sbo".split(), metavar=('all, sbo'))
|
2014-05-28 16:35:41 +02:00
|
|
|
|
2014-06-20 03:43:40 +02:00
|
|
|
parser.add_argument("-t", help="tracking dependencies",
|
|
|
|
type=str, metavar=(''))
|
2014-05-28 16:35:41 +02:00
|
|
|
|
2014-06-20 03:43:40 +02:00
|
|
|
parser.add_argument("-n", help="find from SBo repositority",
|
|
|
|
type=str, metavar=(''))
|
2014-05-23 07:46:51 +02:00
|
|
|
|
2014-06-20 03:43:40 +02:00
|
|
|
parser.add_argument("-c", help="check if your package is up to date",
|
|
|
|
type=str, metavar=(''))
|
2014-05-23 07:46:51 +02:00
|
|
|
|
2014-06-20 03:43:40 +02:00
|
|
|
parser.add_argument("-s", help="download, build & install pkg from SBo",
|
|
|
|
type=str, metavar=(''))
|
2014-05-23 07:46:51 +02:00
|
|
|
|
2014-06-20 03:43:40 +02:00
|
|
|
parser.add_argument("-i", help="install binary packages",
|
|
|
|
type=str, nargs="+", metavar=(''))
|
2014-05-23 07:46:51 +02:00
|
|
|
|
2014-06-20 03:43:40 +02:00
|
|
|
parser.add_argument("-u", help="install-upgrade packages with new",
|
|
|
|
type=str, nargs="+", metavar=(''))
|
2014-05-23 07:46:51 +02:00
|
|
|
|
2014-06-20 03:43:40 +02:00
|
|
|
parser.add_argument("-o", help="reinstall the same packages",
|
|
|
|
type=str, nargs="+", metavar=(''))
|
2014-05-23 07:46:51 +02:00
|
|
|
|
2014-06-20 03:43:40 +02:00
|
|
|
parser.add_argument("-r", help="remove packages",
|
|
|
|
type=str, nargs="+", metavar=(''))
|
2014-05-23 07:46:51 +02:00
|
|
|
|
2014-06-20 03:43:40 +02:00
|
|
|
parser.add_argument("-f", help="find if packages installed",
|
|
|
|
type=str, nargs="+", metavar=(''))
|
2014-05-23 07:46:51 +02:00
|
|
|
|
2014-06-20 03:43:40 +02:00
|
|
|
parser.add_argument("-d", help="display the contents of the packages",
|
|
|
|
type=str, nargs="+", metavar=(''))
|
2014-05-23 07:46:51 +02:00
|
|
|
|
2014-06-20 03:43:40 +02:00
|
|
|
args = parser.parse_args()
|
2014-05-23 07:46:51 +02:00
|
|
|
|
2014-06-20 03:43:40 +02:00
|
|
|
if args.verbose:
|
|
|
|
pkg_version()
|
2014-05-23 07:46:51 +02:00
|
|
|
|
2014-06-20 03:43:40 +02:00
|
|
|
if args.a:
|
|
|
|
pkg_slackbuild(args.a)
|
2014-05-23 07:46:51 +02:00
|
|
|
|
2014-06-20 03:43:40 +02:00
|
|
|
if args.l:
|
|
|
|
pkg_list(args.l)
|
2014-05-28 16:35:41 +02:00
|
|
|
|
2014-06-20 03:43:40 +02:00
|
|
|
if args.t:
|
|
|
|
pkg_tracking(args.t)
|
2014-05-28 16:35:41 +02:00
|
|
|
|
2014-06-20 03:43:40 +02:00
|
|
|
if args.n:
|
|
|
|
SBo_network(args.n)
|
2014-05-23 07:46:51 +02:00
|
|
|
|
2014-06-20 03:43:40 +02:00
|
|
|
if args.c:
|
|
|
|
SBo_check(args.c)
|
2014-05-23 07:46:51 +02:00
|
|
|
|
2014-06-20 03:43:40 +02:00
|
|
|
if args.s:
|
|
|
|
SBo_build(args.s)
|
2014-05-23 07:46:51 +02:00
|
|
|
|
2014-06-20 03:43:40 +02:00
|
|
|
if args.i:
|
|
|
|
pkg_install(args.i)
|
2014-05-23 07:46:51 +02:00
|
|
|
|
2014-06-20 03:43:40 +02:00
|
|
|
if args.u:
|
|
|
|
pkg_upgrade(args.u)
|
2014-05-23 07:46:51 +02:00
|
|
|
|
2014-06-20 03:43:40 +02:00
|
|
|
if args.o:
|
|
|
|
pkg_reinstall(args.o)
|
2014-05-23 07:46:51 +02:00
|
|
|
|
2014-06-20 03:43:40 +02:00
|
|
|
if args.r:
|
|
|
|
pkg_remove(args.r)
|
2014-05-23 07:46:51 +02:00
|
|
|
|
2014-06-20 03:43:40 +02:00
|
|
|
if args.f:
|
|
|
|
pkg_find(args.f)
|
2014-05-23 07:46:51 +02:00
|
|
|
|
2014-06-20 03:43:40 +02:00
|
|
|
if args.d:
|
|
|
|
pkg_display(args.d)
|
2014-05-23 07:46:51 +02:00
|
|
|
|
2014-06-20 03:43:40 +02:00
|
|
|
if not any([args.verbose,
|
|
|
|
args.s,
|
|
|
|
args.t,
|
|
|
|
args.c,
|
|
|
|
args.n,
|
|
|
|
args.o,
|
|
|
|
args.i,
|
|
|
|
args.u,
|
|
|
|
args.a,
|
|
|
|
args.r,
|
|
|
|
args.l,
|
|
|
|
args.f,
|
|
|
|
args.d]):
|
|
|
|
os.system("slpkg -h")
|
2014-05-23 07:46:51 +02:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|