source: genesis/nodes/genesis-to-py.pl@ 6463

Last change on this file since 6463 was 6463, checked in by andrea, 16 years ago

use exodus-compliant 'labels' when building output

  • Property svn:executable set to *
File size: 1.9 KB
Line 
1#!/usr/bin/env perl
2use Geo::Coordinates::RDNAP qw/from_rd to_rd dms/;
3
4
5# RD X,Y -> RD Noorderbreedte, Oosterbreedte
6# http://web.inter.nl.net/users/F.Kissels/gps/conversie.html
7
8# Little perl to convert genesis files into python config files,
9# Which gonna be used for more logic stuff ;-)
10
11#
12# Usage: for file in */wleiden.conf; do ./genesis-to-py.pl $file; done > py.conf
13do($ARGV[0]) || die;
14
15my %status_labels = ( up => 'up', down => 'dw', planned => 'pl' );
16
17$interfaces = join(',',keys %config);
18if ( ($X =~ /\d+/) and ($Y =~ /\d+/) and ($X > 10) and ($Y > 10)) {
19 ($lat, $lon, $h) = from_rd( $X, $Y, 0);
20} else {
21 $lat = $lon = $h = 0;
22}
23
24$status = $status_labels{$status} || 'up'; # ensure reporting a correct status
25
26print <<EOF;
27[$nodename]
28location = $location
29status = $status
30latitude = $lat
31longitude = $lon
32interfaces = $interfaces
33x = $X
34y = $Y
35masterip = $master_ip
36nodetype = $nodetype
37name = $nodename
38configtype = node
39
40EOF
41
42
43foreach $if (keys %config) {
44 print <<EOF;
45[$nodename/$if]
46EOF
47 %tmp = (
48 'configtype' => 'interface',
49 'dhcp' => 'no',
50 'polar' => 'ver',
51 'type' => '11b',
52 'antenna' => 'omni',
53 'essid' => 'essid-unused',
54 );
55 foreach $line (split('\n',$config{$if})) {
56 ($key, $value) = split(/=/,$line);
57 if ($key and (lc($key) =~ /^[a-z].*/)) {
58 #print "$key : $value\n";
59 $value = lc($value);
60 if ($key =~ /^type$/i) {
61 if ($value eq 'ethernet') {
62 $value = 'eth';
63 } else {
64 $value = '11b';
65 }
66 } elsif ($key =~ /^mode$/i) {
67 if ($value eq 'master') {
68 $value = 'ms';
69 } else { # managed
70 $value = 'mn';
71 }
72 }
73 $tmp{lc($key)} = $value;
74 }
75 }
76
77 foreach $key (keys %tmp) {
78 print "$key=$tmp{$key}\n"
79 }
80 print "\n";
81}
Note: See TracBrowser for help on using the repository browser.