root/util/gconf-builder @ 58

Revision 58, 7.0 kB (checked in by max, 7 years ago)

Revised gconf-builder.

  • 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("Which category is $grabber?");
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 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
42print   "\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
49print   "\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
57print   "\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
63if ($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}
72else
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
83print   "\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
92my $g = '';
93
94print   "\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
100if ($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
135print "\n";
136
137$s = ask_boolean("Can $grabber fetch a single channel of data only? ");
138
139if ($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
154print   "\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
159if ($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
176print   "\nCATEGORY: Description\n\n" .
177        "Please enter a brief description of $grabber.\n\n";
178
179$config->{desc} = ask("Description?");
180
181print   "\nCONFIGURATION COMPLETE\n\n" .
182        "Grabber: $grabber\n" .
183        Dumper($config);
184       
185abort() unless (ask_boolean("\nDo you want to go ahead and create $grabber.conf?"));
186
187if (-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
193print "Creating $grabber.conf.\n";
194open(CONF, ">$grabber.conf") or die "cannot write to $grabber.conf: $!";
195print CONF Data::Dumper->Dump([$config], ['config']);
196close CONF;
197
198print "Done.\n";
199
200sub abort
201{
202    print "Aborting.\n";
203    exit;
204}
Note: See TracBrowser for help on using the browser.