[rt18107] Cleaned up access_pathmap.pl
[sitka/sitka-tools.git] / deployment / access_pathmap.pl
CommitLineData
bcd49ef3
LW
1#!/usr/bin/perl
2use strict;
3use warnings;
4use Config::Simple;
5use Getopt::Long;
6
7my ($help, $config_file, $component, $srcpath);
8
9GetOptions(
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
16if ($help) {
17 print <<"HELP";
18
19OPTIONS:
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
31HELP
32 exit;
33}
34
35# load config
36die "No config file specified\n" unless ($config_file);
37die "Config file does not exist\n" unless (-r $config_file and -s $config_file);
38my $cfg = new Config::Simple($config_file);
39
40if (!$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