1 |
joko |
1.1 |
## --------------------------------------------------------------------------- |
2 |
joko |
1.2 |
## $Id: shortcuts.pm,v 1.1 2003/02/09 04:49:45 joko Exp $ |
3 |
joko |
1.1 |
## --------------------------------------------------------------------------- |
4 |
|
|
## $Log: shortcuts.pm,v $ |
5 |
joko |
1.2 |
## Revision 1.1 2003/02/09 04:49:45 joko |
6 |
|
|
## + shortcuts now refactored to this file |
7 |
|
|
## |
8 |
joko |
1.1 |
## --------------------------------------------------------------------------- |
9 |
|
|
|
10 |
|
|
|
11 |
|
|
package shortcuts; |
12 |
|
|
|
13 |
|
|
use strict; |
14 |
|
|
use warnings; |
15 |
|
|
|
16 |
|
|
require Exporter; |
17 |
|
|
our @ISA = qw( Exporter ); |
18 |
|
|
our @EXPORT_OK = qw( |
19 |
|
|
strftime |
20 |
|
|
now today |
21 |
|
|
run_cmd run_cmds |
22 |
|
|
get_chomped |
23 |
joko |
1.2 |
bool2status |
24 |
joko |
1.1 |
); |
25 |
|
|
|
26 |
|
|
|
27 |
|
|
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - main |
28 |
|
|
|
29 |
|
|
use Data::Dumper; |
30 |
|
|
use POSIX qw(strftime); |
31 |
|
|
|
32 |
|
|
# $now_string = strftime "%a %b %e %H:%M:%S %Y", localtime; |
33 |
|
|
# see "perldoc -f localtime" |
34 |
|
|
|
35 |
|
|
sub now { |
36 |
|
|
my $options = shift; |
37 |
|
|
my $pattern = "%Y-%m-%d %H:%M:%S"; |
38 |
|
|
$pattern = "%Y-%m-%d_%H-%M-%S" if $options->{fs}; |
39 |
|
|
my $result = strftime($pattern, localtime); |
40 |
|
|
return $result; |
41 |
|
|
} |
42 |
|
|
|
43 |
|
|
sub today { |
44 |
|
|
return strftime("%Y-%m-%d", localtime); |
45 |
|
|
} |
46 |
|
|
|
47 |
|
|
sub run_cmd { |
48 |
|
|
my $cmd = shift; |
49 |
|
|
my $caption = shift; |
50 |
|
|
#$cmd = 'perl ' . $cmd; |
51 |
|
|
my $sep = "-" x 90; |
52 |
|
|
print $sep, "\n"; |
53 |
|
|
print " ", $cmd, "\n"; |
54 |
|
|
print " ", $caption, "\n" if $caption; |
55 |
|
|
print $sep, "\n"; |
56 |
|
|
system($cmd); |
57 |
|
|
#`$cmd`; |
58 |
|
|
print "ready.", "\n"; |
59 |
|
|
} |
60 |
|
|
|
61 |
|
|
sub run_cmds { |
62 |
|
|
foreach (@_) { |
63 |
|
|
run_cmd($_); |
64 |
|
|
} |
65 |
|
|
} |
66 |
|
|
|
67 |
|
|
sub get_chomped { |
68 |
|
|
my $str = shift; |
69 |
|
|
chomp($str); |
70 |
|
|
return $str; |
71 |
joko |
1.2 |
} |
72 |
|
|
|
73 |
|
|
sub bool2status { |
74 |
|
|
my $bool = shift; |
75 |
|
|
return ($bool ? 'ok' : 'failed'); |
76 |
joko |
1.1 |
} |
77 |
|
|
|
78 |
|
|
1; |