From 73fc5bdd9112e16b8c681c9f5a84d0cce0710466 Mon Sep 17 00:00:00 2001 From: Steve Youngs Date: Sun, 3 Feb 2013 12:39:46 +1000 Subject: [PATCH] Add some rudimentary dependency tracking. "tracking" is probably an over-statement. What this does is to store a package's run-time so deps (gleaned from ldd) in its .project. The build script template has been updated to find/store them, and functions have been added to handy_funcs to view them. I've also gotten rid of most of the uses of pinky in the aux functions and simplified them. * etc/pkgusr/skel-package/.project (Deps): New. * etc/pkgusr/skel-package/build (update_commands): Add magic to find the run-time deps. * etc/pkgusr/handy_funcs (deps): Show the dependencies. * etc/pkgusr/handy_funcs (H-pkg): Add `deps'. * etc/pkgusr/handy_funcs (showinst,showgen,srepo,trepo,web): Remove unnecessary use of pinky. * etc/pkgusr/zsh/_zsh-pkgtools: Add `dpkg'. * etc/pkgusr/zsh/zsh-pkgtools (H-pkg): Add `dpkg'. * etc/pkgusr/zsh/zsh-pkgtools (dpkg): New. * etc/pkgusr/zsh/zsh-pkgtools (upkg,Lpkg,vpkg,ipkg,gpkg,wpkg,pkgrepo): Remove unnecessary use of pinky, sed, etc to simplify. * lisp/pkgusr.el (pkgusr-pkg-deps): New. Bind `H-c D' to it. * lisp/pkgusr.el (pkgusr-pkg-url): Remove unnecessary use of pinky. * lisp/pkgusr.el (pkgusr-pkg-repo): Ditto. * lisp/pkgusr.el (pkgusr-pkg-version): Ditto. * lisp/pkgusr.el (pkgusr-pkg-description): Ditto. Signed-off-by: Steve Youngs --- etc/pkgusr/handy_funcs | 28 ++++++++++++--------- etc/pkgusr/skel-package/.project | 2 ++ etc/pkgusr/skel-package/build | 7 +++--- etc/pkgusr/zsh/_zsh-pkgtools | 2 +- etc/pkgusr/zsh/zsh-pkgtools | 42 +++++++++++++++++++------------- lisp/pkgusr.el | 40 ++++++++++++++++++++++++------ 6 files changed, 81 insertions(+), 40 deletions(-) diff --git a/etc/pkgusr/handy_funcs b/etc/pkgusr/handy_funcs index 19922bb..952c4b3 100644 --- a/etc/pkgusr/handy_funcs +++ b/etc/pkgusr/handy_funcs @@ -1,5 +1,5 @@ # -*- shell-script -*- -# Copyright (C) 2007 Steve Youngs +# Copyright (C) 2007 - 2013 Steve Youngs # What lies here is a collection of handy bash shell functions that # make life a little easier for pkgusr. @@ -95,18 +95,23 @@ updver() showinst() { - local top=$(pinky -l $(whoami)|grep -n "^Install Notes:$"|cut -d: -f1) - local bot=$(pinky -l $(whoami)|grep -n "^General Notes:$"|cut -d: -f1) + local top=$(grep -n "^Install Notes:$" ${HOME}/.project|cut -d: -f1) + local bot=$(grep -n "^General Notes:$" ${HOME}/.project|cut -d: -f1) - pinky -l $(whoami)|sed -n ${top},${bot}p + sed -n ${top},${bot}p ${HOME}/.project } showgen() { - local top=$(pinky -l $(whoami)|grep -n "^General Notes:$"|cut -d: -f1) - local bot=$(pinky -l $(whoami)|grep -n "^CONTENTS:$"|cut -d: -f1) + local top=$(grep -n "^General Notes:$" ${HOME}/.project|cut -d: -f1) + local bot=$(grep -n "^CONTENTS:$" ${HOME}/.project|cut -d: -f1) - pinky -l $(whoami)|sed -n ${top},${bot}p + sed -n ${top},${bot}p ${HOME}/.project +} + +deps() +{ + grep --colour 'Deps: ' ${HOME}/.project } listp() @@ -116,22 +121,22 @@ listp() srepo() { - pinky -l $(whoami)|grep --colour Repo_Location:.*$ + grep --colour Repo_Location:.*$ ${HOME}/.project } rawrepo() { - srepo|awk '{print $2;}'|tr -d '<>' + srepo|awk '{print $2;}'|tr -d '<>' } trepo() { - pinky -l $(whoami)|grep --colour Repo_Type:.*$ + grep --colour Repo_Type:.*$ ${HOME}/.project } web() { - pinky -l $(whoami)|grep --colour Web_Site:.*$ + grep --colour Web_Site:.*$ ${HOME}/.project } rawweb() @@ -248,6 +253,7 @@ H-pkg() trepo Display the type of repo (tla, git, svn, mercurial etc) web Display the package's homepage URL. rawweb Output just the web URL (to use with lynx etc) + deps Display the package's dependencies xtar [TARBALL] Extract TARBALL, automatically choosing the appropriate tar(1) options. vtar [TARBALL] List the contents of TARBALL, automatically choosing diff --git a/etc/pkgusr/skel-package/.project b/etc/pkgusr/skel-package/.project index c4998d2..939efe7 100644 --- a/etc/pkgusr/skel-package/.project +++ b/etc/pkgusr/skel-package/.project @@ -9,6 +9,8 @@ Repo_Location: Web_Site: + Deps: + Install Notes: ------------- Use the build script. diff --git a/etc/pkgusr/skel-package/build b/etc/pkgusr/skel-package/build index 32dab93..f57d36f 100755 --- a/etc/pkgusr/skel-package/build +++ b/etc/pkgusr/skel-package/build @@ -38,8 +38,8 @@ ## Version info. ourname=${0##*/} -VERSION=1.2 -COPYRIGHT="Copyright (C) 2007 - 2011 Steve Youngs " +VERSION=1.3 +COPYRIGHT="Copyright (C) 2007 - 2013 Steve Youngs " version_str="${ourname}: ${VERSION}\n${COPYRIGHT}" show_version() @@ -116,7 +116,8 @@ test_pipe() update_commands() { : - sed -i s/"Last_Updated.*"/"Last_Updated: $(date +%c)"/g ${HOME}/.project + sed -i s/"\(Last_Updated: \).*$"/"\1$(date +%c)"/g ${HOME}/.project + sed -i s/"\(Deps: \).*$"/"\1$(forall_direntries_from $(whoami) -executable -exec ldd {} 2>/dev/null \;|grep '=>' 2>/dev/null|awk '{print $3;}'|xargs stat --format \"%U:%G\"|sort|uniq|xargs echo -n)"/ ${HOME}/.project awk '/^CONTENTS:/ { print; exit; } {print}' ${HOME}/.project > ${HOME}/.projtmp echo "--------" >> ${HOME}/.projtmp list_package $(whoami) >> ${HOME}/.projtmp diff --git a/etc/pkgusr/zsh/_zsh-pkgtools b/etc/pkgusr/zsh/_zsh-pkgtools index 960e968..51ba0c4 100644 --- a/etc/pkgusr/zsh/_zsh-pkgtools +++ b/etc/pkgusr/zsh/_zsh-pkgtools @@ -1,4 +1,4 @@ -#compdef ppkg cpkg upkg vpkg ipkg gpkg wpkg pkgrepo pkgsu xtar vtar +#compdef ppkg cpkg dpkg upkg vpkg ipkg gpkg wpkg pkgrepo pkgsu xtar vtar case $service in (cpkg) _command_names -e ;; diff --git a/etc/pkgusr/zsh/zsh-pkgtools b/etc/pkgusr/zsh/zsh-pkgtools index 018268d..1f11308 100644 --- a/etc/pkgusr/zsh/zsh-pkgtools +++ b/etc/pkgusr/zsh/zsh-pkgtools @@ -1,5 +1,5 @@ # -*- Shell-script -*- -# Copyright (C) 2007 - 2010 Steve Youngs +# Copyright (C) 2007 - 2013 Steve Youngs # # A collection of Zsh functions that I use day to day for maintaining # and administering my machines. These come in very handy if you set up @@ -19,6 +19,7 @@ H-pkg () ipkg [PKG] -- print install notes of PKG. gpkg [PKG] -- print general notes of PKG. wpkg [PKG] -- print PKG website URL. + dpkg [PKG] -- print PKG dependencies. pkgrepo [PKG] -- print the source repo location of PKG with optional 2nd arg non-nil, also print repo type. @@ -86,16 +87,14 @@ upkg() echo "Usage: $0 [PKG]" >&2 return 1 else - echo -n "$argv[1]... " - pinky -l $argv[1]|grep 'Last_Updated:.*'| \ - sed 's/^ //'|grep --colour '.*' + grep --colour 'Last_Updated:.*' ~$argv[1]/.project fi } Lpkg () { for pkg in $(sed -n '/^install/p' /etc/group|cut -d: -f4|tr ',' '\n'); do - printf "${pkg}\t\t\t$(pinky -l ${pkg}|grep Last_Updated|cut -d' ' -f3-)\n" + printf "${pkg}\t\t\t$(upkg ${pkg}|cut -d' ' -f3-)\n" done|less } @@ -106,9 +105,7 @@ vpkg() echo "Usage: $0 [PKG]" >&2 return 1 else - echo -n "$argv[1]... " - pinky -l $argv[1]|grep 'Version:.*'| \ - sed 's/^ //'|grep --colour '.*' + grep --colour 'Version: ' ~$argv[1]/.project fi } @@ -119,9 +116,9 @@ ipkg() echo "Usage: $0 [PKG]" >&2 return 1 else - local top=$(pinky -l $argv[1]|grep -n "Install Notes"|cut -d: -f1) - local bot=$(pinky -l $argv[1]|grep -n "General Notes"|cut -d: -f1) - pinky -l $argv[1]|sed -n ${top},${bot}p + local top=$(grep -n "Install Notes" ~$argv[1]/.project|cut -d: -f1) + local bot=$(grep -n "General Notes" ~$argv[1]/.project|cut -d: -f1) + sed -n ${top},${bot}p ~$argv[1]/.project fi } @@ -132,12 +129,23 @@ gpkg() echo "Usage: $0 [PKG]" >&2 return 1 else - local top=$(pinky -l $argv[1]|grep -n "General Notes"|cut -d: -f1) - local bot=$(pinky -l $argv[1]|grep -n "CONTENTS"|cut -d: -f1) - pinky -l $argv[1]|sed -n ${top},${bot}p + local top=$(grep -n "General Notes" ~$argv[1]/.project|cut -d: -f1) + local bot=$(grep -n "CONTENTS" ~$argv[1]/.project|cut -d: -f1) + sed -n ${top},${bot}p ~$argv[1]/.project fi } +dpkg() +{ + if [[ $ARGC -lt 1 || $ARGC -gt 1 ]]; then + echo Invalid or missing argument >&2 + echo "Usage: $0 [PKG]" >&2 + return 1 + else + grep --colour 'Deps: ' ~$argv[1]/.project + fi +} + wpkg() { if [[ $ARGC -lt 1 || $ARGC -gt 1 ]]; then @@ -145,7 +153,7 @@ wpkg() echo "Usage: $0 [PKG]" >&2 return 1 else - pinky -l $argv[1]|grep --colour 'Web_Site:.*$' + grep --colour 'Web_Site: ' ~$argv[1]/.project fi } @@ -156,8 +164,8 @@ pkgrepo() echo "Usage: $0 [PKG] " >&2 return 1 else - pinky -l $argv[1]|grep --colour 'Repo_Location:.*$' - [[ -n "$argv[2]" ]] && pinky -l $argv[1]|grep --colour 'Repo_Type:.*$' + grep --colour 'Repo_Location: ' ~$argv[1]/.project + [[ -n "$argv[2]" ]] && grep --colour 'Repo_Type: ' ~$argv[1]/.project fi } diff --git a/lisp/pkgusr.el b/lisp/pkgusr.el index e8fca3e..01c3c4f 100644 --- a/lisp/pkgusr.el +++ b/lisp/pkgusr.el @@ -5,7 +5,7 @@ ;; Author: Steve Youngs ;; Maintainer: Steve Youngs ;; Created: <2007-07-13> -;; Time-stamp: +;; Time-stamp: ;; Homepage: N/A ;; Keywords: utils package-management @@ -221,11 +221,12 @@ If non-interactive, return a list whose car is user and cdr is group." (let* ((allpkgs (pkgusr-all-pkgs)) (pkg (or pkg (completing-read "Package: " (mapcar #'list allpkgs) - nil t nil pkgusr-pkg-history)))) + nil t nil pkgusr-pkg-history))) + (pkgfile (format "/usr/src/%s/.project" pkg))) (when (member pkg allpkgs) (with-temp-buffer (erase-buffer) - (insert (shell-command-to-string (format "pinky -l %s" pkg))) + (insert-file-contents pkgfile) (goto-char (point-min)) (re-search-forward "Web_Site: <\\(.*\\)>$" nil t) (if (interactive-p) @@ -239,11 +240,12 @@ If non-interactive, return a list whose car is user and cdr is group." (pkg (or pkg (completing-read "Package: " (mapcar #'list allpkgs) nil t nil pkgusr-pkg-history))) + (pkgfile (format "/usr/src/%s/.project" pkg)) repo type) (when (member pkg allpkgs) (with-temp-buffer (erase-buffer) - (insert (shell-command-to-string (format "pinky -l %s" pkg))) + (insert-file-contents pkgfile) (goto-char (point-min)) (re-search-forward "Repo_Type: ?$" nil t) (setq type (match-string 1)) @@ -259,11 +261,12 @@ If non-interactive, return a list whose car is user and cdr is group." (let* ((allpkgs (pkgusr-all-pkgs)) (pkg (or pkg (completing-read "Package: " (mapcar #'list allpkgs) - nil t nil pkgusr-pkg-history)))) + nil t nil pkgusr-pkg-history))) + (pkgfile (format "/usr/src/%s/.project" pkg))) (if (member pkg allpkgs) (with-temp-buffer (erase-buffer) - (insert (shell-command-to-string (format "pinky -l %s" pkg))) + (insert-file-contents pkgfile) (goto-char (point-min)) (re-search-forward "Version: \\(.*$\\)" nil t) (if (interactive-p) @@ -277,11 +280,12 @@ If non-interactive, return a list whose car is user and cdr is group." (let* ((allpkgs (pkgusr-all-pkgs)) (pkg (or pkg (completing-read "Package: " (mapcar #'list allpkgs) - nil t nil pkgusr-pkg-history)))) + nil t nil pkgusr-pkg-history))) + (pkgfile (format "/usr/src/%s/.project" pkg))) (if (member pkg allpkgs) (with-temp-buffer (erase-buffer) - (insert (shell-command-to-string (format "pinky -l %s" pkg))) + (insert-file-contents pkgfile) (goto-char (point-min)) (re-search-forward "Description: \\(.*$\\)" nil t) (if (interactive-p) @@ -289,6 +293,25 @@ If non-interactive, return a list whose car is user and cdr is group." (match-string 1))) (error 'pkgusr-unknown-pkg pkg)))) +(defun pkgusr-pkg-deps (&optional pkg) + "Return the dependencies of PKG as a string." + (interactive) + (let* ((allpkgs (pkgusr-all-pkgs)) + (pkg (or pkg (completing-read "Package: " + (mapcar #'list allpkgs) + nil t nil pkgusr-pkg-history))) + (pkgfile (format "/usr/src/%s/.project" pkg))) + (if (member pkg allpkgs) + (with-temp-buffer + (erase-buffer) + (insert-file-contents pkgfile) + (goto-char (point-min)) + (re-search-forward "Deps: \\(.*$\\)" nil t) + (if (interactive-p) + (message "[%s Deps] %s" pkg (match-string 1)) + (match-string 1))) + (error 'pkgusr-unknown-pkg pkg)))) + ;; A little bogus perhaps, but it works. `pkgusr-find-file' is ;; something that only I can use because it ssh's through root to ;; get to the pkgusr. And nobody but me would have a need for @@ -338,6 +361,7 @@ after the setq. Be bold and hard code it in pkgusr.el itself.") (global-set-key [(hyper c) f] #'pkgusr-file-pkg) (global-set-key [(hyper c) (hyper r)] #'pkgusr-list-pkgs-regexp) (global-set-key [(hyper c) d] #'pkgusr-pkg-description) +(global-set-key [(hyper c) D] #'pkgusr-pkg-deps) (global-set-key [(hyper c) g] #'pkgusr-pkg-general-notes) (global-set-key [(hyper c) i] #'pkgusr-pkg-install-notes) (global-set-key [(hyper c) r] #'pkgusr-pkg-repo) -- 2.25.1