root/util/gconf-builder @ 473

Revision 473, 9.3 kB (checked in by max, 6 years ago)

Micrograbs in .conf files

  • Property svn:executable set to *
Line 
1#!/usr/bin/perl -w
2
3my $version = '0.1';
4
5use strict;
6
7use Data::Dumper;
8use XMLTV::Ask;
9
10my $config;
11my $s;
12
13print "GConf Builder for Shepherd\n\n";
14
15my $grabber = lc(ask("Name of grabber? "));
16
17die "I don't think so.\n" if ($grabber eq 'shepherd');
18
19print   "\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_choice("Which category is $grabber?", 1, 1, 2);
30
31print   "\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 commas\n" .
35        "(e.g. \"SBS,SBS News\"). 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$config->{channels} =~ s/ /_/g;
42
43print   "\nCATEGORY: Days Supported\n\n" .
44        "Enter the maximum number of days of data $grabber can retrieve.\n\n";
45
46$config->{max_days} = ask("Days supported? [default=7]");
47$config->{max_days} ||= 7;
48
49print   "\nSome grabbers aren't always able to retrieve the maximum number\n" .
50        "of days, because their datasource isn't always topped up. Enter\n" .
51        "the minimum number of days of data that $grabber can reliably fetch.\n\n";
52
53$config->{max_reliable_days} = ask("Days reliably supported? [default=7]");
54$config->{max_reliable_days} ||= 7;
55
56my $example = $config->{max_days} - 1;
57print   "\nIf $grabber retrieves different numbers of days of data for different\n".
58        "channels, specify that here. For example, if $grabber retrieves\n".
59        "$config->{max_days} days of data for most channels, but only $example of ABC2 and SBS News,\n" .
60        "enter \"ABC2:$example,SBS News:$example\". If $grabber doesn't vary by channel, just hit Enter.\n\n";
61$s = ask("Channel variations of days supported?");
62if ($s)
63{
64    my %h;
65    my @a = split(/,\s*/, $s);
66    foreach my $chday (@a)
67    {
68        if ($chday =~ /(.*):(\d+)/)
69        {
70            $h{$1} = $2;
71        }
72    }
73    $config->{max_days_per_chan} = \%h;
74}
75       
76print   "\nCATEGORY: Regions Supported\n\n" .
77        "Enter the region IDs supported by $grabber. If $grabber supports\n" .
78        "all regions, just hit Enter. If it supports a limited number of regions,\n" .
79        "enter these separated by spaces (e.g. \"94 104 118\"). If it supports\n" .
80        "most but not all regions, enter a minus sign followed by a list of the\n" .
81        "unsupported regions (e.g. \"-112 114 128\").\n\n";
82
83$config->{regions} = ask("Regions supported?");
84
85print   "\nCATEGORY: Configuration Requirements\n\n" .
86        "Specify whether $grabber requires any manual configuration\n" .
87        "before it can run (such as registration on a remote web site).\n\n";
88
89if (ask_boolean("Requires manual configuration?"))
90{
91    $config->{config_reqd} = 1;
92       
93    print   "\nShepherd needs a way of detecting whether $grabber has been\n" .
94            "correctly configured or not. Please enter a command-line option\n" .
95            "that will cause $grabber to exit with status 0 if it is configured\n" .
96            "correctly, and exit with another status if it is not.\n\n";
97            $config->{option_ready} = ask("Command-line option for readiness? [default=--ready]");
98            $config->{option_ready} ||= '--ready';
99
100    print   "\nShepherd needs to know the commend-line parameter $grabber uses\n" .
101            "uses for manual configuration. This will be used when the user\n" .
102            "runs shepherd's --configure option.\n\n";
103            $config->{option_config} = ask("Command-line option for configure? [default=--configure]");
104            $config->{option_config} ||= '--configure';
105}
106else
107{
108    print   "\nShepherd needs a way to run $grabber just to check that it compiles\n" .
109            "on the user's system. Please enter a command-line option that will cause\n" .
110            "$grabber to exit with status 0 as quickly as possible, i.e. preferably\n" .
111            "without fetching any data.\n\n";
112    $config->{option_ready} = ask("Command-line option for compilation check? " .
113            "[default=--version]");
114    $config->{option_ready} ||= '--version';
115}
116
117print   "\nCATEGORY: Data Quality\n\n" .
118        "Rate the accuracy of the data $grabber fetches; i.e. how often it\n" .
119        "can be relied upon to report the right programs in the right timeslots.\n" .
120        "(This is a measure of the source $grabber relies upon rather than a\n".
121        "a judgement of $grabber itself.)\n" .
122        "(1) Guide data is often inaccurate\n" .
123        "(2) Guide data is occasionally or sometimes inaccurate\n" .
124        "(3) Guide data is 100% accurate, or very close to it\n\n";
125
126$config->{quality} = ask_choice("Data quality?", 3, 1, 2, 3);
127
128print   "\nCATEGORY: Granularity\n\n" .
129        "Specify whether $grabber is able to fetch data in slices,\n" .
130        "as opposed to having to fetch all or nothing.\n\n";
131
132if (ask_boolean("Can $grabber fetch a single day of data only?", 1))
133{
134    print   "\nWhat option needs to be sent to $grabber to specify the\n" .
135            "number of days wanted? (E.g. if $grabber supports an option\n" .
136            "\"--days n\", where n is the number of days to fetch data for,\n".
137            "enter \"--days\").\n\n";
138    $config->{option_days} = ask("Command-line option for max days? " .
139            "[default=--days]");
140    $config->{option_days} ||= '--days';
141
142    print   "\nWhat option needs to be sent to $grabber to specify that it should\n" .
143            "not start grabbing at day 1? (E.g. if $grabber supports an option\n" .
144            "\"--offset n\", which indicates that it should skip the first\n" .
145            "n days, enter \"--offset\".)\n\n";
146    $config->{option_days_offset} = ask("Command-line option for offset? " .
147            "[default=--offset]");
148    $config->{option_days_offset} ||= '--offset';
149
150    print   "\nIf invoked with the command:\n" .
151            "  ./$grabber $config->{option_days} 2 $config->{option_days_offset} 1\n" .
152            "... how many days of data will $grabber fetch?\n\n";
153    $s = ask("Days fetched? [default=2]");
154    $s ||= 2;
155    unless ($s == 2)
156    {
157        $config->{option_offset_eats_days} = 1;
158    }
159
160    print   "\nDoes $grabber support Shepherd-compliant micro-grabbing? Micro-\n".
161            "grabbing is when a grabber fetches a small part a single day; for\n".
162            "example, 2:30pm to 2:45pm. In order to be compliant, $grabber must be\n".
163            "able to interpret the --gaps_file <s> command-line option, where <s>\n".
164            "is the file name of a Shepherd gaps data structure.\n\n";
165    if (ask_boolean("Does $grabber support micro-grabbing?"))
166    {
167        $config->{micrograbs} = 1;
168    }
169}
170
171if ($config->{category} == 1)
172{
173    print   "\nCATEGORY: Verified Caching\n\n" .
174            "Category 1 grabbers often have an internal cache. They can use this\n" .
175            "to greatly reduce the amount of downloads necessary, by returning the\n" .
176            "cached data rather than fetching it anew. An important part of this\n" .
177            "process is verification, or checking to make sure that the schedule\n" .
178            "hasn't changed significantly from the cache.\n\n";
179
180    $config->{cache} = ask_boolean("Can $grabber reduce downloads by through verified caching?", 1);
181}
182
183print   "\nCATEGORY: Running Time\n\n".
184        "One of the key attributes of shepherd is that it handles failure\n" .
185        "of individual grabbers. It is possible that a grabber could fail in such\n" .
186        "a manner that it never finishes or runs for an excessive amount of time.\n\n";
187$config->{max_runtime} = ask("How many minutes (maximum) should Shepherd allow $grabber to run for? [default=60]");
188$config->{max_runtime} ||= '60';
189
190print   "\nCATEGORY: TOR\n\n" .
191        "Some grabbers work better (faster) if they fetch data via multiple\n" .
192        "sources.  Tor (The Onion Router, tor.eff.org) makes it possible\n" .
193        "to do this, allowing a single user to fetch data via multiple\n" .
194        "endpoints around the internet. $grabber can make use of this\n" .
195        "if it is useful; Shepherd can signal to a grabber that this\n" .
196        "is available via a command-line parameter (e.g. --socks localhost:9050).\n" .
197        "If this grabber supports SOCKS and wishes to use Tor, provide the\n".
198        "command-line option to enable it here, or blank if not desired/required.\n\n";
199$config->{option_anon_socks} = ask("Anon SOCKS command-line option (or blank)?");
200
201print   "\nCATEGORY: Description\n\n" .
202        "Please enter a brief description of $grabber.\n\n";
203
204$config->{desc} = ask("Description?");
205
206print   "\nCONFIGURATION COMPLETE!\n\n" .
207        "Grabber: $grabber\n" .
208        Dumper($config);
209       
210abort() unless (ask_boolean("\nDo you want to go ahead and create $grabber.conf?"));
211
212if (-e "$grabber.conf")
213{
214    print "WARNING: $grabber.conf already exists!\n";
215    abort() unless (ask_boolean("Do you want to overwrite $grabber.conf?"));
216}
217
218print "Creating $grabber.conf.\n";
219open(CONF, ">$grabber.conf") or die "cannot write to $grabber.conf: $!";
220print CONF Data::Dumper->Dump([$config], ['config']);
221close CONF;
222
223print "Done.\n";
224
225sub abort
226{
227    print "Aborting.\n";
228    exit;
229}
Note: See TracBrowser for help on using the browser.