github
Advanced Search
  • Home
  • Pricing and Signup
  • Explore GitHub
  • Blog
  • Login

melo / scripts

  • Admin
  • Watch Unwatch
  • Fork
  • Your Fork
  • Pull Request
  • Download Source
    • 3
    • 0
  • Source
  • Commits
  • Network (0)
  • Issues (0)
  • Downloads (0)
  • Wiki (1)
  • Graphs
  • Branch: master

click here to add a description

click here to add a homepage

  • Branches (1)
    • master ✓
  • Tags (0)
Sending Request…
Enable Donations

Pledgie Donations

Once activated, we'll place the following badge in your repository's detail box:
Pledgie_example
This service is courtesy of Pledgie.

My personal script stash — Read more

  cancel

http://github.com/melo/scripts

  cancel
  • Private
  • Read-Only
  • HTTP Read-Only

This URL has Read+Write access

Added script to log my Apple battery status 
melo (author)
Thu Jan 28 17:03:02 -0800 2010
commit  5e5574e58980a0447196ca5c068c2091cb3e8027
tree    79e2d67db5f13c84c0512ca926d75abaf4177ffa
parent  aa73ec86ea9c75b9c2311be6c8d22a9c69e4c796
scripts / bin / x-perl-send-test-reports bin/x-perl-send-test-reports
100755 192 lines (157 sloc) 4.285 kb
edit raw blame history
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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
#!/usr/bin/env perl
#
# ** Send queued test reports **
#
# I like to use CPAN::Reporter, but the default behavior of sending the
# reports during my cpan runs is very slow.
#
# Fortunately, you can configure CPAN::Reporter to write the reports to
# a directory, and later send them all in a batch.
#
# First you need to configure your CPAN::Reporter. Create a
# $HOME/.cpanreporter/ directory and place a config.ini file inside with
# the following content:
#
# ---- 8< ------
# email_from = melo@simplicidade.org
# edit_report = no
#
# transport=File $QUEUE_DIR
# ---- 8< ------
#
# Adjust the email_from field to use your email, and adjust the
# $QUEUE_DIR directory path in the last line.
#
# I use `/Users/melo/.cpan/reports` as my $QUEUE_DIR, for example.
#
# **Make sure the directory exists**
#
# $ mkdir -p /Users/melo/.cpan/reports
#
# Then make sure your cpan command is configured to use CPAN::Reporter. The easiest way is:
#
# $ cpan
# cpan> o conf test_report 1
# cpan> o conf commit
# cpan> quit
#
# Done! You can now install your modules and a report will be created in
# the $QUEUE_DIR directory
#
# After you create your reports, you can send them later with this script. Just run:
#
# $ x-perl-send-test-reports $QUEUE_DIR
#
# Reports will be renamed to .done after they are send. You can run the
# script with --clean to remove those files.
#
 
use strict;
use warnings;
use 5.10.0;
use Test::Reporter;
use Getopt::Long;
use Path::Class qw( dir );
 
my $opt_clean;
my $opt_from;
my $opt_server;
my $opt_transport;
 
my @queues = parse_arguments();
scan_all_queues(@queues);
 
sub send_report {
  my ($file) = @_;
  
  my $tr = Test::Reporter->new;
  $tr->from($opt_from);
  $tr->mx([ $opt_server ]);
  $tr->transport(split(/\s+/, $opt_transport));
  $tr->via( 'x-perl-send-test-reports v0.1');
 
  return if $tr->read($file)->send;
  return $tr->errstr;
}
 
sub send_reports_in_queue {
  my $q = shift;
  
  scan_queue($q, qr{[.]rpt$}, sub {
    my ($file) = @_;
    local $| = 1;
    
    my $subject = find_subject($file);
    next unless $subject;
    
    print "Sending report for '$subject'... ";
    if (my $error = send_report($file)) {
      print "FAIL\n>> Error: $error\n";
    }
    else {
      if (rename($file, "$file.done")) {
        print "done!\n";
      }
      else {
        print "FAIL\n>>> Could not mark '$subject' as DONE, will be resent.\n";
      }
    }
  });
}
 
sub scan_all_queues {
  for my $q (@_) {
    send_reports_in_queue($q);
    clean_reports_in_queue($q) if $opt_clean;
  }
}
 
sub clean_reports_in_queue {
  my ($q) = @_;
  
  scan_queue($q, qr{[.]done$}, sub {
    $_->remove && print "Cleaned up '$_'\n";
  });
}
 
sub scan_queue {
  my ($q, $regexp, $cb) = @_;
  
  ITEM: while (my $item = $q->next) {
    next ITEM unless -f $item;
    local $_ = $item;
    $cb->($item) if $item =~ /$regexp/;
  }
}
 
sub find_subject {
  my ($rpt) = @_;
  my $subject;
  
  my $fh = $rpt->openr;
  for (1..5) {
    my $line = <$fh>;
    last unless $line;
    
    $subject = $1 if $line =~ m/^Subject:\s*(.+)/;
    last if $subject;
  }
  $fh->close;
  
  return $subject;
}
 
sub parse_arguments {
  GetOptions(
    "from=s" => \$opt_from,
    "server=s" => \$opt_server,
    "transport=s" => \$opt_transport,
    "clean" => \$opt_clean,
  ) || usage();
 
  usage('missing queue directory') unless @ARGV;
  usage('parameter --from is required') unless $opt_from;
  usage('parameter --server is required') unless $opt_server;
  
  for my $q (@ARGV) {
    usage("queue '$q' is not a directory") unless -d $q;
    $q = dir($q);
  }
  
  return @ARGV;
}
 
sub usage {
  my $mesg = join('', @_);
  
  print <<'USAGE';
Send test reports created with CPAN::Reporter.
 
Usage: x-perl-send-test-reports options queue1 ...
 
Options:
 
--from Email FROM address
--server SMTP server to use
--transport Tweak transport to use
--clean Remove reports that where sent sucessfully
 
Example: to send test reports via the GMail server:
 
x-perl-send-test-reports --from your@email --server smtp.gmail.com \
--transport "Net::SMTP::TLS User your@email Password your_gmail_password Port 587" \
~/.cpan/reports
 
USAGE
  
  print "\nFATAL: $mesg\n" if $mesg;
  
  exit(1);
}
 
 
Blog | Support | Training | Contact | API | Status | Twitter | Help | Security
© 2010 GitHub Inc. All rights reserved. | Terms of Service | Privacy Policy
Powered by the Dedicated Servers and
Cloud Computing of Rackspace Hosting®
Dedicated Server