From 1ae1792fd6263ab5739a4d00501967baffd4e470 Mon Sep 17 00:00:00 2001 From: Dimitris Zlatanidis Date: Sat, 4 Jul 2015 06:58:29 +0300 Subject: [PATCH] Feature added auto command --- slpkg/auto_pkg.py | 63 +++++++++++++++++++++++++++++++++++++++++++++++ slpkg/main.py | 17 +++++++++++++ 2 files changed, 80 insertions(+) create mode 100644 slpkg/auto_pkg.py diff --git a/slpkg/auto_pkg.py b/slpkg/auto_pkg.py new file mode 100644 index 00000000..b3f331c9 --- /dev/null +++ b/slpkg/auto_pkg.py @@ -0,0 +1,63 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- + +# auto_pkg.py file is part of slpkg. + +# Copyright 2014-2015 Dimitris Zlatanidis +# All rights reserved. + +# Slpkg is a user-friendly package manager for Slackware installations + +# 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 . + + +from messages import Msg +from pkg.manager import PackageManager +from __metadata__ import MetaData as _meta_ + + +class Auto(object): + + def __init__(self, packages): + self.packages = packages + self.meta = _meta_ + self.commands = { + "1": "installpkg", + "2": "upgradepkg --install-new", + "3": "upgradepkg --reinstall" + } + + def select(self): + print("\nFound Slackware binary package for installation:\n") + for pkg in self.packages: + print(" " + pkg.split("/")[-1]) + print("") + Msg().template(78) + print("| Chose a command:") + Msg().template(78) + for key in sorted(self.commands): + print("| {0}. {1}{2}{3}".format(key, self.meta.color["GREEN"], + self.commands[key], + self.meta.color["ENDC"])) + Msg().template(78) + self.choice = raw_input(" > ") + self.execute() + + def execute(self): + if self.choice in self.commands.keys(): + if self.choice == "1": + PackageManager(self.packages).install("") + elif self.choice in ["2", "3"]: + PackageManager(self.packages).upgrade( + self.commands[self.choice][11:]) diff --git a/slpkg/main.py b/slpkg/main.py index d337207c..8454b9a4 100644 --- a/slpkg/main.py +++ b/slpkg/main.py @@ -22,11 +22,13 @@ # along with this program. If not, see . +import os import sys import getpass from load import Regex from messages import Msg +from auto_pkg import Auto from desc import PkgDesc from config import Config from checks import Updates @@ -477,6 +479,19 @@ class ArgParse(object): usage("") +def auto_detect(args): + """Check for already Slackware binary packages exist + """ + packages = [] + for pkg in args: + if pkg.endswith(".tgz") or pkg.endswith(".txz"): + if os.path.isfile(pkg): + packages.append(pkg) + if packages: + Auto(packages).select() + sys.exit(0) + + def main(): Msg().s_user(getpass.getuser()) @@ -489,6 +504,8 @@ def main(): usage("") sys.exit(0) + auto_detect(args) + if len(args) == 2 and args[0] == "update" and args[1] == "slpkg": args[0] = "update-slpkg"