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

Last change on this file since 10912 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
Line 
1#!/usr/bin/env perl
2
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}
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
22$argc = $#ARGV + 1;
23if ($argc == 0) {
24 print STDERR "Usage $_ <wleiden.conf> ...\n";
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
35do($ARGV[0]) || die;
36
37my %status_labels = ( up => 'up', down => 'dw', planned => 'pl' );
38
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
46$status = $status_labels{$status} || 'up'; # ensure reporting a correct status
47
48print <<EOF;
49[$nodename]
50location = $location
51status = $status
52latitude = $lat
53longitude = $lon
54interfaces = $interfaces
55x = $X
56y = $Y
57masterip = $master_ip
58nodetype = $nodetype
59name = $nodename
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',
72 'compass-direction' => '',
73 'nodename' => $nodename,
74 'interface' => $if,
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";
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 }
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';
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 }
109 # node AMwtrt1 and 'test' directions
110 if ($direction eq "wtrtr" or $direction eq "test") {
111 $direction = '';
112 }
113 $tmp{'compass-direction'} = $direction;
114 } elsif ($key =~ /^gain$/i) {
115 $value =~ s/dbi//;
116 }
117 $tmp{lc($key)} = $value;
118 }
119 }
120# ethernet2wifi bridges
121 if ( $tmp{extra_type} eq 'eth2wifibridge' ) {
122 $tmp{type} = '11b';
123 }
124# 11a
125 if ( $tmp{type} eq '11b' && $tmp{channel} > 13 ) {
126 $tmp{type} = '11a';
127 }
128
129 foreach $key (keys %tmp) {
130 print "$key=$tmp{$key}\n";
131 }
132 print "\n";
133}
Note: See TracBrowser for help on using the repository browser.