source: LATMOS-Accounts/bin/la-create @ 78

Last change on this file since 78 was 78, checked in by nanardon, 15 years ago
  • la-create tools
  • Property svn:executable set to *
File size: 1.9 KB
Line 
1#!/bin/env perl
2
3use strict;
4use warnings;
5use LATMOS::Accounts;
6use Getopt::Long;
7use Pod::Usage;
8use File::Temp;
9
10GetOptions(
11    'c|config=s' => \my $config,
12    'b|base=s'   => \my $base,
13    'o|object=s' => \my $otype,
14    'help'       => sub { pod2usage(0) },
15) or pod2usage();
16
17$otype ||= 'user';
18
19my $LA = LATMOS::Accounts->new($config);
20my $labase = $base ? $LA->base($base) : $LA->default_base;
21$labase && $labase->load or die "Cannot load base";
22
23$labase->is_supported_object($otype) or die "$otype object unsupported\n";
24
25my @fields = $labase->list_canonicals_fields($otype, 'w');
26my %attr;
27
28while (1) {
29    my ($fh, $filename) = File::Temp::tempfile();
30    printf $fh "## new object %s: %s\n", $otype, $ARGV[0];
31    foreach (@fields) {
32        print $fh "$_:" . ($attr{$_} || '') . "\n";
33    }
34    close($fh);
35    my @stat = stat($filename);
36    system('vi', $filename, '+ 1');
37    if ((stat($filename))[9] == $stat[9]) {
38        warn "No change, aborting\n";
39        unlink($filename);
40        last;
41    } else {
42        open($fh, '<', $filename);
43        while (my $line = <$fh>) {
44            chomp($line);
45            $line =~ s/#.*//;
46            my ($fi, $val) = $line =~ /^(\w+)\s*:\s*(.*)/ or next;
47            $attr{$fi} = $val;
48        }
49        close($fh);
50        unlink($filename);
51        $labase->create_c_object($otype, $ARGV[0], %attr) or do {
52            warn "Cannot create object: Redit ?\n";
53            my $reply = <STDIN>;
54            $reply =~ /^[yY]/ or exit(1);
55            next;
56        };
57        $labase->commit;
58
59        warn $LA->default_synchro;
60        if (!$base) {
61            if (my $sync = $LA->default_synchro) {
62                for (1) {
63                    $sync->load_dest and do {
64                        warn  "Cannot load dest";
65                        last;
66                    };
67                    $sync->process();
68                }
69            }
70        }
71        last;
72    }
73}
Note: See TracBrowser for help on using the repository browser.