source: genesis/tools/genesis-to-py.pl@ 14387

Last change on this file since 14387 was 8615, checked in by rick, 14 years ago

Bezempje door alle files. Rommel weg. Tooljes op de juiste locatie.

  • Property svn:executable set to *
File size: 3.3 KB
RevLine 
[6439]1#!/usr/bin/env perl
2
[8214]3eval {
4 require Geo::Coordinates::RDNAP;
5};
6if (! $@) {
7 print "Foo";
8 Geo::Coordinates::RDNAP->import(qw/from_rd to_rd dms/);
9} else {
10 print STDERR "[WARN] Geo::Coordinates::RDNAP not installed\n";
11 sub from_rd {
12 return (0,0,0);
13 }
14}
[6439]15
16# RD X,Y -> RD Noorderbreedte, Oosterbreedte
17# http://web.inter.nl.net/users/F.Kissels/gps/conversie.html
18
19# Little perl to convert genesis files into python config files,
20# Which gonna be used for more logic stuff ;-)
21
[8048]22$argc = $#ARGV + 1;
23if ($argc == 0) {
[8214]24 print STDERR "Usage $_ <wleiden.conf> ...\n";
[8048]25 exit 1;
26# Hack to easy support multiple files without remembering any variable in between
27} elsif ($argc > 1) {
28 foreach $file (@ARGV) {
29 print `perl $ENV{_} $file`;
30 }
31 exit 0;
32}
33
34
[6439]35do($ARGV[0]) || die;
36
[6463]37my %status_labels = ( up => 'up', down => 'dw', planned => 'pl' );
38
[6439]39$interfaces = join(',',keys %config);
40if ( ($X =~ /\d+/) and ($Y =~ /\d+/) and ($X > 10) and ($Y > 10)) {
41 ($lat, $lon, $h) = from_rd( $X, $Y, 0);
42} else {
43 $lat = $lon = $h = 0;
44}
45
[6463]46$status = $status_labels{$status} || 'up'; # ensure reporting a correct status
47
[6439]48print <<EOF;
49[$nodename]
50location = $location
51status = $status
52latitude = $lat
53longitude = $lon
54interfaces = $interfaces
55x = $X
56y = $Y
[6463]57masterip = $master_ip
[6439]58nodetype = $nodetype
[6463]59name = $nodename
[6439]60configtype = node
61
62EOF
63
64
65foreach $if (keys %config) {
66 print <<EOF;
67[$nodename/$if]
68EOF
69 %tmp = (
70 'configtype' => 'interface',
71 'dhcp' => 'no',
[6508]72 'compass-direction' => '',
[8057]73 'nodename' => $nodename,
74 'interface' => $if,
[6439]75 );
76 foreach $line (split('\n',$config{$if})) {
77 ($key, $value) = split(/=/,$line);
78 if ($key and (lc($key) =~ /^[a-z].*/)) {
79 #print "$key : $value\n";
[6463]80 $value = lc($value);
81 if ($key =~ /^type$/i) {
82 if ($value eq 'ethernet') {
83 $value = 'eth';
84 } else {
85 $value = '11b';
86 }
87 } elsif ($key =~ /^mode$/i) {
88 if ($value eq 'master') {
89 $value = 'ms';
90 } else { # managed
91 $value = 'mn';
92 }
[6474]93 } elsif ($key =~ /^polar$/i) {
94 if ($value eq 'hor') {
95 $value = 'hr';
96 } else {
97 $value = 'vr';
98 }
99 } elsif ($key =~ /^essid$/i) {
100 $key = 'ssid';
[6508]101
102 # Dirty hack to fetch compass direction of essid
103 $value =~ /[a-z]+-([a-z]+)\..*/;
104 $direction = $1;
105 # Translate into English
106 if ($direction ne "omni") {
107 $direction =~ tr/oz/es/;
108 }
[6541]109 # node AMwtrt1 and 'test' directions
110 if ($direction eq "wtrtr" or $direction eq "test") {
111 $direction = '';
112 }
[6508]113 $tmp{'compass-direction'} = $direction;
[6474]114 } elsif ($key =~ /^gain$/i) {
115 $value =~ s/dbi//;
[6463]116 }
117 $tmp{lc($key)} = $value;
[6439]118 }
119 }
[6564]120# ethernet2wifi bridges
121 if ( $tmp{extra_type} eq 'eth2wifibridge' ) {
122 $tmp{type} = '11b';
123 }
[6541]124# 11a
[6535]125 if ( $tmp{type} eq '11b' && $tmp{channel} > 13 ) {
126 $tmp{type} = '11a';
127 }
128
[6439]129 foreach $key (keys %tmp) {
[6535]130 print "$key=$tmp{$key}\n";
[6439]131 }
132 print "\n";
133}
Note: See TracBrowser for help on using the repository browser.