1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281
|
#!/usr/bin/perl -w
# $Id: pkgInfo,v 1.5 2013/07/17 19:34:07 tom Exp $
use strict;
#
# This script provides a user interface to packages on the system.
#
use Cdk;
Cdk::init();
# Create a dialog box with options.
my @dialogMessge = ( "<C></U>Unix Package Interface", "<C>Select an option." );
# Create the buutons for the dialog box.
my @buttons =
( "<Add Package>", "<Remove Package>", "<Package Info>", "<Exit>" );
# Create the dialog widget.
my $dialog =
new Cdk::Dialog( 'Message' => \@dialogMessge, 'Buttons' => \@buttons );
# Do this forever.
for ( ; ; ) {
# Activate the dialog box.
my $choice = $dialog->activate();
next if !defined $choice;
# Check the answer.
if ( $choice == 0 ) {
addPackage();
}
elsif ( $choice == 1 ) {
removePackage();
}
elsif ( $choice == 2 ) {
packageInfo();
}
elsif ( $choice == 3 ) {
# Exit.
Cdk::end();
exit;
}
}
#
# This function adds a package.
#
sub addPackage {
my @packageList = ();
my $x;
# Set up the entry field.
my $mesg = "Enter the source package directory:";
my $entry = new Cdk::Entry(
'Label' => $mesg,
'Max' => 512,
'Width' => 30
);
# Get the package directory.
my $pkgDir = $entry->activate();
return if !defined $pkgDir;
# Open the given directory.
if ( !opendir( DIR, $pkgDir ) ) {
# Couldn't open the directory.
my @mesg = (
"<C></B/U>Error", "<C>Could not open the directory </B>$pkgDir",
"<C></U>$!", "", "<C>Press any key to continue."
);
my $label = new Cdk::Label( 'Message' => \@mesg );
$label->draw();
$label->wait();
return;
}
# Get the directory listing of the given directory.
my @contents = readdir(DIR);
closedir(DIR);
# Create a list of all of the directories under the given directory.
foreach my $file (@contents) {
next if $file =~ /^\./;
push( @packageList, $file ) if ( -d "$pkgDir/$file" );
}
# Create a selection list and display the known packages.
my $select = new Cdk::Selection(
'Title' => "Add Which Packages?",
'List' => \@packageList,
'Choices' => [ "Yes ", "No" ],
'Height' => 20,
'Width' => 50
);
# Activate the packages.
my @choiceList = $select->activate();
my @selectedPackages = ();
return if !@choiceList;
# Generate the names of the selected packages.
for ( $x = 0 ; $x <= $#choiceList ; $x++ ) {
if ( $choiceList[$x] == 1 ) {
push( @selectedPackages, $packageList[$x] );
}
}
my $label = new Cdk::Label( 'Message' => \@selectedPackages );
$label->draw();
$label->wait();
}
#
# This function removes a package.
#
sub removePackage {
# Get the packages to remove.
my @packageNames = selectPackages("<C></U>Select the packages to delete.");
my @buttons = ( "<No>", "<Yes>", "<Yes To ALL>" );
my $yesToAll = 0;
# Now that we have the package names, ask for each one.
foreach my $name (@packageNames) {
# If they asked for all to be deleted, no need to ask
if ( !$yesToAll ) {
# Create the dialog message.
my @mesg = (
"<C>Are you sure you want",
"to delete the package </U>$name<!U>?"
);
# Make sure they want to do it.
my $dialog = new Cdk::Dialog(
'Message' => \@mesg,
'Buttons' => \@buttons
);
# Activate it.
my $answer = $dialog->activate();
# If the user hit escape, let the user know the package
# was NOT deleted.
if ( !defined $answer ) {
popupLabel(
[
"<C>Escape Hit",
"<C>The package was </R>Not<!R> deleted."
]
);
next;
}
# Check the answer
if ( $answer == 1 ) {
# Delete the package
popupLabel("pkgrm $name");
}
else {
# Set the yes to all flag.
$yesToAll = 1;
# Delete the package
popupLabel("pkgrm $name");
}
}
else {
# Delete the package
popupLabel("pkgrm $name");
}
}
}
#
# This function provides information about packages.
#
sub packageInfo {
# Get the package to view.
my $packageName = selectPackage("<C></U>Select a package to view.");
# Get the information about the selected package.
my @pinfo = qx (pkginfo -l $packageName);
chomp @pinfo;
# Create the information viewer.
my $viewer = new Cdk::Viewer(
'Buttons' => ["OK"],
'Height' => -2,
'Width' => -4
);
# Activate the viewer.
$viewer->set(
'Title' => "<C>Package Name: </U>$packageName<!U>",
'Info' => \@pinfo,
'Interp' => "FALSE"
);
$viewer->activate();
}
#
# This function creates a scrolling list of all the packages on the system
# and returns the name of the package selected.
#
sub selectPackage {
my $title = shift;
# Get a list of all the packages installed on the system.
my @packageList = qx (pkginfo);
my @packageNames = ();
# Strip out the names of the packages.
foreach my $PKG (@packageList) {
my $pkgName = ( split( /\s+/, $PKG ) )[1];
push( @packageNames, $pkgName );
}
# Create the scrolling list.
my $packageList = new Cdk::Scroll(
'Title' => $title,
'List' => \@packageNames,
'Numbers' => "TRUE",
'Height' => 20,
'Width' => 50
);
# Return the selected name.
my $choice = $packageList->activate();
return ( $packageNames[$choice] );
}
#
# This function creates a selection list of all the packages on the system
# and returns the name of the package selected.
#
sub selectPackages {
my $title = shift;
my @options = qw (Keep Delete);
my @selectedNames = ();
# Get a list of all the packages installed on the system.
my @packageList = qx (pkginfo);
my @packageNames = ();
my @selectedPackages = ();
my $x = 0;
# Strip out the names of the packages.
foreach my $PKG (@packageList) {
my $pkgName = ( split( /\s+/, $PKG ) )[1];
push( @packageNames, $pkgName );
}
# Create the selection list.
my $select = new Cdk::Selection(
'Title' => $title,
'List' => \@packageNames,
'Choices' => \@options,
'Height' => 20,
'Width' => 50
);
# Activate the selection list.
my @list = $select->activate();
# Generate the names of the selected packages.
for ( $x = 0 ; $x <= $#packageNames ; $x++ ) {
if ( $list[$x] == 1 ) {
push( @selectedPackages, $packageNames[$x] );
}
}
return (@selectedPackages);
}
|