950b72e5386527b12daf5f7d9dad09b77e13ea27
[spider.git] / perl / export_user.pl
1 #!/usr/bin/perl
2 #
3 # Export the user file in a form that can be directly imported
4 # back with a do statement
5 #
6
7 require 5.004;
8
9 # search local then perl directories
10 BEGIN {
11         # root of directory tree for this system
12         $root = "/spider"; 
13         $root = $ENV{'DXSPIDER_ROOT'} if $ENV{'DXSPIDER_ROOT'};
14         
15         unshift @INC, "$root/perl";     # this IS the right way round!
16         unshift @INC, "$root/local";
17 }
18
19 use DXVars;
20 use DXUser;
21
22 $userfn = $ARGV[0] if @ARGV;
23
24 DXUser->init($userfn);
25
26 @all = DXUser::get_all_calls();
27 $t = scalar time;
28 print "#!/usr/bin/perl
29 #
30 # The exported userfile for a DXSpider System
31
32 # Input file: $userfn
33 #       Time: $t
34 #
35
36 package DXUser;
37
38 %u = (
39 ";
40
41 for $a (@all) {
42         my $ref = DXUser->get($a);
43         print "'$a' => bless ( { ";
44         
45         my $f;
46         for $f (sort keys %{$ref}) {
47                 my $val = ${$ref}{$f};
48             $val =~ s/'/\\'/og;
49                 print "'$f' => '$val', ";
50         }
51         print " }, 'DXUser'),\n";
52         $count++;
53 }
54 print ");\n
55 #
56 # there were $count records
57 #\n";
58