fix messages

This commit is contained in:
dslackw 2014-07-23 17:01:58 +03:00
parent d34983cb57
commit 67c0b59dd5
16 changed files with 153 additions and 82 deletions

View file

@ -36,7 +36,7 @@ Video Tutorial
==============
.. image:: https://raw.githubusercontent.com/dslackw/images/master/slpkg/screenshot-1.png
:target: https://asciinema.org/a/10939
:target: https://asciinema.org/a/10790
Installation
------------

View file

@ -10,6 +10,10 @@ __version__ = "{0}.{1}.{2}".format(*__version_info__)
__license__ = "GNU General Public License v3 (GPLv3)"
__email__ = "d.zlatanidis@gmail.com"
''' file spacer '''
sp = "-"
''' temponary path '''
tmp = "/tmp/"

View file

@ -24,3 +24,14 @@ def get_file(link, char):
if link[i] == char:
break
return ''.join(results[::-1]).replace('/', '').strip(' ')
def get_to(arg, char):
'''
Get any string before char
'''
result = []
for c in arg:
result.append(c)
if c == char:
break
return ''.join(result).replace(char, '')

View file

@ -51,6 +51,7 @@ from sbo.dependency import *
from sbo.check import sbo_check
from sbo.views import sbo_network
from slack.upgrade import upgrade_all
def main():
description = "Utility to help package management in Slackware"
@ -66,7 +67,7 @@ def main():
parser.add_argument("-n", help="find from SBo repositority",
type=str, metavar=(''))
parser.add_argument("-c", help="check if your package is up to date",
type=str, metavar=(''))
type=str, nargs="+", metavar=('sbo, slack'))
parser.add_argument("-s", help="download, build & install pkg from SBo",
type=str, metavar=(''))
parser.add_argument("-i", help="install binary packages",
@ -83,7 +84,7 @@ def main():
type=str, nargs="+", metavar=(''))
args = parser.parse_args()
if args.verbose:
pkg_version()
prog_version()
if args.a:
s_user(getpass.getuser())
if len(args.a) == 2:
@ -100,7 +101,19 @@ def main():
if args.n:
sbo_network(args.n)
if args.c:
sbo_check(args.c)
if len(args.c) == 2:
if "sbo" in args.c:
sbo_check(''.join(args.c[1]))
elif "slack" in args.c:
if args.c[1] == "update":
upgrade_all()
else:
print ("\n{0}: invalid option: choose from check, update\n".format(__prog__))
else:
print ("\n{0}: error: must enter at least two arguments\n".format(
__prog__))
if args.s:
sbo_build(args.s)
if args.i:

View file

@ -5,11 +5,11 @@ import sys
from colors import colors
from __metadata__ import __prog__
def pkg_not_found(pkg, message):
def pkg_not_found(bol, pkg, message, eol):
'''
Print message when package not found
'''
print ("\n{0}: No such package {1}: {2}\n".format(__prog__, pkg, message))
print ("{0}{1}: No such package {2}: {3}{4}".format(bol, __prog__, pkg, message, eol))
def pkg_found(pkg):
'''
@ -28,7 +28,7 @@ def s_user(user):
Check for root user
'''
if user != "root":
print ("{0}: error: must have root privileges".format(__prog__))
print ("\n{0}: error: must have root privileges\n".format(__prog__))
sys.exit()
def template(max):
@ -54,4 +54,3 @@ def view_sbo(pkg, sbo_url, sbo_dwn, source_dwn, extra_dwn, sbo_req):
print (" {0}D{1}ownload Download this package".format(colors.RED, colors.ENDC))
print (" {0}B{1}uild Download and build".format(colors.RED, colors.ENDC))
print (" {0}I{1}nstall Download/Build/Install\n".format(colors.RED, colors.ENDC))

View file

@ -6,7 +6,7 @@ import shutil
import tarfile
import subprocess
from slpkg.messages import pkg_not_found
from messages import pkg_not_found
def build_extra_pkg(script, source, extra):
'''
@ -24,7 +24,9 @@ def build_extra_pkg(script, source, extra):
os.chdir(path + pkg_name)
os.system("sh {0}{1}{2}".format(path, pkg_name + "/", pkg_name + ".SlackBuild"))
except (OSError, IOError):
pkg_not_found(pkg='', message="Wrong file")
message = "Wrong file"
bol, eol, pkg = "\n", "\n", ""
pkg_not_found(bol, pkg, message, eol)
def build_package(script, source):
'''
@ -41,4 +43,7 @@ def build_package(script, source):
os.system("sh {0}{1}{2}".format(path, pkg_name + "/", pkg_name + ".SlackBuild"))
os.chdir(path)
except (OSError, IOError):
pkg_not_found(pkg='', message="Wrong file")
message = "Wrong file"
bol, eol, pkg = "\n", "\n", ""
pkg_not_found(bol, pkg, message, eol)

View file

@ -9,6 +9,6 @@ def find_package(find_pkg, directory):
'''
results = []
for file in os.listdir(directory):
if file.startswith(find_pkg + '-'):
if file.startswith(find_pkg):
results.append(file)
return results

View file

@ -6,9 +6,9 @@ import sys
import getpass
import subprocess
from slpkg.colors import colors
from slpkg.messages import pkg_not_found, s_user, template
from slpkg.__metadata__ import packages, __prog__, uname, arch
from colors import colors
from messages import pkg_not_found, s_user, template
from __metadata__ import packages, __prog__, uname, arch, sp
from find import find_package
@ -21,7 +21,12 @@ def pkg_install(binary):
try:
print subprocess.check_output('installpkg {0}'.format(binary[pkg]), shell=True)
except subprocess.CalledProcessError:
pkg_not_found(binary[pkg], message="Can't install")
message = "Can't install"
if len(binary) > 1:
bol, eol = "", ""
else:
bol, eol = "\n", "\n"
pkg_not_found(bol, binary[pkg], message, eol)
def pkg_upgrade(binary):
'''
@ -33,7 +38,12 @@ def pkg_upgrade(binary):
print subprocess.check_output('upgradepkg --install-new {0}'.format(binary[pkg]),
shell=True)
except subprocess.CalledProcessError:
pkg_not_found(binary[pkg], message="Can't upgrade")
message = "Can't upgrade"
if len(binary) > 1:
bol, eol = "", ""
else:
bol, eol = "\n", "\n"
pkg_not_found(bol, binary[pkg], message, eol)
def pkg_reinstall(binary):
'''
@ -45,7 +55,12 @@ def pkg_reinstall(binary):
print subprocess.check_output('upgradepkg --reinstall {0}'.format(binary[pkg]),
shell=True)
except subprocess.CalledProcessError:
pkg_not_found(binary[pkg], message="Can't reinstall")
message = "Can't reinstall"
if len(binary) > 1:
bol, eol = "", ""
else:
bol, eol = "\n", "\n"
pkg_not_found(bol, binary[pkg], message, eol)
def pkg_remove(binary):
'''
@ -54,16 +69,21 @@ def pkg_remove(binary):
s_user(getpass.getuser())
pkgs = []
for pkg in range(len(binary)):
if find_package(binary[pkg], packages) == []:
pkg_not_found(binary[pkg], message="Can't remove")
if find_package(binary[pkg] + sp, packages) == []:
message = "Can't remove"
if len(binary) > 1:
bol, eol = "", ""
else:
bol, eol = "\n", "\n"
pkg_not_found(bol, binary[pkg], message, eol)
else:
pkgs.append(binary[pkg])
if pkgs == []:
sys.exit()
count = []
print # new line at start
for pkg in range(len(binary)):
pkgs = find_package(binary[pkg], packages)
print # new line at start
pkgs = find_package(binary[pkg] + sp, packages)
if pkgs != []:
print (colors.RED + "delete --> " + colors.ENDC + "\n ".join(pkgs))
count.append(pkgs)
@ -75,18 +95,18 @@ def pkg_remove(binary):
results_removed = []
not_found = []
for pkg in range(len(binary)):
if find_package(binary[pkg], packages) == []:
if find_package(binary[pkg] + sp, packages) == []:
not_found.append(binary[pkg])
else:
try:
results_removed.append("".join(find_package(binary[pkg], packages)))
results_removed.append("".join(find_package(binary[pkg] + sp, packages)))
print subprocess.check_output('removepkg {0}'.format(binary[pkg]),
shell=True)
except subprocess.CalledProcessError:
file_not_found(binary[pkg])
template(78)
for file in results_removed:
if find_package(file, packages) == []:
if find_package(file + sp, packages) == []:
print ("| {0}: package: {1} removed".format(__prog__, file))
for file in not_found:
print ("| {0}: package: {1} not found".format(__prog__, file))
@ -98,22 +118,32 @@ def pkg_find(binary):
Find installed Slackware packages
'''
for pkg in range(len(binary)):
if find_package(binary[pkg], packages) == []:
pkg_not_found(binary[pkg], message="Can't find")
if find_package(binary[pkg] + sp, packages) == []:
message = "Can't find"
if len(binary) > 1:
bol, eol = "", ""
else:
bol, eol = "\n", "\n"
pkg_not_found(bol, binary[pkg], message, eol)
else:
print (colors.GREEN + "found --> " + colors.ENDC + "\n ".join(
find_package(binary[pkg], packages)))
find_package(binary[pkg] + sp, packages)))
def pkg_display(binary):
'''
Print the Slackware packages contents
'''
for pkg in range(len(binary)):
if find_package(binary[pkg], packages) == []:
pkg_not_found(binary[pkg], message="Can't find")
if find_package(binary[pkg] + sp, packages) == []:
message = "Can't dislpay"
if len(binary) > 1:
bol, eol = "", ""
else:
bol, eol = "\n", "\n"
pkg_not_found(bol, binary[pkg], message, eol)
else:
print subprocess.check_output("cat {0}{1}".format(packages,
" /var/log/packages/".join(find_package(binary[pkg], packages))), shell=True)
" /var/log/packages/".join(find_package(binary[pkg] +sp, packages))), shell=True)
def pkg_list(binary):
'''

View file

@ -4,15 +4,15 @@
import os
import getpass
from slpkg.pkg.build import *
from slpkg.pkg.find import find_package
from slpkg.pkg.manager import pkg_upgrade
from pkg.build import *
from pkg.find import find_package
from pkg.manager import pkg_upgrade
from slpkg.colors import colors
from slpkg.functions import get_file
from slpkg.messages import pkg_not_found, s_user, template
from slpkg.__metadata__ import sbo_arch, sbo_tag, sbo_filetype
from slpkg.__metadata__ import __prog__, tmp, packages, uname, arch
from colors import colors
from functions import get_file
from messages import pkg_not_found, s_user, template
from __metadata__ import sbo_arch, sbo_tag, sbo_filetype
from __metadata__ import __prog__, tmp, packages, uname, arch
from search import sbo_search_pkg
from download import sbo_slackbuild_dwn
@ -22,13 +22,17 @@ def sbo_check(name):
'''
Check if packages is up to date from slackbuilds.org
'''
sbo_file = " ".join(find_package(name, packages))
sbo_file = " ".join(find_package(name + sp, packages))
if sbo_file == "":
pkg_not_found(name, message="Can't find")
message = "Can't find"
bol, eol = "\n", "\n"
pkg_not_found(bol, name, message, eol)
else:
sbo_url = sbo_search_pkg(name)
if sbo_url is None:
pkg_not_found(name, message="Can't find")
message = "Can't find"
bol, eol = "\n", "\n"
pkg_not_found(bol, name, message, eol)
else:
sbo_version = sbo_version_pkg(sbo_url, name)
sbo_dwn = sbo_slackbuild_dwn(sbo_url, name)
@ -69,4 +73,4 @@ def sbo_check(name):
print
else:
print ("\n\n{0}: package {1} is up to date\n".format(__prog__,
"".join(find_package(name, packages))))
"".join(find_package(name + sp, packages))))

View file

@ -1,9 +1,9 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
from slpkg.colors import colors
from slpkg.__metadata__ import __prog__
from slpkg.messages import pkg_not_found, template
from colors import colors
from __metadata__ import __prog__
from messages import pkg_not_found, template
from greps import *
from search import sbo_search_pkg
@ -19,7 +19,9 @@ def sbo_dependencies_pkg(name):
if name != "%README%":
sbo_url = sbo_search_pkg(name)
if sbo_url is None:
pkg_not_found(name, message="Can't find")
message = "From slackbuilds.org"
bol, eol = "\n", "\n"
pkg_not_found(bol, name, message, eol)
else:
sbo_req = sbo_requires_pkg(sbo_url, name)
dependencies = sbo_req.split()
@ -37,7 +39,9 @@ def sbo_dependencies_links_pkg(name):
if name != "%README%":
sbo_url = sbo_search_pkg(name)
if sbo_url is None:
pkg_not_found(name, message="Can't find")
message = "From slackbuilds.org"
bol, eol = "\n", "\n"
pkg_not_found(bol, name, message, eol)
else:
version = ("@" + sbo_version_pkg(sbo_url, name)).split()
sbo_dwn = sbo_slackbuild_dwn(sbo_url, name).split()
@ -60,7 +64,7 @@ def sbo_dependencies_links_pkg(name):
def pkg_tracking(name):
'''
Find dependecies from package and print all
Find package dependecies and print all
'''
dependencies = sbo_dependencies_pkg(name)
if dependencies is None:

View file

@ -2,8 +2,8 @@
# -*- coding: utf-8 -*-
import os
from slpkg.url_read import url_read
from slpkg.__metadata__ import uname, arch
from url_read import url_read
from __metadata__ import uname, arch
def sbo_source_dwn(sbo_url, name):
'''

View file

@ -4,8 +4,8 @@
import os
import getpass
from slpkg.messages import s_user
from slpkg.url_read import url_read
from messages import s_user
from url_read import url_read
# create tmp directory
os.system("mkdir -p /tmp/slpkg/readme/")

View file

@ -4,8 +4,8 @@
import re
import sys
from slpkg.url_read import url_read
from slpkg.functions import rmv_unused
from url_read import url_read
from functions import rmv_unused
from repository import repository
@ -25,9 +25,9 @@ def sbo_search_pkg(name):
sys.stdout.write(".")
sys.stdout.flush()
sbo_url_sub = sbo_url + kind + "/"
find_SBo = re.findall(search_name, url_read(sbo_url_sub))
find_SBo = rmv_unused(" ".join(find_SBo))
if name in find_SBo:
find_sbo = re.findall(search_name, url_read(sbo_url_sub))
find_sbo = rmv_unused(" ".join(find_sbo))
if name in find_sbo:
return sbo_url_sub + name + "/"
sys.stdout.write("\n")

View file

@ -5,15 +5,15 @@ import os
import sys
import getpass
from slpkg.colors import colors
from slpkg.functions import get_file
from slpkg.__metadata__ import tmp, packages, __prog__
from slpkg.__metadata__ import sbo_arch, sbo_tag, sbo_filetype
from slpkg.messages import s_user, pkg_found, pkg_installed, template
from colors import colors
from functions import get_file
from __metadata__ import tmp, packages, __prog__
from __metadata__ import sbo_arch, sbo_tag, sbo_filetype
from messages import s_user, pkg_found, pkg_installed, template
from slpkg.pkg.build import *
from slpkg.pkg.find import find_package
from slpkg.pkg.manager import pkg_upgrade
from pkg.build import *
from pkg.find import find_package
from pkg.manager import pkg_upgrade
from dependency import sbo_dependencies_links_pkg
@ -87,7 +87,7 @@ def sbo_build(name):
pkg_for_install = []
pkg_already_installed = []
for file in filename_version:
if find_package(file, packages) == []:
if find_package(file + sp, packages) == []:
i += 2
pkg_for_install.append(file)
else:
@ -150,10 +150,10 @@ def sbo_build(name):
files.pop(0)
template(78)
for pkg in pkg_for_install:
if find_package(pkg, packages) != []:
if find_package(pkg + sp, packages) != []:
pkg_installed(pkg)
for pkg in pkg_already_installed:
if find_package(pkg, packages) != []:
if find_package(pkg + sp, packages) != []:
pkg_found(pkg)
template(78)
print # new line at end

View file

@ -1,16 +1,15 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
from colors import colors
from functions import get_file
from __metadata__ import tmp, packages
from __metadata__ import sbo_arch, sbo_tag, sbo_filetype
from messages import s_user, pkg_not_found, pkg_found, view_sbo, template
from slpkg.colors import colors
from slpkg.functions import get_file
from slpkg.__metadata__ import tmp, packages
from slpkg.__metadata__ import sbo_arch, sbo_tag, sbo_filetype
from slpkg.messages import s_user, pkg_not_found, pkg_found, view_sbo, template
from slpkg.pkg.build import *
from slpkg.pkg.find import find_package
from slpkg.pkg.manager import pkg_upgrade
from pkg.build import *
from pkg.find import find_package
from pkg.manager import pkg_upgrade
from read import *
from greps import *
@ -24,7 +23,9 @@ def sbo_network(name):
'''
sbo_url = sbo_search_pkg(name)
if sbo_url is None:
pkg_not_found(name, message="Can't find")
message = "From slackbuilds.org"
bol, eol = "\n", "\n"
pkg_not_found(bol, name, message, eol)
else:
sbo_req = sbo_requires_pkg(sbo_url, name)
sbo_dwn = sbo_slackbuild_dwn(sbo_url, name)
@ -76,7 +77,7 @@ def sbo_network(name):
elif read == "I" or read == "i":
s_user(getpass.getuser())
pkg_for_install = name + "-" + sbo_version
if find_package(pkg_for_install, packages) == []:
if find_package(pkg_for_install + sp, packages) == []:
script = get_file(sbo_dwn, "/")
source = get_file(source_dwn, "/")
print ("\n{0}Start -->{1}\n".format(colors.GREEN, colors.ENDC))
@ -98,7 +99,7 @@ def sbo_network(name):
break
else:
template(78)
pkg_found(''.join(find_package(name, packages)))
pkg_found(''.join(find_package(name + sp, packages)))
template(78)
break
else:

View file

@ -3,7 +3,7 @@
from __metadata__ import __version__, __license__, __email__
def pkg_version():
def prog_version():
'''
Print version, license and email
'''