source: subversion/utils/tilesAtHome/tahconfig.pm @ 2195

Revision 2195, 3.6 KB checked in by frederik, 7 years ago (diff)

Added a configuration option "Zip" where you can put the name
of your zip binary, and made it default to simply "zip". The reason
being that I accidentally ran t@h overnight on a machine without
zip installed and only noticed it the next day (it processed jobs
but didn't upload anything). This version will refuse to start if
it doesn't find zip.

Line 
1use strict; 
2
3#--------------------------------------------------------------------------
4# Reads a tiles@home config file, returns a hash array
5#--------------------------------------------------------------------------
6sub ReadConfig{
7  my %Config;
8  while (my $Filename = shift()){
9 
10    open(my $fp,"<$Filename") || die("Can't open \"$Filename\" ($!)\n");
11    while(my $Line = <$fp>){
12      $Line =~ s/#.*$//; # Comments
13      $Line =~ s/\s*$//; # Trailing whitespace
14     
15      if($Line =~ m{
16        (\w+)         # Keyword: just one single word no spaces
17        \s*           # Optional whitespace
18        =             # Equals
19        \s*           # Optional whitespace
20        (.*)          # Value
21        }x){
22       
23        # Store config options in a hash array
24        $Config{$1} = $2;
25        print "Found $1 ($2)\n" if(0); # debug option
26        }
27    }
28    close $fp;
29
30  }
31  ApplyConfigLogic(\%Config);
32 
33  return %Config;
34}
35
36#--------------------------------------------------------------------------
37# Any application-specific knowledge regarding config file options
38# e.g. correct common errors in config files, or enforce naming conventions
39#--------------------------------------------------------------------------
40sub ApplyConfigLogic{
41  my $Config = shift();
42
43  $Config->{OsmUsername} =~ s/@/%40/;  # Encode the @-symbol in OSM passwords
44}
45
46#--------------------------------------------------------------------------
47# Checks a tiles@home configuration
48#--------------------------------------------------------------------------
49sub CheckConfig{
50  my %Config = @_;
51 
52  printf "- Using working directory %s\n", $Config{"WorkingDirectory"};
53 
54  # Inkscape version
55  my $InkscapeV = `$Config{Inkscape} --version`;
56  if($InkscapeV !~ /Inkscape (\d+\.\d+)/){
57    die("Can't find inkscape (using \"$Config{Inkscape}\")\n");
58  }
59  if($1 < 0.42){
60    die("This version of inkscape ($1) is known not to work with tiles\@home\n");
61  }
62  print "- Inkscape version $1\n";
63
64  # XmlStarlet version
65  my $XmlV = `$Config{XmlStarlet} --version`;
66  if($XmlV !~ /(\d+\.\d+\.\d+)/){
67    die("Can't find xmlstarlet (using \"$Config{XmlStarlet}\")\n");
68  }
69  print "- xmlstarlet version $1\n";
70
71  # Zip version
72  $Config{Zip} = "zip" unless defined($Config{Zip});
73  my $ZipV = `$Config{Zip} -v`;
74  if ($ZipV eq "") 
75  {
76    die("Can't find zip (using \"$Config{Zip}\")\n");
77  }
78  print "- zip is present\n";
79 
80  # Upload URL, username
81  printf "- Uploading with username \"$Config{UploadUsername}\"\n", ;
82  if($Config{"UploadPassword"} =~ /\W/){
83    die("Check your upload password\n");
84  }
85
86  if($Config{"UploadURL"} ne $Config{"UploadURL2"}){
87    printf "! Please set UploadURL to %s, this will become the default UploadURL soon\n", $Config{"UploadURL2"};
88  } 
89  if($Config{"UploadChunkSize"} > 2){
90    print "! Upload chunks may be too large for server\n";
91  }
92 
93  if($Config{"UploadChunkSize"} < 0.1){
94    $Config{"UploadChunkSize"} = 1;
95    print "! Using default upload chunk size of 1.0 MB\n";
96  }
97 
98  # $Config{"UploadURL2"};
99
100  if($Config{"DeleteZipFilesAfterUpload"}){
101    print "- Deleting ZIP files after upload\n";
102  }
103
104  if($Config{"RequestUrl"}){
105    print "- Using $Config{RequestUrl} for Requests\n";
106  }
107
108  # OSM username
109  if($Config{OsmUsername} !~ /%40/){
110    die("OsmUsername should be an email address, with the \@ replaced by %40\n");
111  }
112  print "- Using OSM username \"$Config{OsmUsername}\"\n";
113
114  # $Config{"OsmPassword"};
115 
116  # Misc stuff
117  foreach(qw(N S E W)){
118    if($Config{"Border$_"} > 0.5){
119      printf "Border$_ looks abnormally large\n";
120    }
121  }
122
123  if($Config{"MaxZoom"} < 12 || $Config{"MaxZoom"} > 20){
124    print "Check MaxZoom\n";
125  }
126
127}
128
1291
Note: See TracBrowser for help on using the repository browser.