~ubuntu-branches/ubuntu/raring/texlive-extra/raring

« back to all changes in this revision

Viewing changes to texmf-dist/scripts/ctanupload/ctanupload.pl

  • Committer: Package Import Robot
  • Author(s): Norbert Preining
  • Date: 2012-05-16 08:22:07 UTC
  • mfrom: (1.1.12) (3.1.20 sid)
  • Revision ID: package-import@ubuntu.com-20120516082207-41ox35jj1qsu46a7
Tags: 2012.20120516-1
* new upstream snapshot based on TL2012 tlpretest
* switch to xz compression for orig and deb (Closes: #672428)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#!/usr/bin/perl
2
2
################################################################################
3
 
# Copyright (c) 2011 Martin Scharrer <martin@scharrer-online.de>
 
3
# Copyright (c) 2011-2012 Martin Scharrer <martin@scharrer-online.de>
4
4
# This is open source software under the GPL v3 or later.
5
5
################################################################################
6
6
use strict;
10
10
sub load_data;
11
11
sub save_data;
12
12
 
13
 
my $VERSION = 'v1.2b from 2012/05/06';
 
13
my $VERSION = 'v1.2c from 2012/05/08';
14
14
my %CTAN_SERVERURLS = (
15
15
    dante     => 'http://dante.ctan.org/upload.html',
16
16
    uktug     => 'http://www.tex.ac.uk/upload/',
235
235
$CTAN_URL = (values %CTAN_SERVERURLS)[int rand scalar values %CTAN_SERVERURLS]
236
236
    if not defined $CTAN_URL;
237
237
 
 
238
my $DANTE = $CTAN_URL =~ /dante/;
 
239
 
238
240
PROMPT:
239
241
 
240
242
if ($PROMPT) {
243
245
            my $input = '';
244
246
            if ($field eq 'notes' || $field eq 'announce') {
245
247
                next if $field eq 'announce' and $FIELDS{DoNotAnnounce};
246
 
                next if $field eq 'notes' and $CTAN_URL ne $CTAN_SERVERURLS{dante};
 
248
                next if $field eq 'notes' and not $DANTE;
247
249
                print "\u$FIELDS_DESC{$field}: (press CTRL-Z (Windows) or CTRL-D (Linux) to stop)\n";
248
250
                while (<STDIN>) {
249
251
                    $input .= $_;
336
338
    exit (2);
337
339
}
338
340
 
339
 
my $DoNotAnnounce;
340
 
if ($FIELDS{DoNotAnnounce}) {
341
 
    $FIELDS{DoNotAnnounce} = 'No';
342
 
    $FIELDS{to_announce}   = 'Yes';
343
 
    $DoNotAnnounce = '[x]';
344
 
}
345
 
else {
346
 
    $FIELDS{DoNotAnnounce} = 'Yes';
347
 
    delete $FIELDS{to_announce};
348
 
    $DoNotAnnounce = '[ ]';
349
 
}
350
 
# Only keep the announcement field used by the site:
351
 
if ($CTAN_URL eq $CTAN_SERVERURLS{dante}) {
352
 
    delete $FIELDS{to_announce};
353
 
}
354
 
else {
355
 
    delete $FIELDS{DoNotAnnounce};
356
 
}
 
341
my $DoNotAnnounce = ($FIELDS{DoNotAnnounce}) ? '[x]' : '[ ]';
357
342
 
358
343
if (!$FIELDS{directory}) {
359
344
    $FIELDS{directory} = '/macros/latex/contrib/' . $FIELDS{contribution};
395
380
        if ($response eq 'e' or $response eq 'edit') {
396
381
            my $file = 'ctanupload.dat';
397
382
            save_data($file);
398
 
            if (not defined $ENV{EDITOR}) {
 
383
            my $editor = $ENV{'CTANUPLOAD_EDITOR'} || $ENV{'EDITOR'};
 
384
            if (not defined $editor) {
399
385
                print "No EDITOR environment variable defined.\n";
400
386
                print "Data was stored in file '$file'. Please edit manually and load with the -F option.\n";
401
387
                exit (1);
402
388
            }
403
389
            else {
404
 
                system($ENV{EDITOR}, $file);
 
390
                system($editor, $file);
405
391
                load_data($file);
406
392
                goto PROMPT;
407
393
            }
421
407
    }
422
408
}
423
409
 
 
410
if ($FIELDS{DoNotAnnounce}) {
 
411
    if ($DANTE) {
 
412
        $FIELDS{DoNotAnnounce} = 'No';
 
413
        delete $FIELDS{'to_announce'};
 
414
        $FIELDS{notes} = '';
 
415
    } else {
 
416
        $FIELDS{'to_announce'} = 'Yes';
 
417
        delete $FIELDS{DoNotAnnounce};
 
418
        delete $FIELDS{notes};
 
419
    }
 
420
}
 
421
else {
 
422
    if ($DANTE) {
 
423
        $FIELDS{DoNotAnnounce} = 'Yes';
 
424
        delete $FIELDS{to_announce};
 
425
    } else {
 
426
        delete $FIELDS{'to_announce'};
 
427
        delete $FIELDS{DoNotAnnounce};
 
428
        delete $FIELDS{notes};
 
429
    }
 
430
}
 
431
# Add Submit button for the sake of completeness:
 
432
$FIELDS{'SUBMIT'} = ($DANTE) ? 'Submit' : 'Submit contribution';
424
433
 
425
434
use WWW::Mechanize;
426
435
my $mech = WWW::Mechanize->new(quiet => $QUIET, autocheck => 1);
440
449
print "\nResponse:\n";
441
450
print LOG "\n# Response:\n" if $LOG;
442
451
eval {
443
 
    #print $mech->content();
444
 
    #return 1;
445
 
    use HTML::TreeBuilder;
446
 
    use HTML::FormatText;
447
 
    my $tree = HTML::TreeBuilder->new_from_content( $mech->content() );
448
 
    my $formatter = HTML::FormatText->new(leftmargin => 0, rightmargin => 80);
449
 
    my @response = split /\n/, $formatter->format($tree);
450
 
    local $, = "\n";
451
 
    print @response[3..$#response-3];
452
 
    local $, = "\n# ";
453
 
    print LOG '', @response[3..$#response-3] if $LOG;
 
452
    if ($mech->response()->header('Content-Type') eq 'text/plain') {
 
453
        #open (my $DEBUGFILE, '>', 'ctanupload.dbg');
 
454
        #print {$DEBUGFILE} $mech->content();
 
455
        #close ($DEBUGFILE);
 
456
        print $mech->content();
 
457
        print LOG $mech->content() if $LOG;
 
458
    }
 
459
    else {
 
460
        use HTML::TreeBuilder;
 
461
        use HTML::FormatText;
 
462
        my $tree = HTML::TreeBuilder->new_from_content( $mech->content() );
 
463
        my $formatter = HTML::FormatText->new(leftmargin => 0, rightmargin => 80);
 
464
        my @response = split /\n/, $formatter->format($tree);
 
465
        local $, = "\n";
 
466
        print @response[3..$#response-3];
 
467
        local $, = "\n# ";
 
468
        print LOG '', @response[3..$#response-3] if $LOG;
 
469
    }
454
470
    1;
455
471
} or do {
456
472
    print "Can't display HTML response, storing reponse if log file 'ctanupload_response.html'\n";