[Midnightbsd-cvs] mports: lib/Magus: Add start of new indexer, and various bug fixes.

ctriv at midnightbsd.org ctriv at midnightbsd.org
Mon Oct 29 17:17:12 EDT 2007


Log Message:
-----------
Add start of new indexer, and various bug fixes.

Modified Files:
--------------
    mports/Tools/lib/Magus:
        Chroot.pm (r1.10 -> r1.11)
        Index.pm (r1.3 -> r1.4)
        Port.pm (r1.6 -> r1.7)
        PortCategory.pm (r1.1 -> r1.2)

-------------- next part --------------
Index: Port.pm
===================================================================
RCS file: /home/cvs/mports/Tools/lib/Magus/Port.pm,v
retrieving revision 1.6
retrieving revision 1.7
diff -LTools/lib/Magus/Port.pm -LTools/lib/Magus/Port.pm -u -r1.6 -r1.7
--- Tools/lib/Magus/Port.pm
+++ Tools/lib/Magus/Port.pm
@@ -146,6 +146,89 @@
 }
 
 
+=head2 $port->set_result_pass($phase => $name => $message);
+
+A convience method for setting a port as passed.  Creates one subresult of
+type C<$name>, with message C<$message> in phase C<$phase>.
+
+=cut
+
+sub set_result_pass {
+  my ($self, $phase, $name, $msg) = @_;
+  
+  $self->_set_result('pass', $phase, $name, $msg);
+}
+
+
+=head2 $port->set_result_skip($phase => $name => $message);
+
+A convience method for setting a port as skipped.  Creates one subresult of
+type C<$name>, with message C<$message> in phase C<$phase>.
+
+=cut
+
+sub set_result_skip {
+  my ($self, $phase, $name, $msg) = @_;
+  
+  $self->_set_result('skip', $phase, $name, $msg);
+}
+
+
+=head2 $port->set_result_internal($phase => $name => $message);
+
+A convience method for setting a port as internalled.  Creates one subresult of
+type C<$name>, with message C<$message> in phase C<$phase>.
+
+=cut
+
+sub set_result_internal {
+  my ($self, $phase, $name, $msg) = @_;
+  
+  $self->_set_result('internal', $phase, $name, $msg);
+}
+
+
+=head2 $port->set_result_fail($phase, $name => $message);
+
+A convience method for setting a port as failed.  Creates one subresult of
+type C<$name>, with message C<$message> in phase C<$phase>.
+
+=cut
+
+sub set_result_fail {
+  my ($self, $phase, $name, $msg) = @_;
+  
+  $self->_set_result('fail', $phase, $name, $msg);
+}
+
+
+
+sub _set_result {
+  my ($self, $summary, $phase, $name, $msg) = @_;
+  
+  my $result;
+  
+  if ($result = $self->current_result) {
+    $result->delete;
+  }
+  
+  $result = $self->add_to_results({
+    version => $self->version,
+    arch    => $Magus::Machine->arch,
+    machine => $Magus::Machine,
+    summary => $summary,
+  });
+  
+  $result->add_to_subresults({
+    type  => $summary,
+    name  => $name,
+    msg   => $msg,
+    phase => $phase,
+  });
+}
+
+
+
 
 1;
 __END__
Index: Chroot.pm
===================================================================
RCS file: /home/cvs/mports/Tools/lib/Magus/Chroot.pm,v
retrieving revision 1.10
retrieving revision 1.11
diff -LTools/lib/Magus/Chroot.pm -LTools/lib/Magus/Chroot.pm -u -r1.10 -r1.11
--- Tools/lib/Magus/Chroot.pm
+++ Tools/lib/Magus/Chroot.pm
@@ -96,6 +96,12 @@
   my ($self) = @_;
   
   $self->{root} = "$self->{prefix}/$self->{branch}";
+
+  # check to make sure that things are working properly in the chroot, a restart
+  # or deleting /usr/mports can break the loopback.
+  if (!-e "$self->{root}/usr/mports/Makefile") {
+    $self->delete;
+  }
   
   # if the chroot dir exists and is clean, then we're done.
   return if -e "$self->{root}/.clean";
@@ -265,8 +271,9 @@
   my ($self) = @_;
   
   for (qw(/dev /usr/src /usr/mports)) {
-    system("/sbin/umount $self->{root}$_") == 0 
-      or die "umount returned non-zero: $?\n";
+    # if umount failed it is probably because nothing was mounted.
+    # therefore we ignore the error code here 
+    system("/sbin/umount $self->{root}$_") 
   }
   
   system("/bin/chflags 0 $self->{root}/var/empty") == 0 
Index: Index.pm
===================================================================
RCS file: /home/cvs/mports/Tools/lib/Magus/Index.pm,v
retrieving revision 1.3
retrieving revision 1.4
diff -LTools/lib/Magus/Index.pm -LTools/lib/Magus/Index.pm -u -r1.3 -r1.4
--- Tools/lib/Magus/Index.pm
+++ Tools/lib/Magus/Index.pm
@@ -32,34 +32,79 @@
 use strict;
 use warnings;
 
-use base 'Mport::Index';
+use Mport::Utils qw(make_var recurse_ports);
   
-  
-sub create_db {
+use Fatal qw(chdir);
+use YAML qw(Load);
+ 
+sub sync {
   my ($class) = @_;
   
-  return DBI->connect(
-    "DBI:mysql:database=$Magus::Config{DBName}:host=$Magus::Config{DBHost}",
-    $Magus::Config{DBUser},
-    $Magus::Config{DBPass},
-    { RaiseError => 1, PrintError => 0 },
-  );
-}  
+  recurse_ports {
+    my $yaml = `BATCH=1 PACKAGE_BUILDING=1 MAGUS=1 make describe-yaml`;
+    my %dump;
+    
+    eval {
+      %dump = %{ Load($yaml) };
+    };
+    
+    if ($@) {
+      warn "Unable to parse yaml for $_[0]: $@\n";
+      return;
+    }
+    
+    my $port = Magus::Port->find_or_create({ name => $dump{name} });
+    
+    $port->version($dump{version});
+    $port->description($dump{description});
+    $port->pkgname($dump{pkgname});
+    $port->license($dump{license});
+    $port->update;
+    
+    $class->sync_depends(\%dump, $port);
+    $class->sync_categories(\%dump, $port);
+    
+    if ($dump{is_interactive}) {
+      $port->set_result_skip(index => IsInteractive => "Port is marked as interactive.");
+    }
+  };
+  
+  my $ports = Magus::Port->retrieve_all;
   
+  while (my $port = $ports->next) {
+    unless (-d $port->origin) {
+      $port->set_result_fail(index => BadDirMakefile => "$port does not exist but is in the directory makefile.");
+    }
+  }
+}
+
 
-sub insert_depends {
-  my ($class, $port, $dbh) = @_;
+sub sync_categories {
+    my ($class, $dump, $port) = @_;
+    
+    Magus::PortCategory->search(port => $port)->delete_all;
+    
+    for (@{$dump->{'categories'}}) {
+      my $cat = Magus::Category->find_or_create({ category => $_});
+      $port->add_to_categories({ category => $cat });
+    }
+}
+  
+sub sync_depends {
+  my ($class, $dump, $port) = @_;
   
   # We only have one depend type, merge into a unique list
   my %depends;
-  while (my ($type, $deps) = each %{$port->{'depends'}}) {
+  while (my ($type, $deps) = each %{$dump->{'depends'}}) {
     foreach my $dep (@$deps) {
       $depends{$dep}++;
     }
   }
   
+  Magus::Depend->search(port => $port)->delete_all;
+  
   foreach my $dep (keys %depends) {
-    Magus::Depend->insert({port => $port->{'name'}, dependency => $dep});
+    $port->add_to_depends({ dependency => $dep });
   }
 }  
        
Index: PortCategory.pm
===================================================================
RCS file: /home/cvs/mports/Tools/lib/Magus/PortCategory.pm,v
retrieving revision 1.1
retrieving revision 1.2
diff -LTools/lib/Magus/PortCategory.pm -LTools/lib/Magus/PortCategory.pm -u -r1.1 -r1.2
--- Tools/lib/Magus/PortCategory.pm
+++ Tools/lib/Magus/PortCategory.pm
@@ -34,7 +34,7 @@
 use base qw(Magus::DBI);
 
 
-__PACKAGE__->table('categories');
+__PACKAGE__->table('port_categories');
 __PACKAGE__->columns(Essential => qw/port category/);
 __PACKAGE__->has_a(port => 'Magus::Port');
 __PACKAGE__->has_a(category => 'Magus::Category');


More information about the Midnightbsd-cvs mailing list