OSDN Git Service

some changes...
[otptools/otptools.git] / sfmag2wiki / s2wattach.pl
1 #!/usr/bin/perl
2 # SourceForge.JP Wiki manipulator
3 # by hylom
4 # This code is under GPL.
5 #
6
7 use warnings;
8 use strict;
9
10 use lib '/Users/hylom/otptools';
11
12 use utf8;
13 use open IO => ':utf8';
14 use open ':std';
15
16 use Getopt::Std;
17 use SourceForgeJP;
18 use IO::File;
19 use Term::Prompt;
20 use URI::Escape;
21 use Encode;
22 use File::Temp;
23 use Path::Class;
24
25 my $usage = <<EOD;
26 s2wattach.pl <file>
27 EOD
28
29 my $filename= shift @ARGV;
30 unless( $filename ) {
31     print $usage;
32     exit;
33 }
34
35 #my $project = "test11";
36 my $project = "hpc-parallel";
37 my $filepath = file($filename);
38 my $parent_dir = $filepath->parent();
39
40 my $txtpath = $parent_dir->file("wiki.txt");
41 my $pagename = get_pagename($txtpath, $project);
42
43 my $sf = WWW::SourceForgeJP->new();
44 my $ret = $sf->Wiki->post_attachment( project => $project,
45                                       page => $pagename,
46                                       file => $filepath );
47 if( $ret ) {
48     print "$filepath: upload succeed.\n";
49 } else {
50     print "$filepath: upload failed.\n";
51 }
52
53 sub get_pagename {
54     my $fullpath = shift @_;
55
56     my $fh = $fullpath->open("r");
57     if( ! $fh ) {
58         print STDERR "can't open: $fullpath: $!";
59         return
60     }
61     my $filename = <$fh>;
62     $fh->close();
63     chomp $filename;
64     return $filename;
65 }