Embedix-DB
view release on metacpan or search on metacpan
#!/usr/bin/perl -w
eval 'exec /usr/bin/perl -w -S $0 ${1+"$@"}'
if 0; # not running under some shell
use strict;
use Getopt::Long;
use Data::Dumper;
use Pod::Usage;
use Safe;
use Embedix::DB;
use Embedix::ECD;
#_______________________________________
sub help {
pod2usage(-verbose => 1);
}
#_______________________________________
sub new {
my $edb = shift;
if (-d "./EBX") {
print STDERR "a project already exists here\n";
} else {
mkdir("EBX", 0775) or die($!);
}
die("not done yet");
}
#_______________________________________
sub add {
my $edb = shift;
foreach (@ARGV) {
my $ecd = Embedix::ECD->newFromFile($_);
$edb->updateDistro(ecd => $ecd);
}
}
#_______________________________________
sub ls {
my $edb = shift;
my $cl = $edb->getComponentList;
my $cat;
foreach $cat (@$cl) {
print $cat->[0], "\n";
foreach my $item (@{$cat->[1]}) {
print " $item->[1]\n";
}
}
}
# this is a wrapper for distro manipulation methods
#_______________________________________
sub admin {
my $edb = shift;
local @ARGV = @_;
my %sub_for_admin_command = (
addDistro => undef,
cloneDistro => undef,
updateDistro => undef,
);
my $c = shift(@ARGV) || pod2usage(-verbose => 0);
my $sub;
if (defined($sub = $sub_for_admin_command{$c})) {
$sub->($edb, @ARGV);
} else {
warn("'$c' is not a valid command.\n");
}
}
#_________________________________________________________________________main
# read config
my $config_file = "$ENV{HOME}/.embedix/embedixrc";
if (-e $config_file) {
# eval ebxrc
open(EBXRC, $config_file) || die($!);
my $ebxrc = join('', <EBXRC>);
close(EBXRC);
eval($ebxrc);
} else {
# create ebxrc if it doesn't already exist;
mkdir("$ENV{HOME}/.embedix", 0777) || die($!);
open(EBXRC, "> $config_file") || die($!);
close(EBXRC);
chmod(0600, $config_file)
}
# setup function table
my %sub_for_command = (
'--help' => \&help,
'-h' => \&help,
add => \&add,
admin => \&admin,
build => undef,
dep => undef,
enable => undef,
ls => \&ls,
new => \&new,
);
# connect to edb
my $edb = Embedix::DB->new(
backend => 'Pg',
source => [
'dbi:Pg:dbname=embedix', undef, undef,
{ AutoCommit => 0 }
],
);
# cheat
$edb->workOnDistro(name => 'Embedix 2.0', board => 'i386');
( run in 1.871 second using v1.01-cache-2.11-cpan-5a3173703d6 )