-
Notifications
You must be signed in to change notification settings - Fork 31
/
namebench.py
executable file
·78 lines (65 loc) · 2.44 KB
/
namebench.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/usr/bin/env python
# Copyright 2009 Google Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""namebench: DNS service benchmarking tool."""
__author__ = '[email protected] (Thomas Stromberg)'
import os
import platform
import sys
import signal
# Check before we start importing internal dependencies
if sys.version < '2.4':
your_version = sys.version.split(' ')[0]
print '* Your Python version (%s) is too old! Please upgrade to 2.6+!' % your_version
sys.exit(1)
elif sys.version >= '3.0':
print '* namebench is currently incompatible with Python 3.0 - trying anyways'
from libnamebench import cli
from libnamebench import config
def signal_handler(signal, frame):
os._exit(1)
if __name__ == '__main__':
signal.signal(signal.SIGINT, signal_handler)
options = config.GetMergedConfiguration()
use_tk = False
if len(sys.argv) == 1:
if os.getenv('DISPLAY', None):
use_tk = True
# Macs get a special Cocoa binary
if os.getenv('I_LOVE_TK', None):
use_tk = True
elif platform.mac_ver()[0]:
use_tk = False
elif platform.system() == 'Windows':
use_tk = True
if use_tk:
try:
# Workaround for unicode path errors.
# See http://code.google.com/p/namebench/issues/detail?id=41
if hasattr(sys, 'winver') and hasattr(sys, 'frozen'):
os.environ['TCL_LIBRARY'] = os.path.join(os.path.dirname(sys.executable), 'tcl', 'tcl8.5')
os.environ['TK_LIBRARY'] = os.path.join(os.path.dirname(sys.executable), 'tcl', 'tk8.5')
import Tkinter
except ImportError:
if len(sys.argv) == 1:
print "- The python-tk (tkinter) library is missing, using the command-line interface.\n"
use_tk = False
if use_tk:
print 'Starting graphical interface for namebench (use -x to force command-line usage)'
from libnamebench import tk
interface = tk.NameBenchGui
else:
interface = cli.NameBenchCli
namebench = interface(options)
namebench.Execute()