annotate bundle_collection.pl @ 2:705ebd286b57 draft default tip

"planemo upload commit 7761f1e59039279728185e751f1a51b56fe14cb0"
author nml
date Mon, 24 Aug 2020 12:14:15 -0400
parents bae199dc511f
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2
705ebd286b57 "planemo upload commit 7761f1e59039279728185e751f1a51b56fe14cb0"
nml
parents: 0
diff changeset
1 #!/usr/bin/env perl
0
bae199dc511f planemo upload commit 75c510cf71217015f3f83baf61a4a54a3a1f4bfd
nml
parents:
diff changeset
2
bae199dc511f planemo upload commit 75c510cf71217015f3f83baf61a4a54a3a1f4bfd
nml
parents:
diff changeset
3 use strict;
bae199dc511f planemo upload commit 75c510cf71217015f3f83baf61a4a54a3a1f4bfd
nml
parents:
diff changeset
4 use warnings;
bae199dc511f planemo upload commit 75c510cf71217015f3f83baf61a4a54a3a1f4bfd
nml
parents:
diff changeset
5 use File::Copy;
bae199dc511f planemo upload commit 75c510cf71217015f3f83baf61a4a54a3a1f4bfd
nml
parents:
diff changeset
6 use File::Basename;
bae199dc511f planemo upload commit 75c510cf71217015f3f83baf61a4a54a3a1f4bfd
nml
parents:
diff changeset
7 use Getopt::Long;
bae199dc511f planemo upload commit 75c510cf71217015f3f83baf61a4a54a3a1f4bfd
nml
parents:
diff changeset
8 use Pod::Usage;
bae199dc511f planemo upload commit 75c510cf71217015f3f83baf61a4a54a3a1f4bfd
nml
parents:
diff changeset
9
bae199dc511f planemo upload commit 75c510cf71217015f3f83baf61a4a54a3a1f4bfd
nml
parents:
diff changeset
10 my ($html_file, $html_path, @args, %information, $folder);
bae199dc511f planemo upload commit 75c510cf71217015f3f83baf61a4a54a3a1f4bfd
nml
parents:
diff changeset
11
bae199dc511f planemo upload commit 75c510cf71217015f3f83baf61a4a54a3a1f4bfd
nml
parents:
diff changeset
12 Getopt::Long::Configure('bundling');
bae199dc511f planemo upload commit 75c510cf71217015f3f83baf61a4a54a3a1f4bfd
nml
parents:
diff changeset
13 GetOptions(
bae199dc511f planemo upload commit 75c510cf71217015f3f83baf61a4a54a3a1f4bfd
nml
parents:
diff changeset
14 'i|input=s' => \@args,
bae199dc511f planemo upload commit 75c510cf71217015f3f83baf61a4a54a3a1f4bfd
nml
parents:
diff changeset
15 'h|html=s' => \$html_file,
bae199dc511f planemo upload commit 75c510cf71217015f3f83baf61a4a54a3a1f4bfd
nml
parents:
diff changeset
16 'p|path=s' => \$html_path
bae199dc511f planemo upload commit 75c510cf71217015f3f83baf61a4a54a3a1f4bfd
nml
parents:
diff changeset
17 );
bae199dc511f planemo upload commit 75c510cf71217015f3f83baf61a4a54a3a1f4bfd
nml
parents:
diff changeset
18
bae199dc511f planemo upload commit 75c510cf71217015f3f83baf61a4a54a3a1f4bfd
nml
parents:
diff changeset
19 pod2usage(1) unless @args && $html_file && $html_path;
bae199dc511f planemo upload commit 75c510cf71217015f3f83baf61a4a54a3a1f4bfd
nml
parents:
diff changeset
20
bae199dc511f planemo upload commit 75c510cf71217015f3f83baf61a4a54a3a1f4bfd
nml
parents:
diff changeset
21 #At this point, the output directory does not exist yet. So we have to make it
bae199dc511f planemo upload commit 75c510cf71217015f3f83baf61a4a54a3a1f4bfd
nml
parents:
diff changeset
22 mkdir $html_path or die "Could not make directory $!";
bae199dc511f planemo upload commit 75c510cf71217015f3f83baf61a4a54a3a1f4bfd
nml
parents:
diff changeset
23
bae199dc511f planemo upload commit 75c510cf71217015f3f83baf61a4a54a3a1f4bfd
nml
parents:
diff changeset
24 #Now make a folder for all our files
bae199dc511f planemo upload commit 75c510cf71217015f3f83baf61a4a54a3a1f4bfd
nml
parents:
diff changeset
25 my $data_folder = $html_path."/Bundled_Collection";
bae199dc511f planemo upload commit 75c510cf71217015f3f83baf61a4a54a3a1f4bfd
nml
parents:
diff changeset
26 mkdir $data_folder or die "Could not make directory $!";
bae199dc511f planemo upload commit 75c510cf71217015f3f83baf61a4a54a3a1f4bfd
nml
parents:
diff changeset
27
bae199dc511f planemo upload commit 75c510cf71217015f3f83baf61a4a54a3a1f4bfd
nml
parents:
diff changeset
28 #Go through each list item
bae199dc511f planemo upload commit 75c510cf71217015f3f83baf61a4a54a3a1f4bfd
nml
parents:
diff changeset
29 foreach my $entry (@args)
bae199dc511f planemo upload commit 75c510cf71217015f3f83baf61a4a54a3a1f4bfd
nml
parents:
diff changeset
30 {
bae199dc511f planemo upload commit 75c510cf71217015f3f83baf61a4a54a3a1f4bfd
nml
parents:
diff changeset
31 #Get key and value. Remove any spaces
bae199dc511f planemo upload commit 75c510cf71217015f3f83baf61a4a54a3a1f4bfd
nml
parents:
diff changeset
32 my ($info, $file) = split /=/, $entry;
bae199dc511f planemo upload commit 75c510cf71217015f3f83baf61a4a54a3a1f4bfd
nml
parents:
diff changeset
33 my ($name, $ext) = split /,/, $info;
bae199dc511f planemo upload commit 75c510cf71217015f3f83baf61a4a54a3a1f4bfd
nml
parents:
diff changeset
34 $name=~s/ /_/g;
bae199dc511f planemo upload commit 75c510cf71217015f3f83baf61a4a54a3a1f4bfd
nml
parents:
diff changeset
35 my $full_name = $name.".".$ext;
bae199dc511f planemo upload commit 75c510cf71217015f3f83baf61a4a54a3a1f4bfd
nml
parents:
diff changeset
36
bae199dc511f planemo upload commit 75c510cf71217015f3f83baf61a4a54a3a1f4bfd
nml
parents:
diff changeset
37 #We store this for later to make the html file
bae199dc511f planemo upload commit 75c510cf71217015f3f83baf61a4a54a3a1f4bfd
nml
parents:
diff changeset
38 $information{$name}{$ext}=1;
bae199dc511f planemo upload commit 75c510cf71217015f3f83baf61a4a54a3a1f4bfd
nml
parents:
diff changeset
39
bae199dc511f planemo upload commit 75c510cf71217015f3f83baf61a4a54a3a1f4bfd
nml
parents:
diff changeset
40 #copy each file to its directory
bae199dc511f planemo upload commit 75c510cf71217015f3f83baf61a4a54a3a1f4bfd
nml
parents:
diff changeset
41
bae199dc511f planemo upload commit 75c510cf71217015f3f83baf61a4a54a3a1f4bfd
nml
parents:
diff changeset
42 my $file_path = $data_folder."/".$full_name;
bae199dc511f planemo upload commit 75c510cf71217015f3f83baf61a4a54a3a1f4bfd
nml
parents:
diff changeset
43
bae199dc511f planemo upload commit 75c510cf71217015f3f83baf61a4a54a3a1f4bfd
nml
parents:
diff changeset
44 copy($file,$file_path) or die "Could not copy $file to $file_path: $!";
bae199dc511f planemo upload commit 75c510cf71217015f3f83baf61a4a54a3a1f4bfd
nml
parents:
diff changeset
45 }
bae199dc511f planemo upload commit 75c510cf71217015f3f83baf61a4a54a3a1f4bfd
nml
parents:
diff changeset
46
bae199dc511f planemo upload commit 75c510cf71217015f3f83baf61a4a54a3a1f4bfd
nml
parents:
diff changeset
47 #Write out the html file
bae199dc511f planemo upload commit 75c510cf71217015f3f83baf61a4a54a3a1f4bfd
nml
parents:
diff changeset
48 open my $out, ">", $html_file or die "Could not open html file: $!";
bae199dc511f planemo upload commit 75c510cf71217015f3f83baf61a4a54a3a1f4bfd
nml
parents:
diff changeset
49
bae199dc511f planemo upload commit 75c510cf71217015f3f83baf61a4a54a3a1f4bfd
nml
parents:
diff changeset
50 my $num_keys = scalar(keys %information);
bae199dc511f planemo upload commit 75c510cf71217015f3f83baf61a4a54a3a1f4bfd
nml
parents:
diff changeset
51 my $num_vals = scalar(@args);
bae199dc511f planemo upload commit 75c510cf71217015f3f83baf61a4a54a3a1f4bfd
nml
parents:
diff changeset
52
bae199dc511f planemo upload commit 75c510cf71217015f3f83baf61a4a54a3a1f4bfd
nml
parents:
diff changeset
53 printf $out "<!DOCTYPE html>
bae199dc511f planemo upload commit 75c510cf71217015f3f83baf61a4a54a3a1f4bfd
nml
parents:
diff changeset
54 <html>
2
705ebd286b57 "planemo upload commit 7761f1e59039279728185e751f1a51b56fe14cb0"
nml
parents: 0
diff changeset
55 <head>
705ebd286b57 "planemo upload commit 7761f1e59039279728185e751f1a51b56fe14cb0"
nml
parents: 0
diff changeset
56 <style type=\"text/css\">
705ebd286b57 "planemo upload commit 7761f1e59039279728185e751f1a51b56fe14cb0"
nml
parents: 0
diff changeset
57
705ebd286b57 "planemo upload commit 7761f1e59039279728185e751f1a51b56fe14cb0"
nml
parents: 0
diff changeset
58 body {
705ebd286b57 "planemo upload commit 7761f1e59039279728185e751f1a51b56fe14cb0"
nml
parents: 0
diff changeset
59 font-family: sans-serif;
705ebd286b57 "planemo upload commit 7761f1e59039279728185e751f1a51b56fe14cb0"
nml
parents: 0
diff changeset
60 color: #000;
705ebd286b57 "planemo upload commit 7761f1e59039279728185e751f1a51b56fe14cb0"
nml
parents: 0
diff changeset
61 }
705ebd286b57 "planemo upload commit 7761f1e59039279728185e751f1a51b56fe14cb0"
nml
parents: 0
diff changeset
62
705ebd286b57 "planemo upload commit 7761f1e59039279728185e751f1a51b56fe14cb0"
nml
parents: 0
diff changeset
63 table {
705ebd286b57 "planemo upload commit 7761f1e59039279728185e751f1a51b56fe14cb0"
nml
parents: 0
diff changeset
64 margin-left: 3em;
705ebd286b57 "planemo upload commit 7761f1e59039279728185e751f1a51b56fe14cb0"
nml
parents: 0
diff changeset
65 text-align: center;
705ebd286b57 "planemo upload commit 7761f1e59039279728185e751f1a51b56fe14cb0"
nml
parents: 0
diff changeset
66 }
705ebd286b57 "planemo upload commit 7761f1e59039279728185e751f1a51b56fe14cb0"
nml
parents: 0
diff changeset
67 th {
705ebd286b57 "planemo upload commit 7761f1e59039279728185e751f1a51b56fe14cb0"
nml
parents: 0
diff changeset
68 text-align:center;
705ebd286b57 "planemo upload commit 7761f1e59039279728185e751f1a51b56fe14cb0"
nml
parents: 0
diff changeset
69 background-color: #000080;
705ebd286b57 "planemo upload commit 7761f1e59039279728185e751f1a51b56fe14cb0"
nml
parents: 0
diff changeset
70 color: #FFF;
705ebd286b57 "planemo upload commit 7761f1e59039279728185e751f1a51b56fe14cb0"
nml
parents: 0
diff changeset
71 padding: 0.4em;
705ebd286b57 "planemo upload commit 7761f1e59039279728185e751f1a51b56fe14cb0"
nml
parents: 0
diff changeset
72 }
705ebd286b57 "planemo upload commit 7761f1e59039279728185e751f1a51b56fe14cb0"
nml
parents: 0
diff changeset
73 td {
705ebd286b57 "planemo upload commit 7761f1e59039279728185e751f1a51b56fe14cb0"
nml
parents: 0
diff changeset
74 font-family: monospace;
705ebd286b57 "planemo upload commit 7761f1e59039279728185e751f1a51b56fe14cb0"
nml
parents: 0
diff changeset
75 text-align: left;
705ebd286b57 "planemo upload commit 7761f1e59039279728185e751f1a51b56fe14cb0"
nml
parents: 0
diff changeset
76 background-color: #EEE;
705ebd286b57 "planemo upload commit 7761f1e59039279728185e751f1a51b56fe14cb0"
nml
parents: 0
diff changeset
77 color: #000;
705ebd286b57 "planemo upload commit 7761f1e59039279728185e751f1a51b56fe14cb0"
nml
parents: 0
diff changeset
78 padding: 0.4em;
705ebd286b57 "planemo upload commit 7761f1e59039279728185e751f1a51b56fe14cb0"
nml
parents: 0
diff changeset
79 }
705ebd286b57 "planemo upload commit 7761f1e59039279728185e751f1a51b56fe14cb0"
nml
parents: 0
diff changeset
80 h2 {
705ebd286b57 "planemo upload commit 7761f1e59039279728185e751f1a51b56fe14cb0"
nml
parents: 0
diff changeset
81 color: #800000;
705ebd286b57 "planemo upload commit 7761f1e59039279728185e751f1a51b56fe14cb0"
nml
parents: 0
diff changeset
82 padding-bottom: 0;
705ebd286b57 "planemo upload commit 7761f1e59039279728185e751f1a51b56fe14cb0"
nml
parents: 0
diff changeset
83 margin-bottom: 0;
705ebd286b57 "planemo upload commit 7761f1e59039279728185e751f1a51b56fe14cb0"
nml
parents: 0
diff changeset
84 clear: left;
705ebd286b57 "planemo upload commit 7761f1e59039279728185e751f1a51b56fe14cb0"
nml
parents: 0
diff changeset
85 }
705ebd286b57 "planemo upload commit 7761f1e59039279728185e751f1a51b56fe14cb0"
nml
parents: 0
diff changeset
86 </style>
705ebd286b57 "planemo upload commit 7761f1e59039279728185e751f1a51b56fe14cb0"
nml
parents: 0
diff changeset
87 </head>
0
bae199dc511f planemo upload commit 75c510cf71217015f3f83baf61a4a54a3a1f4bfd
nml
parents:
diff changeset
88
2
705ebd286b57 "planemo upload commit 7761f1e59039279728185e751f1a51b56fe14cb0"
nml
parents: 0
diff changeset
89 <body>
705ebd286b57 "planemo upload commit 7761f1e59039279728185e751f1a51b56fe14cb0"
nml
parents: 0
diff changeset
90
705ebd286b57 "planemo upload commit 7761f1e59039279728185e751f1a51b56fe14cb0"
nml
parents: 0
diff changeset
91 <h2 id=\"M0\">Bundle Collection Summary</h2><br><br>
0
bae199dc511f planemo upload commit 75c510cf71217015f3f83baf61a4a54a3a1f4bfd
nml
parents:
diff changeset
92
2
705ebd286b57 "planemo upload commit 7761f1e59039279728185e751f1a51b56fe14cb0"
nml
parents: 0
diff changeset
93 Number of keys: $num_keys<br>
705ebd286b57 "planemo upload commit 7761f1e59039279728185e751f1a51b56fe14cb0"
nml
parents: 0
diff changeset
94 Number of values: $num_vals<br><br>
0
bae199dc511f planemo upload commit 75c510cf71217015f3f83baf61a4a54a3a1f4bfd
nml
parents:
diff changeset
95
2
705ebd286b57 "planemo upload commit 7761f1e59039279728185e751f1a51b56fe14cb0"
nml
parents: 0
diff changeset
96 <table border=\"1\">
705ebd286b57 "planemo upload commit 7761f1e59039279728185e751f1a51b56fe14cb0"
nml
parents: 0
diff changeset
97 <tr><th>File name</th><th>File type</th></tr>\n";
0
bae199dc511f planemo upload commit 75c510cf71217015f3f83baf61a4a54a3a1f4bfd
nml
parents:
diff changeset
98
bae199dc511f planemo upload commit 75c510cf71217015f3f83baf61a4a54a3a1f4bfd
nml
parents:
diff changeset
99 foreach my $key (sort(keys %information))
bae199dc511f planemo upload commit 75c510cf71217015f3f83baf61a4a54a3a1f4bfd
nml
parents:
diff changeset
100 {
bae199dc511f planemo upload commit 75c510cf71217015f3f83baf61a4a54a3a1f4bfd
nml
parents:
diff changeset
101
bae199dc511f planemo upload commit 75c510cf71217015f3f83baf61a4a54a3a1f4bfd
nml
parents:
diff changeset
102 foreach my $val (keys %{$information{$key}} )
bae199dc511f planemo upload commit 75c510cf71217015f3f83baf61a4a54a3a1f4bfd
nml
parents:
diff changeset
103 {
2
705ebd286b57 "planemo upload commit 7761f1e59039279728185e751f1a51b56fe14cb0"
nml
parents: 0
diff changeset
104 printf $out " <tr><td>$key</td><td>$val</td></tr>\n";
0
bae199dc511f planemo upload commit 75c510cf71217015f3f83baf61a4a54a3a1f4bfd
nml
parents:
diff changeset
105 }
bae199dc511f planemo upload commit 75c510cf71217015f3f83baf61a4a54a3a1f4bfd
nml
parents:
diff changeset
106 }
bae199dc511f planemo upload commit 75c510cf71217015f3f83baf61a4a54a3a1f4bfd
nml
parents:
diff changeset
107
2
705ebd286b57 "planemo upload commit 7761f1e59039279728185e751f1a51b56fe14cb0"
nml
parents: 0
diff changeset
108 printf $out " </table>\n</body>\n</html>";
0
bae199dc511f planemo upload commit 75c510cf71217015f3f83baf61a4a54a3a1f4bfd
nml
parents:
diff changeset
109
bae199dc511f planemo upload commit 75c510cf71217015f3f83baf61a4a54a3a1f4bfd
nml
parents:
diff changeset
110 close $out;
bae199dc511f planemo upload commit 75c510cf71217015f3f83baf61a4a54a3a1f4bfd
nml
parents:
diff changeset
111
bae199dc511f planemo upload commit 75c510cf71217015f3f83baf61a4a54a3a1f4bfd
nml
parents:
diff changeset
112 __END__
bae199dc511f planemo upload commit 75c510cf71217015f3f83baf61a4a54a3a1f4bfd
nml
parents:
diff changeset
113
bae199dc511f planemo upload commit 75c510cf71217015f3f83baf61a4a54a3a1f4bfd
nml
parents:
diff changeset
114 =head1 name
bae199dc511f planemo upload commit 75c510cf71217015f3f83baf61a4a54a3a1f4bfd
nml
parents:
diff changeset
115
bae199dc511f planemo upload commit 75c510cf71217015f3f83baf61a4a54a3a1f4bfd
nml
parents:
diff changeset
116 bundle_collection.pl - Downloads a collection from Galaxy
bae199dc511f planemo upload commit 75c510cf71217015f3f83baf61a4a54a3a1f4bfd
nml
parents:
diff changeset
117
bae199dc511f planemo upload commit 75c510cf71217015f3f83baf61a4a54a3a1f4bfd
nml
parents:
diff changeset
118 =head1 SYNOPSIS
bae199dc511f planemo upload commit 75c510cf71217015f3f83baf61a4a54a3a1f4bfd
nml
parents:
diff changeset
119
2
705ebd286b57 "planemo upload commit 7761f1e59039279728185e751f1a51b56fe14cb0"
nml
parents: 0
diff changeset
120 bundle_collection.pl -h html_file -p output_path -i "key=value"
0
bae199dc511f planemo upload commit 75c510cf71217015f3f83baf61a4a54a3a1f4bfd
nml
parents:
diff changeset
121
bae199dc511f planemo upload commit 75c510cf71217015f3f83baf61a4a54a3a1f4bfd
nml
parents:
diff changeset
122 =back
2
705ebd286b57 "planemo upload commit 7761f1e59039279728185e751f1a51b56fe14cb0"
nml
parents: 0
diff changeset
123 =cut