Completed
Push — master ( 091708...b877bb )
by Ryan
01:13
created

create_config()   B

Complexity

Conditions 3

Size

Total Lines 34

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
c 1
b 0
f 0
dl 0
loc 34
rs 8.8571
1
import os
2
import sys
3
4
5
class Config(dict):
6
7
    def __init__(self):
8
        dict.__init__(self)
9
10
    def __getattr__(self, key):
11
        try:
12
            return self[key]
13
        except KeyError:
14
            raise AttributeError
15
16
    def __setattr__(self, key, value):
17
        self[key] = value
18
19
    def __delattr__(self, key):
20
        del self[key]
21
22
    def __repr__(self):
23
        return '<Config ' + dict.__repr__(self) + '>'
24
25
26
def create_config():
27
    default = """\
28
verbose: False
29
debug: False
30
simulate: False
31
32
server:
33
  ips_file: "/etc/trdb/endpoints"
34
  mmdb: "/etc/trdb/GeoIP2-ISP.mmdb"
35
  bind: 127.0.0.1
36
  port: 9001
37
38
runner:
39
  ips_file: "/etc/trdb/endpoints"
40
  # hostname: ""
41
  remote_ips: False
42
  # will overide ips_file and ips from server (remote_ips)
43
  # ips:
44
  #   - "8.8.8.8"
45
  #   - "1.1.1.1"
46
  server_url: "http://127.0.0.1:9001"
47
  procs: 10
48
  # Multiple parsers are planned, currently the NANOG traceroute is supported,
49
  #     vanilla "traceroute" pkg on Debian
50
  # DO NOT use /usr/bin/traceroute or just traceroute, on debian the alternatives
51
  # system could mess this up if you have more than one traceroute installed
52
  traceroute_bin: /usr/bin/traceroute-nanog\n"""
53
54
    try:
55
        with open(os.path.expanduser("~/.trdb.yaml"), "w") as f:
56
            f.write(default)
57
    except:
58
        print "Failed to write out example config"
59
        sys.exit(1)
60