Alt-CWB-ambs
view release on metacpan or search on metacpan
lib/CWB/Encoder.pm view on Meta::CPAN
}
return bless($self, $class);
}
=item $idx->group($group);
=item $idx->perm($permission);
Optional group membership and access permissions for newly created
files (otherwise, neither B<chgrp> nor B<chmod> will be called). Note
that I<$permission> must be a string rather than an octal number (as
for the built-in B<chmod> function). Indexing will fail if the
specified group and/or permissions cannot be set.
=cut
sub group {
my ($self, $group) = @_;
$self->{GROUP} = $group;
}
sub perm {
lib/CWB/Encoder.pm view on Meta::CPAN
if $self->{DEBUG};
CWB::Shell::Cmd $command; # execute creation command
my $perm = $self->{PERM}; # check that target file(s) exist and set permissions
my $group = $self->{GROUP};
foreach my $c (@$creates) {
my $f = $self->filename($att, $c);
croak "CWB::Indexer: Creation of component $att/$c ($f) failed (aborted).\n"
unless -s $f;
if ($perm) {
my $cmd = "chmod $perm '$f'";
print STDERR "CWB::Indexer: exec: $cmd\n"
if $self->{DEBUG};
CWB::Shell::Cmd $cmd;
}
if ($group) {
my $cmd = "chgrp $group '$f'";
print STDERR "CWB::Indexer: exec: $cmd\n"
if $self->{DEBUG};
CWB::Shell::Cmd $cmd;
}
lib/CWB/Encoder.pm view on Meta::CPAN
sub null_attributes {
my $self = shift;
push @{$self->{NATT}}, @_;
}
=item $enc->group($group);
=item $enc->perm($permission);
Optional group membership and access permissions for newly created
files (otherwise, neither B<chgrp> nor B<chmod> will be called). Note
that I<$permission> must be a string rather than an octal number (as
for the built-in B<chmod> function). Encoding will fail if the
specified group and/or permissions cannot be set. If the data
directory has to be created, its access permissions and group
membership are set accordingly.
=cut
sub group {
my ($self, $group) = @_;
$self->{GROUP} = $group;
}
lib/CWB/Encoder.pm view on Meta::CPAN
$dh->close;
}
else {
print "Creating data directory $dir ...\n"
if $self->{VERBOSE};
croak "CWB::Encoder: Can't create data directory $dir\n"
unless mkdir $dir;
my $perm = $self->{PERM};
if ($perm) {
$perm =~ tr[642][753]; # derive directory permissions
CWB::Shell::Cmd("chmod $perm '$dir'");
$perm = "(chmod $perm)";
}
else {
$perm = "";
}
my $group = $self->{GROUP};
if ($group) {
CWB::Shell::Cmd("chgrp $group '$dir'");
$group = "(chgrp $group)";
}
else {
lib/CWB/Encoder.pm view on Meta::CPAN
my $perm = $self->{PERM};
my $group = $self->{GROUP};
my $dir = $self->{DIR};
print "Setting access permissions ...\n" # set access permissions for created files
if $self->{VERBOSE};
foreach my $att (@{$self->{PATT}}) { # positional attributes
my $pattern = "'$dir'/$att.*";
print STDERR "CWB::Encoder: processing group $pattern\n"
if $self->{DEBUG} and ($perm or $group);
CWB::Shell::Cmd("chmod $perm $pattern")
if $perm;
CWB::Shell::Cmd("chgrp $group $pattern")
if $group;
}
foreach my $attspec (@{$self->{SATT}}) { # structural attributes
my $temp = $attspec; # don't modify original list
my $rec = ($temp =~ s/:([0-9]+)//) ? $1 : 0; # recursion depth
my ($att, @xmlatts) = split /\+/, $temp; # attribute name and XML tag attributes
foreach my $n ("", 1 .. $rec) { # indices of embedded regions
foreach my $ext ("", map {"_$_"} @xmlatts) { # extensions for XML tag attributes
my $pattern = "'$dir'/$att$ext$n.*";
print STDERR "CWB::Encoder: processing group $pattern\n"
if $self->{DEBUG} and ($perm or $group);
CWB::Shell::Cmd("chmod $perm $pattern")
if $perm;
CWB::Shell::Cmd("chgrp $group $pattern")
if $group;
}
}
}
print "Writing .info file ...\n" # write .info file
if $self->{VERBOSE};
my $infofile = "$dir/.info";
my $fh = CWB::OpenFile "> $infofile";
print $fh $self->{INFO}, "\n";
$fh->close;
CWB::Shell::Cmd("chmod $perm '$infofile'")
if $perm;
CWB::Shell::Cmd("chgrp $group '$infofile'")
if $group;
print "Editing registry entry ...\n" # edit registry file
if $self->{VERBOSE};
my $reg = $self->{REGISTRY};
my $name = $self->{NAME};
my $regfile = "$reg/$name";
my $rf = new CWB::RegistryFile $regfile;
croak "CWB::Encoder: Syntax error in registry entry $regfile\n"
unless defined $rf;
$rf->name($self->{LONGNAME});
# $rf->property("charset", $self->{CHARSET}); # -- already set by cwb-encode (since v2.2.101)
$rf->property("language", $self->{LANG});
$rf->write($regfile);
print STDERR "CWB::Encoder: registry entry $regfile has been edited\n"
if $self->{DEBUG};
print STDERR "CWB::Encoder: setting access permissions for $regfile\n"
if $self->{DEBUG} and ($perm or $group);
CWB::Shell::Cmd("chmod $perm '$regfile'")
if $perm;
CWB::Shell::Cmd("chgrp $group '$regfile'")
if $group;
my $idx = new CWB::Indexer "$reg:".(uc $name); # build indices and compress p-attributes
$idx->group($group)
if $group;
$idx->perm($perm)
if $perm;
$idx->memory($self->{MEMORY});
( run in 0.349 second using v1.01-cache-2.11-cpan-496ff517765 )