Update of /cvsroot/gmod/schema/chado/lib/Bio/GMOD
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22621/chado/lib/Bio/GMOD
Modified Files:
Config.pm
Log Message:
Items worked on during the GMOD meeting:
- load_gff now inserts value from the source column into featureprop
with the autocreated term 'GFF_source'
- added new Bio::GMOD::Config and Bio::GMOD::DB::Config; can be used to
retrieve all information from gmod.conf and db.conf files, and in the case
of Bio::GMOD::DB::Config, can return a database handle.
(and I even documented it all :-)
Index: Config.pm
===================================================================
RCS file: /cvsroot/gmod/schema/chado/lib/Bio/GMOD/Config.pm,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** Config.pm 9 Apr 2004 02:19:41 -0000 1.1
--- Config.pm 30 Apr 2004 14:30:40 -0000 1.2
***************
*** 11,24 ****
my $conf = Bio::GMOD::Config->new();
! my $tmpdir = $conf->tmp();
! my $confdir = $conf->conf();
!
! #assume there is a file 'chado.conf' with database connetion info
! my $dbusername = $conf->db->{'chado'}{'DBNAME'};
! my $dbhostname = $conf->db->{'chado'}{'DBHOST'};
! # ...etc...
my @dbnames = $conf->available_dbs();
- my @dbparams = $conf->available_params($dbnames[0]);
=head1 DESCRIPTION
--- 11,18 ----
my $conf = Bio::GMOD::Config->new();
! my $tmpdir = $conf->tmpdir();
! my $confdir = $conf->confdir();
my @dbnames = $conf->available_dbs();
=head1 DESCRIPTION
***************
*** 27,31 ****
files in GMOD_ROOT/conf. Typically, these files will be gmod.conf
(containing site-wide parameters), and one each configuration file for
! each database, named dbname.conf, containing database connection parameters.
=head1 METHODS
--- 21,26 ----
files in GMOD_ROOT/conf. Typically, these files will be gmod.conf
(containing site-wide parameters), and one each configuration file for
! each database, named dbname.conf, containing database connection parameters,
! which are accessed through Bio::GMOD::Config::DB objects.
=head1 METHODS
***************
*** 33,37 ****
=cut
! use File::Spec::Functions qw/ catdir /;
=head2 new
--- 28,32 ----
=cut
! use File::Spec::Functions qw/ catdir catfile /;
=head2 new
***************
*** 70,102 ****
#db.conf (per programmers guide)
! my %db;
opendir CONFDIR, $confdir
or die "couldn't open $confdir directory for reading:$!\n";
my $dbname;
while (my $dbfile = readdir(CONFDIR) ) {
- my $tmpconf = catdir($confdir, $dbfile);
- next unless (-f $tmpconf);
if ($dbfile =~ /^(\w+)\.conf/) {
! $dbname = $1;
} else {
next;
}
- $db{$dbname}{'conf'} = $tmpconf;
}
closedir CONFDIR;
! foreach my $conffile (keys %db) {
! open CONF, $db{$conffile}{'conf'}
! or die "Couldn't open $db{$conffile}{'conf'} for reading: $!";
! while (<CONF>) {
! next if /^\#/;
! if (/(\w+)\s*=\s*(\S+)/) {
! $db{$conffile}{$1} = $2;
! }
}
- close CONF;
}
! return bless {db => \%db,
confdir => $confdir}, $self;
}
--- 65,94 ----
#db.conf (per programmers guide)
! my @db;
opendir CONFDIR, $confdir
or die "couldn't open $confdir directory for reading:$!\n";
my $dbname;
while (my $dbfile = readdir(CONFDIR) ) {
if ($dbfile =~ /^(\w+)\.conf/) {
! push @db, $1;
} else {
next;
}
}
closedir CONFDIR;
! my %conf;
! my $conffile = catfile($confdir, 'gmod.conf');
! open CONF, $conffile or die "Unable to open $conffile: $!\n";
! while (<CONF>) {
! next if /^\#/;
! if (/(\w+)\s*=\s*(\S.*)$/) {
! $conf{$1}=$2;
}
}
+ close CONF;
! return bless {db => \@db,
! conf => \%conf,
confdir => $confdir}, $self;
}
***************
*** 111,116 ****
Status : public
! This method returns a list of database configuration files available in
! GMOD_ROOT/conf.
=cut
--- 103,108 ----
Status : public
! This method returns reference to a list of database configuration
! files available in GMOD_ROOT/conf.
=cut
***************
*** 118,151 ****
sub available_dbs {
! my $self = shift;
! my @dbs;
! my $dbs = $self->{'db'};
! foreach (keys %$dbs ) {
! next if $_ eq 'gmod';
! push @dbs, $_;
! }
! return @dbs;
}
! =head2 available_params
!
! Title : available_params
! Usage : @params = $config->available_params('chado');
Function: returns a list of parameters (ie, hash keys) for a given database
Returns : see above
! Args : The name of a database
Status : public
!
! Returns a list of database connection parameters (ie, hash keys) for
a given database configuration file.
!
=cut
!
! sub available_params {
my $self = shift;
! my $db = shift;
!
! my $params = $self->{'db'}{$db};
my @params;
foreach (keys %$params) {
--- 110,134 ----
sub available_dbs {
! shift->{'db'};
}
! =head2 all_tags
!
! Title : all_tags
! Usage : @tags = $config->all_tags();
Function: returns a list of parameters (ie, hash keys) for a given database
Returns : see above
! Args : none
Status : public
!
! Returns a list of database connection parameters (ie, hash keys) for
a given database configuration file.
!
=cut
! sub all_tags {
my $self = shift;
!
! my $params = $self->{'conf'};
my @params;
foreach (keys %$params) {
***************
*** 155,158 ****
--- 138,187 ----
}
+ =head2 has_tag
+
+ Title : has_tag
+ Usage : $bool = $conf->has_tag('TMP');
+ Function: Returns true if the tag is contained in the config file
+ Returns : see above
+ Args : name of tag
+ Status : public
+
+ =cut
+
+ sub has_tag{
+ my $self = shift;
+ my $tag = shift;
+
+ my $conf = $self->{'conf'};
+ if (defined $$conf{$tag}) {
+ return 1;
+ } else {
+ return 0;
+ }
+ }
+
+ =head2 get_tag_value
+
+ Title : get_tag_value
+ Usage : $value = $conf->get_tag_value($tag);
+ Function: return the value of a config parameter
+ Returns : see above
+ Args : name of a tag
+ Status : Public
+
+ =cut
+
+ sub get_tag_value {
+ my $self = shift;
+ my $tag = shift;
+
+ my $conf = $self->{'conf'};
+ if (defined $$conf{$tag}) {
+ return $$conf{$tag};
+ } else {
+ return;
+ }
+ }
+
=head2 confdir
***************
*** 169,173 ****
sub confdir {
! shift->{'conf'};
}
--- 198,202 ----
sub confdir {
! shift->{'confdir'};
}
***************
*** 186,192 ****
! sub tmp {
! my $self = shift;
! $self->{'db'}->{'gmod'}->{'TMP'};
}
--- 215,220 ----
! sub tmpdir {
! shift->get_tag_value('TMP');
}
|