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