-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtransmitting_hash
More file actions
executable file
·172 lines (151 loc) · 3.55 KB
/
transmitting_hash
File metadata and controls
executable file
·172 lines (151 loc) · 3.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
#!/usr/bin/perl
use FindBin;
use lib $FindBin::Bin;
use strict;
use warnings FATAL => 'all';
use File::Basename;
use File::Temp;
use File::Path qw(make_path remove_tree);
use Storable qw(lock_store lock_nstore lock_retrieve);
use _kxLab;
my $program = basename( $0 );
my ($hardware, $flavour, $poolname, $operation, $name, $value);
my $value_only = 'no';
sub usage
{
print <<EOF;
Usage: $program [options]
Options:
{--get | --set} - type of operation;
--hardware=HARDWARE - where HARDWARE ia a current HARDWARE name;
--flavour=FLAVOUR - where FLAVOUR ia a current FLAVOUR name;
--pool-name=NAME - where NAME is the variables pool name;
--name=NAME - where NAME is a variable name;
--value=string - where 'string' is a value of variable;
--value-only - if this option is used then $program
prints out only value of required vatiable,
if this option is not used then $program
prints out the pair 'NAME=VALUE' without
spaces around of equal ('=') symbol.
EOF
exit;
}
# args:
# - environment pool name ( perl,for example );
# - hardware name ( ci20, for example );
# - flavour name ( m512, for example );
# - variable;
# - value;
sub save_env
{
my $fname = shift;
my $name = shift;
my $value = shift;
my $tabref;
if( -s $fname and defined( Storable::file_magic( $fname ) ) )
{
$tabref = lock_retrieve( $fname );
if( ! defined $tabref )
{
$tabref = 0;
}
}
$tabref->{ $name } = $value;
lock_store( \%$tabref, $fname );
}
sub get_env
{
my $fname = shift;
my $name = shift;
my $value = "";
my $tabref;
if( -s $fname and defined( Storable::file_magic( $fname ) ) )
{
$tabref = lock_retrieve( $fname );
}
if( defined $tabref )
{
my $val = $tabref->{ $name };
if( defined $val ) { $value = $val; }
}
return $value;
}
foreach ( @ARGV )
{
if( /--hardware=(\S*)/ )
{
$hardware = $1;
}
elsif( /--flavour=(\S*)/ )
{
$flavour = $1;
}
elsif( /--pool-name=(\S*)/ )
{
$poolname = $1;
}
elsif( /--name=(\S*)/ )
{
$name = $1;
}
elsif( /--value=(\S*)/ )
{
$value = $1;
}
elsif( /--set/ )
{
$operation = 'set';
}
elsif( /--get/ )
{
$operation = 'get';
}
elsif( /--value-only/ )
{
$value_only = 'yes';
}
elsif( /--help/ )
{
usage;
}
else
{
usage;
}
}
if( ! defined $hardware or $hardware eq "" ) { usage; }
if( ! defined $poolname or $poolname eq "" ) { usage; }
if( ! defined $operation or $operation eq "" ) { usage; }
if( ! defined $name or $name eq "" ) { usage; }
if( $operation eq 'set' )
{
if( ! defined $value or $value eq "" ) { usage; }
}
my $hash_fname;
if( defined $flavour and $flavour ne "" )
{
$hash_fname = _kxLab::build_system_tmpdir() . "/" . "." .
$hardware . "." . $flavour . "." . $poolname . ".transmitting-hash";
}
else
{
$hash_fname = _kxLab::build_system_tmpdir() . "/" . "." .
$hardware . "." . $poolname . ".transmitting-hash";
}
if( $operation eq 'set' )
{
save_env( $hash_fname, $name, $value );
}
else
{
my $val = get_env( $hash_fname, $name );
if( defined $val and $val ne "" )
{
$value = $val;
}
}
#
# ECHO according to '--value-only' option:
#
if( $value_only eq 'yes' ) { print $value ; }
else { print $name . "=" . $value ; }