source: LATMOS-Accounts/bin/la-edit @ 591

Last change on this file since 591 was 457, checked in by nanardon, 15 years ago
  • add options to not load acls, command line tools are superuser command, then skip acls checks
  • Property svn:executable set to *
File size: 2.4 KB
Line 
1#!/usr/bin/perl
2
3use strict;
4use warnings;
5use LATMOS::Accounts;
6use Getopt::Long;
7use Pod::Usage;
8
9=head1 NAME
10
11    la-edit - Tools to edit object in LATMOS::Accounts system
12
13=head1 SYNOPSIS
14
15    la-query [options] [obj_id]
16
17=cut
18
19GetOptions(
20    'c|config=s' => \my $config,
21    'b|base=s'   => \my $base,
22    'o|object=s' => \my $otype,
23    'e|empty'    => \my $empty_attr,
24    'ro'         => \my $with_ro,
25    'f=s'        => \my $inputfile,
26    'help'       => sub { pod2usage(0) },
27) or pod2usage();
28
29$otype ||= 'user';
30
31=head1 OPTIONS
32
33=over 4
34
35=item -c|--config configfile
36
37Use this cofngiuration file instead the default one
38
39=item -b|--base basename
40
41Query this specific base instead default.
42
43=item -o|object object_type
44
45Query should be performed on this objects. Default is to user 'User' object.
46
47=item -e|--empty
48
49Include also unset attributes
50
51=item --ro
52
53Include also read-only attributes as comment
54
55=item -f FILE
56
57Use this file to get attributes (- use stdin)
58
59=back
60
61=cut
62
63my $LA = LATMOS::Accounts->new($config, noacl => 1);
64my $labase = $base ? $LA->base($base) : $LA->default_base;
65$labase && $labase->load or die "Cannot load base";
66
67sub input_from_handle {
68    my ($obj, $fh) = @_;
69    my %attr = LATMOS::Accounts::Utils::parse_obj_file($fh);
70    my $res = $obj->set_c_fields(%attr);
71    if($res) {
72        print "Changes applied\n";
73        $labase->commit;
74    }
75    return
76    $res ? 1 : 0;
77}
78
79if (my $ouid = shift(@ARGV)) {
80    my $obj = $labase->get_object($otype, $ouid) or do {
81        die "Object $otype $ouid not found\n";
82    };
83
84    if ($inputfile) {
85        my $handle;
86        if ($inputfile eq '-') {
87            $handle = *STDIN;
88        } else {
89            open($handle, '<', $inputfile) or die
90                "Cannot open input file $@\n";
91        }
92        my $res = input_from_handle($obj, $handle);
93        close($handle);
94        exit(!$res);
95    } else {
96        exit ! LATMOS::Accounts::Utils::dump_read_temp_file(
97            sub {
98                my ($fh) = @_;
99                $obj->text_dump($fh,
100                    {
101                        empty_attr => $empty_attr,
102                        only_rw => !$with_ro,
103                    }
104                );
105            },
106            sub {
107                my ($fh) = @_;
108                return input_from_handle($obj, $fh);
109            }
110        );
111    }
112} else {
113    foreach (sort $labase->list_objects($otype)) {
114        print "$_\n";
115    }
116}
Note: See TracBrowser for help on using the repository browser.