Commit | Line | Data |
---|---|---|
bcd49ef3 LW |
1 | #!/usr/bin/perl |
2 | use strict; | |
3 | use warnings; | |
4 | use Config::Simple; | |
5 | use Getopt::Long; | |
6 | ||
7 | my ($help, $config_file, $component, $srcpath); | |
8 | ||
9 | GetOptions( | |
10 | 'help' => \$help, # show help message and exit | |
11 | 'config=s' => \$config_file, # INI file for path mappings | |
12 | 'component=s' => \$component, # The component to grab the source paths for | |
13 | 'srcpath=s' => \$srcpath # The source path to grap the destination path for | |
14 | ); | |
15 | ||
16 | if ($help) { | |
17 | print <<"HELP"; | |
18 | ||
19 | OPTIONS: | |
20 | --help | |
21 | Show help message and exit. | |
22 | --config | |
23 | Location of INI file for path mappings. | |
24 | --component | |
c6a6221d LW |
25 | The component of the INI file for which you want the paths. |
26 | If you do not specify a component value then all components | |
27 | (sections) in the INI file are returned. | |
bcd49ef3 LW |
28 | --srcpath |
29 | The source path to return the destination path for | |
30 | ||
31 | HELP | |
32 | exit; | |
33 | } | |
34 | ||
35 | # load config | |
36 | die "No config file specified\n" unless ($config_file); | |
37 | die "Config file does not exist\n" unless (-r $config_file and -s $config_file); | |
38 | my $cfg = new Config::Simple($config_file); | |
39 | ||
40 | if (!$component) { | |
41 | my @components = (); | |
42 | #pull out components from INI file | |
43 | open my $fh, '<', $config_file; | |
44 | while (<$fh>) { | |
45 | chomp; | |
46 | if ($_ =~ /^\[[^]]+\]$/) { | |
c6a6221d LW |
47 | $_ =~ s/^\[//; |
48 | $_ =~ s/\]$//; | |
49 | #we use newlines because spaces seem to be valid within an INI file section. | |
50 | #I am not sure if newlines are also valid because I could not find anything | |
51 | #defining the INI section syntax, but I imagine using a newline within an INI | |
52 | #file section declartion is not done very often if it is valid syntax. | |
53 | print "$_\n"; | |
bcd49ef3 LW |
54 | } |
55 | } | |
bcd49ef3 LW |
56 | } elsif (!$srcpath) { |
57 | foreach my $key (keys $cfg->get_block($component)) { | |
c6a6221d LW |
58 | #again we use newlines because spaces can be used within directory names. I belive |
59 | #it is possible to use a newline in a directory name, but someone would have to be | |
60 | #trying really hard to make things break if they started doing that with the Evergreen | |
61 | #source. | |
bcd49ef3 LW |
62 | print $key . "\n"; |
63 | } | |
64 | } else { | |
65 | print $cfg->get_block($component)->{$srcpath}; | |
66 | } | |
67 |