| 1 | #!/usr/bin/env perl |
|---|
| 2 | # |
|---|
| 3 | # GHNS Meta Template - create template file for GHNS upload |
|---|
| 4 | # Copyright (C) 2006 - 2008 Josef Spillner <josef@kstuff.org> |
|---|
| 5 | # Published under 'GNU AGPLv3 or later' conditions |
|---|
| 6 | |
|---|
| 7 | use strict; |
|---|
| 8 | use DateTime; |
|---|
| 9 | |
|---|
| 10 | if(!$ARGV[0]){ |
|---|
| 11 | print "Synopsis: ghnsmetatemplate <datafile> [<previewfile>]\n"; |
|---|
| 12 | exit 1; |
|---|
| 13 | } |
|---|
| 14 | |
|---|
| 15 | sub input { |
|---|
| 16 | my $prompt = shift(@_); |
|---|
| 17 | my $def = shift(@_); |
|---|
| 18 | |
|---|
| 19 | print $prompt; |
|---|
| 20 | if(!defined($def)){ |
|---|
| 21 | print " [required!]"; |
|---|
| 22 | } |
|---|
| 23 | print ":\n"; |
|---|
| 24 | |
|---|
| 25 | my $res = <STDIN>; |
|---|
| 26 | chomp $res; |
|---|
| 27 | if($res){ |
|---|
| 28 | return $res; |
|---|
| 29 | } |
|---|
| 30 | |
|---|
| 31 | if(!defined($def)){ |
|---|
| 32 | return input($prompt, $def); |
|---|
| 33 | } |
|---|
| 34 | return $def; |
|---|
| 35 | } |
|---|
| 36 | |
|---|
| 37 | my $dt = DateTime->now; |
|---|
| 38 | my $isodate = $dt->datetime; |
|---|
| 39 | |
|---|
| 40 | my $lang = input("Language (e.g. en)", ""); |
|---|
| 41 | |
|---|
| 42 | my $category = input("Category (e.g. korganizer/calendar)", undef); |
|---|
| 43 | my $name = input("Name of the entry (e.g. My First Calendar)", undef); |
|---|
| 44 | my $author = input("Author's name (e.g. Bill Writer)", undef); |
|---|
| 45 | my $author_email = input("Author's email (e.g. bwriter\@calendars.org)", ""); |
|---|
| 46 | my $licence = input("Licence name (e.g. GNU General Public Licence)", ""); |
|---|
| 47 | my $licence_agreement = input("Licence acronym (e.g. GPL)", ""); |
|---|
| 48 | my $summary = input("Description of the content (e.g. It's a nice calendar)", undef); |
|---|
| 49 | my $version = input("Version of the content (e.g. 0.1)", undef); |
|---|
| 50 | my $releasedate = "$isodate"; # TODO: server-side generation? |
|---|
| 51 | |
|---|
| 52 | my $payload = $ARGV[0]; |
|---|
| 53 | my $preview = ""; |
|---|
| 54 | if($ARGV[1]){ |
|---|
| 55 | $preview = $ARGV[1]; |
|---|
| 56 | } |
|---|
| 57 | |
|---|
| 58 | my $m = ""; |
|---|
| 59 | $m .= "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"; |
|---|
| 60 | $m .= "<ghnsupload>\n"; |
|---|
| 61 | $m .= " <stuff category=\"$category\">\n"; |
|---|
| 62 | $m .= " <name lang=\"$lang\">$name</name>\n"; |
|---|
| 63 | $m .= " <author email=\"$author_email\">$author</author>\n"; |
|---|
| 64 | $m .= " <licence agreement=\"$licence_agreement\">$licence</licence>\n"; |
|---|
| 65 | $m .= " <version>$version</version>\n"; |
|---|
| 66 | $m .= " <releasedate>$releasedate</releasedate>\n"; |
|---|
| 67 | $m .= " <summary lang=\"$lang\">$summary</summary>\n"; |
|---|
| 68 | $m .= " <preview lang=\"$lang\">$preview</preview>\n"; |
|---|
| 69 | $m .= " <payload lang=\"$lang\">$payload</payload>\n"; |
|---|
| 70 | $m .= " </stuff>\n"; |
|---|
| 71 | $m .= "</ghnsupload>\n"; |
|---|
| 72 | |
|---|
| 73 | print $m; |
|---|
| 74 | |
|---|