Module bp
[hide private]
[frames] | no frames]

Source Code for Module bp

  1  #!/usr/bin/env python 
  2   
  3  ### BITPIM 
  4  ### 
  5  ### Copyright (C) 2003-2006 Roger Binns <rogerb@rogerbinns.com> 
  6  ### 
  7  ### This program is free software; you can redistribute it and/or modify 
  8  ### it under the terms of the BitPim license as detailed in the LICENSE file. 
  9  ### 
 10  ### $Id: bp.py 4436 2007-10-30 23:10:47Z djpham $ 
 11   
 12  """Main entry point to Bitpim 
 13   
 14  It invokes BitPim in gui or commandline mode as appropriate 
 15   
 16  @Note: Only gui mode is supported at the moment 
 17  """ 
 18  from __future__ import with_statement 
 19  import sys 
 20  import bp_cli 
 21   
 22  # only gui mode support at the moment 
 23   
 24  if __debug__: 
25 - def profile(filename, command):
26 import hotshot, hotshot.stats, os 27 file=os.path.abspath(filename) 28 profile=hotshot.Profile(file) 29 profile.run(command) 30 profile.close() 31 del profile 32 howmany=100 33 stats=hotshot.stats.load(file) 34 stats.strip_dirs() 35 stats.sort_stats('time', 'calls') 36 stats.print_stats(100) 37 stats.sort_stats('cum', 'calls') 38 stats.print_stats(100) 39 stats.sort_stats('calls', 'time') 40 stats.print_stats(100) 41 sys.exit(0)
42 43 44 if __name__ == '__main__': 45 import sys 46 import getopt 47 import os.path 48 49 # in production builds we don't need the stupid warnings 50 if sys.platform=="darwin" and len(sys.argv)>1 and sys.argv[1].startswith("-psn_"): 51 # get rid of the process serial number on mac 52 sys.argv=sys.argv[:1]+sys.argv[2:] 53 try: 54 _options, _args=getopt.gnu_getopt(sys.argv[1:], 'c:d:f:p:') 55 _invalid_args=[x for x in _args if x not in ['debug', 'bitfling'] and \ 56 not bp_cli.valid_command(x)] 57 if _invalid_args: 58 raise getopt.GetoptError('Invalid argument(s): '+','.join(_invalid_args)) 59 except getopt.GetoptError: 60 e=sys.exc_info()[1] 61 _invalid_args=True 62 _error_str=e.msg 63 if _invalid_args: 64 # invalid/unknown arguments 65 try: 66 import wx 67 import guihelper 68 _msg='%s\nUsage: %s [-c config file]|[-d config dir] [-p comm port] [-f phone model] [CLI Command] [debug] [bitfling]\n'%(_error_str, sys.argv[0]) 69 sys.stderr.write(_msg) 70 # try to display an error message box 71 _app=wx.PySimpleApp() 72 guihelper.MessageDialog(None, _msg, 'BitPim Error', 73 style=wx.OK|wx.ICON_ERROR) 74 finally: 75 sys.exit(1) 76 _kwargs={} 77 # check for debug flag 78 _debug=bool(_args and 'debug' in _args) 79 # CLI commands present? 80 _clicmd=len(_args)==1 and bp_cli.valid_command(_args[0]) 81 if not _debug and not _clicmd: 82 import warnings
83 - def ignorer(*args, **kwargs): pass
84 warnings.showwarning=ignorer 85 86 # on windows we set stdout, stderr to do nothing objects otherwise there 87 # is an error after 4kb of output
88 - class _donowt:
89 - def __getattr__(self, _):
90 return self
91
92 - def __call__(self, *args, **kwargs):
93 pass
94 95 # heck, do it for all platforms 96 sys.stdout=_donowt() 97 sys.stderr=_donowt() 98 99 for _k,_v in _options: 100 if _k=='-d': 101 _kwargs['config_filename']=os.path.join(_v, '.bitpim') 102 elif _k=='-c': 103 _kwargs['config_filename']=_v 104 elif _k=='-p': 105 _kwargs['comm_port']=_v 106 elif _k=='-f': 107 _kwargs['phone_model']=_v 108 if _args and _clicmd: 109 # CLI detected 110 _cli=bp_cli.CLI(_args[0], sys.stdin, sys.stdout, sys.stderr, 111 **_kwargs) 112 if _cli.OK: 113 _cli.run() 114 elif _args and 'bitfling' in _args: 115 import bitfling.bitfling 116 #if True: 117 # profile("bitfling.prof", "bitfling.bitfling.run(sys.argv)") 118 #else: 119 bitfling.bitfling.run(sys.argv) 120 else: 121 import gui 122 #if True: 123 # profile("bitpim.prof", "gui.run(sys.argv)") 124 #else: 125 gui.run(sys.argv, _kwargs) 126