/[A3C]/bin/ldap2model.pl
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /bin/ldap2model.pl

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 98 by dpavlin, Wed Apr 30 21:27:54 2008 UTC revision 99 by dpavlin, Wed Apr 30 23:44:43 2008 UTC
# Line 5  use strict; Line 5  use strict;
5  # schema2model.pl - convert LDAP schema file into jifty model  # schema2model.pl - convert LDAP schema file into jifty model
6  #  #
7  # 04/30/08 20:55:21 CEST Dobrica Pavlinusic <dpavlin@rot13.org>  # 04/30/08 20:55:21 CEST Dobrica Pavlinusic <dpavlin@rot13.org>
8    #
9    # ./bin/ldap2model.pl data/all.ldif hrEduOrg
10    
11  use Net::LDAP::Schema;  use Net::LDAP::Schema;
12    use File::Slurp;
13  use Data::Dump qw/dump/;  use Data::Dump qw/dump/;
14    
15  my ( $path, $objectClass ) = @ARGV;  my ( $path, $objectClass ) = @ARGV;
# Line 16  die "usage: $0 path/to/schema.ldif inetO Line 19  die "usage: $0 path/to/schema.ldif inetO
19  my $schema = Net::LDAP::Schema->new;  my $schema = Net::LDAP::Schema->new;
20  $schema->parse ( $path ) or die $schema->error;  $schema->parse ( $path ) or die $schema->error;
21    
22    die "$objectClass objectClass not found in $path\n" unless $schema->objectclass( $objectClass );
23    
24    my $model = qq/package A3C::Model::$objectClass;
25    use strict;
26    use warnings;
27    
28    use Jifty::DBI::Schema;
29    
30    use A3C::Record schema {
31    
32    /;
33    
34    my $methods;
35    
36  sub entry {  sub entry {
37          my ( $e, $add ) = @_;          my ( $e, $add ) = @_;
38          my $out = qq/\tcolumn $_->{name} =>\n\t\tlabel is _('$_->{desc}')/;          my $name = $_->{name} || die "no name?";
39            $methods .= qq/sub $_ { \$_[0]->$name }\n/ foreach @{$_->{aliases}};
40            my $out = qq/\tcolumn $name =>\n\t\tlabel is _('$_->{desc}')/;
41          $out .= qq/,\n\t\t# single-value/ if $_->{'single-value'};          $out .= qq/,\n\t\t# single-value/ if $_->{'single-value'};
42          $out .= qq/,\n\t\tmax_length is $_->{max_length}/ if $_->{'max_length'};          $out .= qq/,\n\t\tmax_length is $_->{max_length}/ if $_->{'max_length'};
43          $out .= qq/,\n\t\t$add/ if $add;          $out .= qq/,\n\t\t$add/ if $add;
# Line 26  sub entry { Line 45  sub entry {
45          return $out;          return $out;
46  }  }
47    
48  my $model = qq/\t# $objectClass super: / . join(' ', $schema->superclass($objectClass)). qq/\n\n/;  $model .= qq/\t# $objectClass super: / . join(' ', $schema->superclass($objectClass)). qq/\n\n/ if $schema->superclass($objectClass);
49    
50  $model .= qq/\t# $objectClass must:\n\n/;  $model .= qq/\t# $objectClass must:\n\n/;
51    
# Line 42  map { Line 61  map {
61          $model .= entry( $_ );          $model .= entry( $_ );
62  } $schema->may( $objectClass );  } $schema->may( $objectClass );
63    
64  print $model;  $model .= qq/
65    
66    };
67    
68    $methods
69    
70    use A3C::DefaultACL;
71    
72    1;
73    /;
74    
75    my $model_path = "lib/A3C/Model/$objectClass.pm";
76    write_file( $model_path, $model );
77    warn "Created $model_path\n";

Legend:
Removed from v.98  
changed lines
  Added in v.99

  ViewVC Help
Powered by ViewVC 1.1.26