From 4d53cfca3c10633d9c0a683cd7324ec26edcd57a Mon Sep 17 00:00:00 2001 From: =?utf8?q?Piotr=20Husiaty=C5=84ski?= Date: Wed, 13 Feb 2008 22:36:59 +0100 Subject: [PATCH] New conf.py variables. Few changes in abs.py plugin. --- conf.py | 18 +++++++++----- plugin/abs.py | 76 +++++++++++++++++++++++++++++++++++----------------------- plugin/aur2.py | 24 ++++++++++++------- plugload.py | 51 --------------------------------------- pyshell.py | 20 +++++++++------- showinfo.py | 6 +++++ 6 files changed, 91 insertions(+), 104 deletions(-) delete mode 100644 plugload.py diff --git a/conf.py b/conf.py index 856550a..6275c83 100644 --- a/conf.py +++ b/conf.py @@ -2,7 +2,7 @@ # -*- coding: utf-8-*- """ -Configuration file +Configuration file. """ from colors import * @@ -11,18 +11,24 @@ import os.path alias = { "h" : "history ", - "up" : "pacman -Suy ", - "p -Ss" : "pacman -Ss ", - "p -Suy" : "pacman -Suy ", - "Ss" : "search ", - "s" : "pacman -Ss ", "info" : "help ", } modules_path = os.path.join(os.getcwd(), "plugin/") +# history file, by default in home dir history_file = os.path.join(os.path.expanduser("~"), ".aurshell_history") history_length = 500 +# source compilation path, by default in home dir +build_dir = os.path.join(os.path.expanduser("~"), "aurshell") +# how to install package? +install_cmd = "sudo pacman -U " +# compile command +compile_cmd = "makepkg -f " +# AUR url +aur_url = "http://aur.archlinux.com" + +# shell prompt shell_prompt = color["BLUE"] + " [ " + color["WHITE"] + "aurshell" + \ color["BLUE"] + " ] " + color["none"] diff --git a/plugin/abs.py b/plugin/abs.py index 6189842..98c3873 100644 --- a/plugin/abs.py +++ b/plugin/abs.py @@ -2,19 +2,42 @@ import string import os import os.path import sys - - +import re +import shutil class abs(object): - """Do some stuff with ABS""" - def __init__(self, put): + """ + Do some stuff with ABS. Search, compile, install. + You know, everything that you need to be happy + """ + def __init__(self, put, conf): self.put = put + self.conf = conf self.compile_cmd = "makepkg -f " self.install_cmd = "pacman -U " self.search_path = "/var/abs" + + def do_builddir(self, bdir=None, *ignore): + # shouldn't this be plugin independent method? + if bdir: + if not os.path.isdir(bdir): + if self.put.ask("No such directory, create it?"): + try: + os.mkdir(bdir) + self.conf.build_dir = bdir + except OSError: + self.put("Permission denied.", "RED", True) + else: + self.conf.build_dir = bdir + self.put("Build directory: ", "GREEN", False) + self.put(self.conf.build_dir) + + def do_search(self, pkgname, *ignore): """Find PKGBUILD""" + # TODO 2008-02-13 20:08:29 + # Regular expression operations for searching pkgbuild_found = [] for root, dirs, files in os.walk(self.search_path): for d in dirs: @@ -35,36 +58,29 @@ class abs(object): for d in dirs: if d == pkgname: path = os.path.join(root, d) - self.put("==> " + path, "GREEN", True) - os.system("cd %s && %s " % (path, self.compile_cmd)) + build_path = os.path.join(self.conf.build_dir, d) + if os.path.isdir(build_path): + if self.put.ask("Directory exist. Delete it?"): + shutil.rmtree(build_path) + else: + self.put("Nothing to do.") + return + shutil.copytree(path, build_path) + os.system("cd %s && %s " % (build_path, self.conf.compile_cmd)) return self.put("PKGBUILD not found.") def do_install(self, pkgname, *ignore): - pkg_list = [] - for root, dirs, files in os.walk(self.search_path): - for d in dirs: - if d == pkgname: - path = os.path.join(root, d) - for pkg in os.listdir(path): - if pkg.endswith("pkg.tar.gz"): - pkg_list.append(pkg) - if len(pkg_list) == 0: - self.put("No package found. Try to compile it first.") - elif len(pkg_list) == 1: - os.system("cd %s && %s %s" % \ - (path, self.install_cmd, pkg_list[0])) - else: - self.put("More than one package found. Please choose one:") - for numb, pkg in enumerate(pkg_list): - self.put(str(numb) + pkg) - pkg_numb = int(raw_input()) - if pkg_numb > len(pkg_list): - sys.exit("Blah! Error!") - os.system("cd %s && %s %s" % \ - (path, self.install_cmd, pkg_list[pkg_numb])) - return - + build_path = os.path.join(self.conf.build_dir, pkgname) + if not os.path.isdir(build_path): + self.put("No package found. Try to compile it first.") + return + for pkgfile in os.listdir(build_path): + if pkgfile.endswith("pkg.tar.gz"): + os.system("cd %s && %s %s" % \ + (build_path, self.conf.install_cmd, pkgfile)) + return + self.put("No package found. Try to compile it first.") diff --git a/plugin/aur2.py b/plugin/aur2.py index 73e054e..ec3ed20 100644 --- a/plugin/aur2.py +++ b/plugin/aur2.py @@ -5,22 +5,30 @@ import os class aur(object): - """Search and build packages with PKGBUILDs from AUR.""" - def __init__(self, put): + """ + Search and build packages with PKGBUILDs from AUR. + As for now, it's not ready to use. AUR2 need to be + done first. + """ + def __init__(self, put, conf): + self.conf = conf self.put = put - self.url = "http://aur.archlinux.org/" - def do_seturl(self, url, *ignore): + def do_seturl(self, url=None, *ignore): """Set non-default url for AUR database""" - self.url = url - self.put("AUR url: ", "GREEN", False) - self.put(url) + if not url: + self.put("AUR url: ", "GREEN", False) + self.put(self.conf.aur_url) + else: + self.conf.aur_url = url + self.put("New AUR url: ", "GREEN", False) + self.put(self.conf.aur_url) def do_search(self, *args): """Search package with in it's name or description""" #TODO 2008-02-11 15:35:33 self.put("aur2 search:", color="GREEN", newline=True) - self.put("empty") + self.put("TODO, but AUR2 isn't readu yet.") def do_upgrade(self, *ignore): """Upgrade packages from AUR""" diff --git a/plugload.py b/plugload.py deleted file mode 100644 index d1aac80..0000000 --- a/plugload.py +++ /dev/null @@ -1,51 +0,0 @@ -#!/usr/bin/python -# -*- coding: utf-8-*- - - -import os -import os.path -import sys -import types -import string - -def load(modules_path): - """Load all commands modules from modules_path direcotory. - - Returns a dictionary : - { - "class_name" : class_instance, - ... - } - """ - command_modules = [] - # adding plugins path to sys.path - if modules_path not in sys.path: - sys.path.append(modules_path) - # importing all modules from modules_path - for module_name in os.listdir(modules_path): - module_path = os.path.abspath( - string.join(modules_path, module_name)) - (module_name, module_extension) = os.path.splitext(module_name) - # if it shouldn't be load - if os.path.islink(module_path) or \ - module_path == __file__ or \ - module_extension != ".py": - continue - for key in sys.modules.keys(): - if key == module_name: - del sys.modules[key] - module = __import__(module_name) - command_modules.append({"obj": module_name, "name": module,}) - # search for class in each module - module_objs = {} - for module in command_modules: - for obj in dir(module["name"]): - # TODO - # better class serch 2008-01-27 16:56:42 - if not obj.startswith("_") and \ - type(getattr(module['name'], obj)) == types.TypeType: - # create instance for each class - module_objs[obj] = \ - getattr(module['name'], obj)() - return module_objs - diff --git a/pyshell.py b/pyshell.py index 6d439f5..3290e70 100644 --- a/pyshell.py +++ b/pyshell.py @@ -16,7 +16,6 @@ import types import readline import conf -import plugload from showinfo import Put __version__ = "0.1" @@ -27,23 +26,26 @@ class AurShell(cmd.Cmd): Interactive shell framework. To use it, write some modules, becouse by default it's very poor shell. """ - def __init__(self, init_message=""): + def __init__(self): cmd.Cmd.__init__(self) + # use it instead of plain `print` self.put = Put() + self.conf = conf # prefix for method callable by shell self.cmdprefix = "do_" self.prompt = conf.shell_prompt + # plugins dict self.commands = self.load_plugins(conf.modules_path) + # intro message + self.intro = "\n\tWelcome to aurShell v%(__version__)s\n" % globals() # load history, create empty file if history doesn't exist if not os.path.isfile(conf.history_file): open(conf.history_file, "w").close() readline.read_history_file(conf.history_file) readline.set_history_length(conf.history_length) - - if init_message: - self.intro = init_message - else: - self.intro = "\n\tWelcome to aurShell v%(__version__)s\n" % globals() + # create build_dir if doesn't exist + if not os.path.isdir(conf.build_dir): + os.mkdir(conf.build_dir) def load_plugins(self, modules_path): @@ -76,11 +78,11 @@ class AurShell(cmd.Cmd): if not obj.startswith("_"): try: # check if it's method - x = getattr(module['name'], obj)(self.put) + x = getattr(module['name'], obj)(self.put, conf) # create instance for each class # as agrument give it Put() class instance module_objs[obj] = \ - getattr(module['name'], obj)(self.put) + getattr(module['name'], obj)(self.put, conf) except TypeError: pass return module_objs diff --git a/showinfo.py b/showinfo.py index dc8f20a..925d40f 100644 --- a/showinfo.py +++ b/showinfo.py @@ -28,6 +28,12 @@ class Put(object): else: print("%s %s" % (message, " ".join(args))) + def ask(self, question, color=None, answer=" [Y/n]"): + self.color(question + answer, color, False) + if raw_input() in "Yy": + return True + return False + def noline(self, message): """Print message, but don't end it with new line character""" -- 2.11.4.GIT