| 1 | #!/usr/bin/perl -w |
|---|
| 2 | |
|---|
| 3 | my $version = '0.1'; |
|---|
| 4 | |
|---|
| 5 | use strict; |
|---|
| 6 | |
|---|
| 7 | use Data::Dumper; |
|---|
| 8 | use XMLTV::Ask; |
|---|
| 9 | |
|---|
| 10 | my $config; |
|---|
| 11 | my $s; |
|---|
| 12 | |
|---|
| 13 | print "GConf Builder for Shepherd\n\n"; |
|---|
| 14 | |
|---|
| 15 | my $grabber = lc(ask("Name of grabber? ")); |
|---|
| 16 | |
|---|
| 17 | die "I don't think so.\n" if ($grabber eq 'shepherd'); |
|---|
| 18 | |
|---|
| 19 | print "\nCATEGORY: Grabber Type\n\n" . |
|---|
| 20 | "Grabbers generally fall into two categories:\n" . |
|---|
| 21 | "(1) Grabbers that fetch detailed data by downloading one page\n" . |
|---|
| 22 | " per show\n" . |
|---|
| 23 | "(2) Grabbers that either cannot fetch detailed data, or fetch\n" . |
|---|
| 24 | " it for many shows with each download (e.g. one download\n" . |
|---|
| 25 | " per day, or one download for all shows)\n" . |
|---|
| 26 | "Category 1 grabbers tend to be slow and use relatively large\n" . |
|---|
| 27 | "amounts of bandwidth. Category 2 grabbers are quite fast\n" . |
|---|
| 28 | "and download relatively few files.\n\n"; |
|---|
| 29 | $config->{category} = ask("Which category is $grabber?"); |
|---|
| 30 | |
|---|
| 31 | print "\nCATEGORY: Channels Supported\n\n" . |
|---|
| 32 | "Enter the names of channels supported by $grabber. If $grabber\n" . |
|---|
| 33 | "supports all free-to-air channels, just hit Enter. If it supports\n" . |
|---|
| 34 | "a limited number of channels, enter these separated by spaces\n" . |
|---|
| 35 | "(e.g. \"ABC ABC2\"). If it supports most channels with a\n" . |
|---|
| 36 | "limited number of exceptions, enter a minus sign then a list\n" . |
|---|
| 37 | "of the exceptions, separated by spaces (e.g. \"-ABC Nine\").\n" . |
|---|
| 38 | "Please use standard channel names (e.g. Nine, TEN, Seven, etc).\n\n"; |
|---|
| 39 | |
|---|
| 40 | $config->{channels} = ask("Channels supported? "); |
|---|
| 41 | |
|---|
| 42 | print "\nCATEGORY: Days Supported\n\n" . |
|---|
| 43 | "Enter how many days of data $grabber can retrieve. The current\n" . |
|---|
| 44 | "day is considered to be day 1.\n\n"; |
|---|
| 45 | |
|---|
| 46 | $config->{max_days} = ask("Days supported? [default=7]"); |
|---|
| 47 | $config->{max_days} ||= 7; |
|---|
| 48 | |
|---|
| 49 | print "\nSome grabbers aren't always able to retrieve the maximum number\n" . |
|---|
| 50 | "of days, because sometimes the datasource isn't topped up. Enter\n" . |
|---|
| 51 | "the minimum number of days of data that $grabber can reliably fetch,\n" . |
|---|
| 52 | "where today is day 1.\n\n"; |
|---|
| 53 | |
|---|
| 54 | $config->{min_days} = ask("Minimum days supported? [default=7]"); |
|---|
| 55 | $config->{min_days} ||= 7; |
|---|
| 56 | |
|---|
| 57 | print "\nCATEGORY: Configuration Requirements\n\n" . |
|---|
| 58 | "Specify whether $grabber requires any manual configuration\n" . |
|---|
| 59 | "before it can run (such as registration on a remote web site).\n\n"; |
|---|
| 60 | |
|---|
| 61 | $config->{config_reqd} = ask_boolean("Requires manual configuration? "); |
|---|
| 62 | |
|---|
| 63 | if ($config->{config_reqd}) |
|---|
| 64 | { |
|---|
| 65 | print "\nShepherd needs a way of detecting whether $grabber has been\n" . |
|---|
| 66 | "correctly configured or not. Please enter a command-line option\n" . |
|---|
| 67 | "that will cause $grabber to exit with status 0 if it is configured\n" . |
|---|
| 68 | "correctly, and exit with another status if it is not.\n\n"; |
|---|
| 69 | $config->{option_ready} = ask("Command-line option for readiness? [default=--ready]"); |
|---|
| 70 | $config->{option_ready} ||= '--ready'; |
|---|
| 71 | } |
|---|
| 72 | else |
|---|
| 73 | { |
|---|
| 74 | print "\nShepherd needs a way to run $grabber just to check that it compiles\n" . |
|---|
| 75 | "on the user's system. Please enter a command-line option that will cause\n" . |
|---|
| 76 | "$grabber to exit with status 0 as quickly as possible, i.e. preferably\n" . |
|---|
| 77 | "without fetching any data.\n\n"; |
|---|
| 78 | $config->{option_ready} = ask("Command-line option for compilation check? " . |
|---|
| 79 | "[default=--version]"); |
|---|
| 80 | $config->{option_read} ||= '--version'; |
|---|
| 81 | } |
|---|
| 82 | |
|---|
| 83 | print "\nCATEGORY: Niceness\n\n" . |
|---|
| 84 | "NOTE: This metric will probably change, so don't sweat it for now.\n". |
|---|
| 85 | "Rate the niceness of $grabber. Niceness is a general score out\n" . |
|---|
| 86 | "of 10 for how quickly, efficiently, and, well, nicely, the\n" . |
|---|
| 87 | "grabber can retrieve data.\n\n"; |
|---|
| 88 | |
|---|
| 89 | $config->{niceness} = ask("Niceness? [default=5]"); |
|---|
| 90 | $config->{niceness} ||= 5; |
|---|
| 91 | |
|---|
| 92 | my $g = ''; |
|---|
| 93 | |
|---|
| 94 | print "\nCATEGORY: Granularity\n\n" . |
|---|
| 95 | "Specify whether $grabber is able to fetch data in slices,\n" . |
|---|
| 96 | "as opposed to having to fetch all or nothing.\n\n"; |
|---|
| 97 | |
|---|
| 98 | $s = ask_boolean("Can $grabber fetch a single day of data only? "); |
|---|
| 99 | |
|---|
| 100 | if ($s) |
|---|
| 101 | { |
|---|
| 102 | $g .= 'd'; |
|---|
| 103 | print "\nWhat option needs to be sent to $grabber to specify the\n" . |
|---|
| 104 | "number of days wanted? (E.g. if $grabber supports an option\n" . |
|---|
| 105 | "\"--days n\", where n is the number of days to fetch data for,\n". |
|---|
| 106 | "enter \"--days\").\n\n"; |
|---|
| 107 | $config->{option_days} = ask("Command-line option for max days? " . |
|---|
| 108 | "[default=--days]"); |
|---|
| 109 | $config->{option_days} ||= '--days'; |
|---|
| 110 | |
|---|
| 111 | print "\nWhat option needs to be sent to $grabber to specify the\n" . |
|---|
| 112 | "day to begin fetching data for? (E.g. if $grabber\n" . |
|---|
| 113 | "supports an option \"--offset n\", where n is the first\n" . |
|---|
| 114 | "day to start grabbing data for, enter \"--offset\".)\n\n"; |
|---|
| 115 | $config->{option_days_offset} = ask("Command-line option for offset? " . |
|---|
| 116 | "[default=--offset]"); |
|---|
| 117 | $config->{option_days_offset} ||= '--offset'; |
|---|
| 118 | |
|---|
| 119 | print "\nAssuming today is day 1 and tomorrow is day 2, which day(s)\n" . |
|---|
| 120 | "will $grabber retrieve data for if invoked with the following\n" . |
|---|
| 121 | "command:\n" . |
|---|
| 122 | " ./$grabber $config->{option_days} 2 $config->{option_days_offset} 1\n" . |
|---|
| 123 | "Enter a range, such as \"2-4\" or \"2-2\".\n\n"; |
|---|
| 124 | $s = ask("Days fetched with the above option? " . |
|---|
| 125 | "[default=2-2]"); |
|---|
| 126 | $s ||= '2-2'; |
|---|
| 127 | if ($s =~ /(\d)-(\d)/) |
|---|
| 128 | { |
|---|
| 129 | $config->{option_days_adjust} = 2- $2; |
|---|
| 130 | $config->{option_days_offset_adjust} = 2- $1; |
|---|
| 131 | } |
|---|
| 132 | |
|---|
| 133 | } |
|---|
| 134 | |
|---|
| 135 | print "\n"; |
|---|
| 136 | |
|---|
| 137 | $s = ask_boolean("Can $grabber fetch a single channel of data only? "); |
|---|
| 138 | |
|---|
| 139 | if ($s) |
|---|
| 140 | { |
|---|
| 141 | $g .= 'c'; |
|---|
| 142 | print "\nWhat option needs to be sent to $grabber to specify\n" . |
|---|
| 143 | "the channels wanted? For example, if $grabber can be\n" . |
|---|
| 144 | "instructed to fetch data for channels Seven and Nine by\n" . |
|---|
| 145 | "the option \"--channels Seven,Nine\", enter \"--channels\".\n\n"; |
|---|
| 146 | |
|---|
| 147 | $config->{option_channels} = ask("Command-line option for channels? " . |
|---|
| 148 | "[default=--channels]"); |
|---|
| 149 | $config->{option_channels} ||= '--channels'; |
|---|
| 150 | } |
|---|
| 151 | |
|---|
| 152 | $config->{granularity} = $g; |
|---|
| 153 | |
|---|
| 154 | print "\nCATEGORY: Caching\n\n" . |
|---|
| 155 | "Some grabbers use an internal cache, to avoid re-fetching data.\n\n"; |
|---|
| 156 | |
|---|
| 157 | $config->{cache} = ask_boolean("Does $grabber use an internal cache?"); |
|---|
| 158 | |
|---|
| 159 | if ($config->{cache}) |
|---|
| 160 | { |
|---|
| 161 | |
|---|
| 162 | print "\nSome grabbers are able to run in \"cheap\" mode, which\n" . |
|---|
| 163 | "means they verify and return their internal cache without\n" . |
|---|
| 164 | "fetching many web pages or taking too long to run.\n\n"; |
|---|
| 165 | $config->{cheap_mode} = ask_boolean("Does $grabber have a \"cheap\" mode?"); |
|---|
| 166 | if ($config->{cheap_mode}) |
|---|
| 167 | { |
|---|
| 168 | $config->{option_cheap} = ask("\nWhat option enables this \"cheap\" " . |
|---|
| 169 | "mode? [default=--cheap]"); |
|---|
| 170 | $config->{option_cheap} ||= '--cheap'; |
|---|
| 171 | } |
|---|
| 172 | |
|---|
| 173 | # Possibly ask a question about cache verification |
|---|
| 174 | } |
|---|
| 175 | |
|---|
| 176 | print "\nCATEGORY: Description\n\n" . |
|---|
| 177 | "Please enter a brief description of $grabber.\n\n"; |
|---|
| 178 | |
|---|
| 179 | $config->{desc} = ask("Description?"); |
|---|
| 180 | |
|---|
| 181 | print "\nCONFIGURATION COMPLETE\n\n" . |
|---|
| 182 | "Grabber: $grabber\n" . |
|---|
| 183 | Dumper($config); |
|---|
| 184 | |
|---|
| 185 | abort() unless (ask_boolean("\nDo you want to go ahead and create $grabber.conf?")); |
|---|
| 186 | |
|---|
| 187 | if (-e "$grabber.conf") |
|---|
| 188 | { |
|---|
| 189 | print "WARNING: $grabber.conf already exists!\n"; |
|---|
| 190 | abort() unless (ask_boolean("Do you want to overwrite $grabber.conf?")); |
|---|
| 191 | } |
|---|
| 192 | |
|---|
| 193 | print "Creating $grabber.conf.\n"; |
|---|
| 194 | open(CONF, ">$grabber.conf") or die "cannot write to $grabber.conf: $!"; |
|---|
| 195 | print CONF Data::Dumper->Dump([$config], ['config']); |
|---|
| 196 | close CONF; |
|---|
| 197 | |
|---|
| 198 | print "Done.\n"; |
|---|
| 199 | |
|---|
| 200 | sub abort |
|---|
| 201 | { |
|---|
| 202 | print "Aborting.\n"; |
|---|
| 203 | exit; |
|---|
| 204 | } |
|---|