1
2
3
4
5
6
7
8
9
10
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
23
24 if __debug__:
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
50 if sys.platform=="darwin" and len(sys.argv)>1 and sys.argv[1].startswith("-psn_"):
51
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
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
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
78 _debug=bool(_args and 'debug' in _args)
79
80 _clicmd=len(_args)==1 and bp_cli.valid_command(_args[0])
81 if not _debug and not _clicmd:
82 import warnings
84 warnings.showwarning=ignorer
85
86
87
94
95
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
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
117
118
119 bitfling.bitfling.run(sys.argv)
120 else:
121 import gui
122
123
124
125 gui.run(sys.argv, _kwargs)
126