[rt18107] Extracted the pathmap functionality from integrity-checker.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
25 The component of the INI file for which you want the paths
26 --srcpath
27 The source path to return the destination path for
28
29HELP
30 exit;
31}
32
33# load config
34die "No config file specified\n" unless ($config_file);
35die "Config file does not exist\n" unless (-r $config_file and -s $config_file);
36my $cfg = new Config::Simple($config_file);
37
38if (!$component) {
39 my @components = ();
40 #pull out components from INI file
41 open my $fh, '<', $config_file;
42 while (<$fh>) {
43 chomp;
44 if ($_ =~ /^\[[^]]+\]$/) {
45 $_ =~ s/[\[\]]//g;
46 push(@components, $_);
47 }
48 }
49 print "@components\n";
50} elsif (!$srcpath) {
51 foreach my $key (keys $cfg->get_block($component)) {
52 print $key . "\n";
53 }
54} else {
55 print $cfg->get_block($component)->{$srcpath};
56}
57