annotate mysqlpy.py @ 100:489c25782e0b

demands cmd2 0.3.3
author catherine@localhost
date Wed, 28 May 2008 09:43:38 -0400
parents 9c5371b5edf4
children 4aa28dffe658
rev   line source
0
9c87fa772ec1 before big refactor
catherine@serenity.wpafb.af.mil
parents:
diff changeset
1 #!/usr/bin/python
9c87fa772ec1 before big refactor
catherine@serenity.wpafb.af.mil
parents:
diff changeset
2 # MySqlPy V1.3
9c87fa772ec1 before big refactor
catherine@serenity.wpafb.af.mil
parents:
diff changeset
3 # Author: Luca.Canali@cern.ch
9c87fa772ec1 before big refactor
catherine@serenity.wpafb.af.mil
parents:
diff changeset
4 #
9c87fa772ec1 before big refactor
catherine@serenity.wpafb.af.mil
parents:
diff changeset
5 #
9c87fa772ec1 before big refactor
catherine@serenity.wpafb.af.mil
parents:
diff changeset
6 # Companion of SqlPython, a python module that reproduces Oracle's command line within python
9c87fa772ec1 before big refactor
catherine@serenity.wpafb.af.mil
parents:
diff changeset
7 # 'sqlplus inside python'
9c87fa772ec1 before big refactor
catherine@serenity.wpafb.af.mil
parents:
diff changeset
8 # See also: http://twiki.cern.ch/twiki/bin/view/PSSGroup/SqlPython
9c87fa772ec1 before big refactor
catherine@serenity.wpafb.af.mil
parents:
diff changeset
9 # http://catherine.devlin.googlepages.com/
9c87fa772ec1 before big refactor
catherine@serenity.wpafb.af.mil
parents:
diff changeset
10
9c87fa772ec1 before big refactor
catherine@serenity.wpafb.af.mil
parents:
diff changeset
11 from sqlpyPlus import *
92
fa8c9eb8908f accepting command-line args
catherine@cordelia
parents: 65
diff changeset
12 import binascii, sys, tempfile
0
9c87fa772ec1 before big refactor
catherine@serenity.wpafb.af.mil
parents:
diff changeset
13
9c87fa772ec1 before big refactor
catherine@serenity.wpafb.af.mil
parents:
diff changeset
14 class mysqlpy(sqlpyPlus):
9c87fa772ec1 before big refactor
catherine@serenity.wpafb.af.mil
parents:
diff changeset
15 '''
9c87fa772ec1 before big refactor
catherine@serenity.wpafb.af.mil
parents:
diff changeset
16 MySqlPy V1.3 - 'sqlplus in python'
9c87fa772ec1 before big refactor
catherine@serenity.wpafb.af.mil
parents:
diff changeset
17 Author: Luca.Canali@cern.ch
94
5df8e2477ca3 command-line args working
catherine@cordelia
parents: 93
diff changeset
18 Rev: 1.4.4, 28-May-08
0
9c87fa772ec1 before big refactor
catherine@serenity.wpafb.af.mil
parents:
diff changeset
19
9c87fa772ec1 before big refactor
catherine@serenity.wpafb.af.mil
parents:
diff changeset
20 Companion of SqlPython, a python module that reproduces Oracle's command line within python
9c87fa772ec1 before big refactor
catherine@serenity.wpafb.af.mil
parents:
diff changeset
21 and sqlpyPlus. Major contributions by Catherine Devlin, http://catherinedevlin.blogspot.com
94
5df8e2477ca3 command-line args working
catherine@cordelia
parents: 93
diff changeset
22
5df8e2477ca3 command-line args working
catherine@cordelia
parents: 93
diff changeset
23 Usage: sqlpython [connect string] [single-word command] ["multi-word command"]...
5df8e2477ca3 command-line args working
catherine@cordelia
parents: 93
diff changeset
24
0
9c87fa772ec1 before big refactor
catherine@serenity.wpafb.af.mil
parents:
diff changeset
25 Quick start command list:
9c87fa772ec1 before big refactor
catherine@serenity.wpafb.af.mil
parents:
diff changeset
26
9c87fa772ec1 before big refactor
catherine@serenity.wpafb.af.mil
parents:
diff changeset
27 - top -> executes a query to list all active sessions in (Oracle 10g and RAC)
9c87fa772ec1 before big refactor
catherine@serenity.wpafb.af.mil
parents:
diff changeset
28 (use: instance activity monitoring, a DBA tool)
9c87fa772ec1 before big refactor
catherine@serenity.wpafb.af.mil
parents:
diff changeset
29 - tselect -> prints the result set in trasposed form, useful to print result sets with
9c87fa772ec1 before big refactor
catherine@serenity.wpafb.af.mil
parents:
diff changeset
30 many columns such as dba_ or v$ views (ex: dba_tables or v$instance)
9c87fa772ec1 before big refactor
catherine@serenity.wpafb.af.mil
parents:
diff changeset
31 - py -> execute a python command (C.D.)
9c87fa772ec1 before big refactor
catherine@serenity.wpafb.af.mil
parents:
diff changeset
32 - db -> quick connect using credentials in pass.txt file
9c87fa772ec1 before big refactor
catherine@serenity.wpafb.af.mil
parents:
diff changeset
33 (Ex: write username and pass in pass.txt and then "db db_alias" to connect)
9c87fa772ec1 before big refactor
catherine@serenity.wpafb.af.mil
parents:
diff changeset
34 - sql -> prints the sql text from the cache. parameter: sql_id of the statement
9c87fa772ec1 before big refactor
catherine@serenity.wpafb.af.mil
parents:
diff changeset
35 (Ex: sql fzqa1qj65nagki)
9c87fa772ec1 before big refactor
catherine@serenity.wpafb.af.mil
parents:
diff changeset
36 - explain -> prints the execution plan from the cache. parameter: sql_id of the statement
9c87fa772ec1 before big refactor
catherine@serenity.wpafb.af.mil
parents:
diff changeset
37 - sessinfo-> prints session information. 1 parameter sid (Ex: sql 101 print info for sid 101)
9c87fa772ec1 before big refactor
catherine@serenity.wpafb.af.mil
parents:
diff changeset
38 - longops -> prints from gv$session_longops (running full scans, etc)
9c87fa772ec1 before big refactor
catherine@serenity.wpafb.af.mil
parents:
diff changeset
39 - load -> prints the OS load on all cluster nodes (10g RAC)
9c87fa772ec1 before big refactor
catherine@serenity.wpafb.af.mil
parents:
diff changeset
40 - sleect,slect -> alias for select (I mistyped select this way too many times...)
9c87fa772ec1 before big refactor
catherine@serenity.wpafb.af.mil
parents:
diff changeset
41 - top9i -> 9i (and single instance) version of top
9c87fa772ec1 before big refactor
catherine@serenity.wpafb.af.mil
parents:
diff changeset
42 - describe, @, !, spool, show, set, list, get, write -> sql*plus-like, from sqlpyPlus (C.D.)
9c87fa772ec1 before big refactor
catherine@serenity.wpafb.af.mil
parents:
diff changeset
43 - shortcuts: \c (connect), \d (describe), etc, from sqlpyPlus (C.D.)
9c87fa772ec1 before big refactor
catherine@serenity.wpafb.af.mil
parents:
diff changeset
44 - :myvarname = xx, set autobind 1, print -> bind variables management extension, to sqlplus (C.D.)
9c87fa772ec1 before big refactor
catherine@serenity.wpafb.af.mil
parents:
diff changeset
45
9c87fa772ec1 before big refactor
catherine@serenity.wpafb.af.mil
parents:
diff changeset
46 Example:
9c87fa772ec1 before big refactor
catherine@serenity.wpafb.af.mil
parents:
diff changeset
47 SQL> connect username@dbalias or username/pass@dbalias
9c87fa772ec1 before big refactor
catherine@serenity.wpafb.af.mil
parents:
diff changeset
48 SQL> select sysdate from dual;
9c87fa772ec1 before big refactor
catherine@serenity.wpafb.af.mil
parents:
diff changeset
49 SQL> exit
9c87fa772ec1 before big refactor
catherine@serenity.wpafb.af.mil
parents:
diff changeset
50 '''
9c87fa772ec1 before big refactor
catherine@serenity.wpafb.af.mil
parents:
diff changeset
51
9c87fa772ec1 before big refactor
catherine@serenity.wpafb.af.mil
parents:
diff changeset
52 def __init__(self):
9c87fa772ec1 before big refactor
catherine@serenity.wpafb.af.mil
parents:
diff changeset
53 sqlpyPlus.__init__(self)
9c87fa772ec1 before big refactor
catherine@serenity.wpafb.af.mil
parents:
diff changeset
54 self.maxtselctrows = 10
9c87fa772ec1 before big refactor
catherine@serenity.wpafb.af.mil
parents:
diff changeset
55 self.query_load10g = '''
9c87fa772ec1 before big refactor
catherine@serenity.wpafb.af.mil
parents:
diff changeset
56 ins.instance_name,ins.host_name,round(os.value,2) load
9c87fa772ec1 before big refactor
catherine@serenity.wpafb.af.mil
parents:
diff changeset
57 from gv$osstat os, gv$instance ins
9c87fa772ec1 before big refactor
catherine@serenity.wpafb.af.mil
parents:
diff changeset
58 where os.inst_id=ins.inst_id and os.stat_name='LOAD'
9c87fa772ec1 before big refactor
catherine@serenity.wpafb.af.mil
parents:
diff changeset
59 order by 3 desc;
9c87fa772ec1 before big refactor
catherine@serenity.wpafb.af.mil
parents:
diff changeset
60 '''
9c87fa772ec1 before big refactor
catherine@serenity.wpafb.af.mil
parents:
diff changeset
61 self.query_top9i = '''
9c87fa772ec1 before big refactor
catherine@serenity.wpafb.af.mil
parents:
diff changeset
62 sid,username,osuser||'@'||terminal "Server User@terminal",program,taddr, status,
9c87fa772ec1 before big refactor
catherine@serenity.wpafb.af.mil
parents:
diff changeset
63 module, sql_hash_value hash, fixed_table_sequence seq, last_call_et elaps
9c87fa772ec1 before big refactor
catherine@serenity.wpafb.af.mil
parents:
diff changeset
64 from v$session
9c87fa772ec1 before big refactor
catherine@serenity.wpafb.af.mil
parents:
diff changeset
65 where username is not null and program not like 'emagent%' and status='ACTIVE'
9c87fa772ec1 before big refactor
catherine@serenity.wpafb.af.mil
parents:
diff changeset
66 and audsid !=sys_context('USERENV','SESSIONID');
9c87fa772ec1 before big refactor
catherine@serenity.wpafb.af.mil
parents:
diff changeset
67 '''
9c87fa772ec1 before big refactor
catherine@serenity.wpafb.af.mil
parents:
diff changeset
68 self.query_ractop = '''
9c87fa772ec1 before big refactor
catherine@serenity.wpafb.af.mil
parents:
diff changeset
69 inst_id||'_'||sid inst_sid,username,osuser||'@'||terminal "User@Term",program, decode(taddr,null,null,'NN') tr,
9c87fa772ec1 before big refactor
catherine@serenity.wpafb.af.mil
parents:
diff changeset
70 sql_id, '.'||mod(fixed_table_sequence,1000) seq, state||': '||event event,
9c87fa772ec1 before big refactor
catherine@serenity.wpafb.af.mil
parents:
diff changeset
71 case state when 'WAITING' then seconds_in_wait else wait_time end w_tim, last_call_et elaps
9c87fa772ec1 before big refactor
catherine@serenity.wpafb.af.mil
parents:
diff changeset
72 from gv$session
9c87fa772ec1 before big refactor
catherine@serenity.wpafb.af.mil
parents:
diff changeset
73 where status='ACTIVE' and username is not null
9c87fa772ec1 before big refactor
catherine@serenity.wpafb.af.mil
parents:
diff changeset
74 and not (event like '% waiting for messages in the queue' and state='WAITING')
9c87fa772ec1 before big refactor
catherine@serenity.wpafb.af.mil
parents:
diff changeset
75 and audsid !=sys_context('USERENV','SESSIONID');
9c87fa772ec1 before big refactor
catherine@serenity.wpafb.af.mil
parents:
diff changeset
76 '''
9c87fa772ec1 before big refactor
catherine@serenity.wpafb.af.mil
parents:
diff changeset
77 self.query_longops = '''
9c87fa772ec1 before big refactor
catherine@serenity.wpafb.af.mil
parents:
diff changeset
78 inst_id,sid,username,time_remaining remaining, elapsed_seconds elapsed, sql_hash_value hash, opname,message
9c87fa772ec1 before big refactor
catherine@serenity.wpafb.af.mil
parents:
diff changeset
79 from gv$session_longops
9c87fa772ec1 before big refactor
catherine@serenity.wpafb.af.mil
parents:
diff changeset
80 where time_remaining>0;
9c87fa772ec1 before big refactor
catherine@serenity.wpafb.af.mil
parents:
diff changeset
81 '''
58
de6278a3bf53 adding compare help
catherine@cordelia
parents: 5
diff changeset
82
92
fa8c9eb8908f accepting command-line args
catherine@cordelia
parents: 65
diff changeset
83 def do_new(self, args):
fa8c9eb8908f accepting command-line args
catherine@cordelia
parents: 65
diff changeset
84 'tells you about new objects'
fa8c9eb8908f accepting command-line args
catherine@cordelia
parents: 65
diff changeset
85 self.do_select('''owner,
fa8c9eb8908f accepting command-line args
catherine@cordelia
parents: 65
diff changeset
86 object_name,
fa8c9eb8908f accepting command-line args
catherine@cordelia
parents: 65
diff changeset
87 object_type
fa8c9eb8908f accepting command-line args
catherine@cordelia
parents: 65
diff changeset
88 FROM all_objects
fa8c9eb8908f accepting command-line args
catherine@cordelia
parents: 65
diff changeset
89 WHERE created > SYSDATE - 7''')
0
9c87fa772ec1 before big refactor
catherine@serenity.wpafb.af.mil
parents:
diff changeset
90 def do_top9i(self,args):
9c87fa772ec1 before big refactor
catherine@serenity.wpafb.af.mil
parents:
diff changeset
91 '''Runs query_top9i defined above, to display active sessions in Oracle 9i'''
9c87fa772ec1 before big refactor
catherine@serenity.wpafb.af.mil
parents:
diff changeset
92 self.do_select(self.query_top9i)
9c87fa772ec1 before big refactor
catherine@serenity.wpafb.af.mil
parents:
diff changeset
93
9c87fa772ec1 before big refactor
catherine@serenity.wpafb.af.mil
parents:
diff changeset
94 def do_top(self,args):
9c87fa772ec1 before big refactor
catherine@serenity.wpafb.af.mil
parents:
diff changeset
95 '''Runs query_ractop defined above, to display active sessions in Oracle 10g (and RAC)'''
9c87fa772ec1 before big refactor
catherine@serenity.wpafb.af.mil
parents:
diff changeset
96 self.do_select(self.query_ractop)
9c87fa772ec1 before big refactor
catherine@serenity.wpafb.af.mil
parents:
diff changeset
97
9c87fa772ec1 before big refactor
catherine@serenity.wpafb.af.mil
parents:
diff changeset
98 def do_longops(self,args):
9c87fa772ec1 before big refactor
catherine@serenity.wpafb.af.mil
parents:
diff changeset
99 '''Runs query_longops defined above, to display long running operations (full scans, etc)'''
9c87fa772ec1 before big refactor
catherine@serenity.wpafb.af.mil
parents:
diff changeset
100 self.do_select(self.query_longops)
9c87fa772ec1 before big refactor
catherine@serenity.wpafb.af.mil
parents:
diff changeset
101
9c87fa772ec1 before big refactor
catherine@serenity.wpafb.af.mil
parents:
diff changeset
102 def do_load(self,args):
9c87fa772ec1 before big refactor
catherine@serenity.wpafb.af.mil
parents:
diff changeset
103 '''Runs query_load10g defined above, to display OS load on cluster nodes (10gRAC)'''
9c87fa772ec1 before big refactor
catherine@serenity.wpafb.af.mil
parents:
diff changeset
104 self.do_select(self.query_load10g)
9c87fa772ec1 before big refactor
catherine@serenity.wpafb.af.mil
parents:
diff changeset
105
64
1a52de2c541e minor tweaks
catherine@cordelia
parents: 58
diff changeset
106 def do_himom(self,args):
1a52de2c541e minor tweaks
catherine@cordelia
parents: 58
diff changeset
107 '''greets your mom'''
1a52de2c541e minor tweaks
catherine@cordelia
parents: 58
diff changeset
108 print 'hi mom'
1a52de2c541e minor tweaks
catherine@cordelia
parents: 58
diff changeset
109
0
9c87fa772ec1 before big refactor
catherine@serenity.wpafb.af.mil
parents:
diff changeset
110 def do_db(self,args,filepath='pass.txt'):
9c87fa772ec1 before big refactor
catherine@serenity.wpafb.af.mil
parents:
diff changeset
111 '''Exec do_connect to db_alias in args (credentials form the file pass.txt) '''
9c87fa772ec1 before big refactor
catherine@serenity.wpafb.af.mil
parents:
diff changeset
112 f = open(filepath,'r')
9c87fa772ec1 before big refactor
catherine@serenity.wpafb.af.mil
parents:
diff changeset
113 connectstr = f.readline().strip() +'@'+args
9c87fa772ec1 before big refactor
catherine@serenity.wpafb.af.mil
parents:
diff changeset
114 self.do_connect(connectstr)
9c87fa772ec1 before big refactor
catherine@serenity.wpafb.af.mil
parents:
diff changeset
115 f.close()
9c87fa772ec1 before big refactor
catherine@serenity.wpafb.af.mil
parents:
diff changeset
116
9c87fa772ec1 before big refactor
catherine@serenity.wpafb.af.mil
parents:
diff changeset
117 def do_py(self, arg):
9c87fa772ec1 before big refactor
catherine@serenity.wpafb.af.mil
parents:
diff changeset
118 '''Executes a python command'''
9c87fa772ec1 before big refactor
catherine@serenity.wpafb.af.mil
parents:
diff changeset
119 try:
9c87fa772ec1 before big refactor
catherine@serenity.wpafb.af.mil
parents:
diff changeset
120 exec(arg)
9c87fa772ec1 before big refactor
catherine@serenity.wpafb.af.mil
parents:
diff changeset
121 except Exception, e:
9c87fa772ec1 before big refactor
catherine@serenity.wpafb.af.mil
parents:
diff changeset
122 print e
9c87fa772ec1 before big refactor
catherine@serenity.wpafb.af.mil
parents:
diff changeset
123
5
65ae6cec71c6 expanded desc good so far
devlinjs@FA7CZA6N1254998.wrightpatterson.afmc.ds.af.mil
parents: 4
diff changeset
124 def do_tselect(self, arg):
0
9c87fa772ec1 before big refactor
catherine@serenity.wpafb.af.mil
parents:
diff changeset
125 '''executes a query and prints the result in trasposed form. Useful when querying tables with many columns'''
5
65ae6cec71c6 expanded desc good so far
devlinjs@FA7CZA6N1254998.wrightpatterson.afmc.ds.af.mil
parents: 4
diff changeset
126
65ae6cec71c6 expanded desc good so far
devlinjs@FA7CZA6N1254998.wrightpatterson.afmc.ds.af.mil
parents: 4
diff changeset
127 self.do_select(arg, override_terminator='\\t')
0
9c87fa772ec1 before big refactor
catherine@serenity.wpafb.af.mil
parents:
diff changeset
128
9c87fa772ec1 before big refactor
catherine@serenity.wpafb.af.mil
parents:
diff changeset
129 def do_sql(self,args):
9c87fa772ec1 before big refactor
catherine@serenity.wpafb.af.mil
parents:
diff changeset
130 '''prints sql statement give the sql_id (Oracle 10gR2)'''
9c87fa772ec1 before big refactor
catherine@serenity.wpafb.af.mil
parents:
diff changeset
131 self.query = "select inst_id, sql_fulltext from gv$sqlstats where sql_id='"+args+"'"
9c87fa772ec1 before big refactor
catherine@serenity.wpafb.af.mil
parents:
diff changeset
132 try:
9c87fa772ec1 before big refactor
catherine@serenity.wpafb.af.mil
parents:
diff changeset
133 self.curs.execute(self.query)
9c87fa772ec1 before big refactor
catherine@serenity.wpafb.af.mil
parents:
diff changeset
134 row = self.curs.fetchone()
9c87fa772ec1 before big refactor
catherine@serenity.wpafb.af.mil
parents:
diff changeset
135 print "\nSQL statement from cache"
9c87fa772ec1 before big refactor
catherine@serenity.wpafb.af.mil
parents:
diff changeset
136 print "------------------------\n"
9c87fa772ec1 before big refactor
catherine@serenity.wpafb.af.mil
parents:
diff changeset
137 while row:
9c87fa772ec1 before big refactor
catherine@serenity.wpafb.af.mil
parents:
diff changeset
138 print "\nINST_ID = "+str(row[0])+" - SQL TEXT:\n", row[1].read()
9c87fa772ec1 before big refactor
catherine@serenity.wpafb.af.mil
parents:
diff changeset
139 row = self.curs.next()
9c87fa772ec1 before big refactor
catherine@serenity.wpafb.af.mil
parents:
diff changeset
140 except Exception, e:
9c87fa772ec1 before big refactor
catherine@serenity.wpafb.af.mil
parents:
diff changeset
141 print e
9c87fa772ec1 before big refactor
catherine@serenity.wpafb.af.mil
parents:
diff changeset
142
9c87fa772ec1 before big refactor
catherine@serenity.wpafb.af.mil
parents:
diff changeset
143 def do_explain(self,args):
9c87fa772ec1 before big refactor
catherine@serenity.wpafb.af.mil
parents:
diff changeset
144 '''prints the plan of a given statement from the sql cache. 1 parameter: sql_id, see also do_sql '''
9c87fa772ec1 before big refactor
catherine@serenity.wpafb.af.mil
parents:
diff changeset
145 self.query = "select * from table(dbms_xplan.display_cursor('"+args+"'))"
9c87fa772ec1 before big refactor
catherine@serenity.wpafb.af.mil
parents:
diff changeset
146 try:
9c87fa772ec1 before big refactor
catherine@serenity.wpafb.af.mil
parents:
diff changeset
147 self.curs.execute(self.query)
9c87fa772ec1 before big refactor
catherine@serenity.wpafb.af.mil
parents:
diff changeset
148 rows = self.curs.fetchall()
9c87fa772ec1 before big refactor
catherine@serenity.wpafb.af.mil
parents:
diff changeset
149 desc = self.curs.description
9c87fa772ec1 before big refactor
catherine@serenity.wpafb.af.mil
parents:
diff changeset
150 self.rc = self.curs.rowcount
9c87fa772ec1 before big refactor
catherine@serenity.wpafb.af.mil
parents:
diff changeset
151 if self.rc > 0:
9c87fa772ec1 before big refactor
catherine@serenity.wpafb.af.mil
parents:
diff changeset
152 print '\n' + sqlpython.pmatrix(rows,desc,200)
9c87fa772ec1 before big refactor
catherine@serenity.wpafb.af.mil
parents:
diff changeset
153 except Exception, e:
9c87fa772ec1 before big refactor
catherine@serenity.wpafb.af.mil
parents:
diff changeset
154 print e
9c87fa772ec1 before big refactor
catherine@serenity.wpafb.af.mil
parents:
diff changeset
155
9c87fa772ec1 before big refactor
catherine@serenity.wpafb.af.mil
parents:
diff changeset
156 def do_sessinfo(self,args):
9c87fa772ec1 before big refactor
catherine@serenity.wpafb.af.mil
parents:
diff changeset
157 '''Reports session info for the give sid, extended to RAC with gv$'''
9c87fa772ec1 before big refactor
catherine@serenity.wpafb.af.mil
parents:
diff changeset
158 self.do_tselect('* from gv$session where sid='+args+';')
9c87fa772ec1 before big refactor
catherine@serenity.wpafb.af.mil
parents:
diff changeset
159
9c87fa772ec1 before big refactor
catherine@serenity.wpafb.af.mil
parents:
diff changeset
160 def do_sleect(self,args):
9c87fa772ec1 before big refactor
catherine@serenity.wpafb.af.mil
parents:
diff changeset
161 '''implements sleect = select, a common typo'''
9c87fa772ec1 before big refactor
catherine@serenity.wpafb.af.mil
parents:
diff changeset
162 self.do_select(args)
9c87fa772ec1 before big refactor
catherine@serenity.wpafb.af.mil
parents:
diff changeset
163
9c87fa772ec1 before big refactor
catherine@serenity.wpafb.af.mil
parents:
diff changeset
164 do_slect = do_sleect
9c87fa772ec1 before big refactor
catherine@serenity.wpafb.af.mil
parents:
diff changeset
165
9c87fa772ec1 before big refactor
catherine@serenity.wpafb.af.mil
parents:
diff changeset
166 def run():
9c87fa772ec1 before big refactor
catherine@serenity.wpafb.af.mil
parents:
diff changeset
167 my=mysqlpy()
9c87fa772ec1 before big refactor
catherine@serenity.wpafb.af.mil
parents:
diff changeset
168 print my.__doc__
60
4f80329a1905 loading fix
catherine.devlin@gmail.com
parents: 58
diff changeset
169 try:
92
fa8c9eb8908f accepting command-line args
catherine@cordelia
parents: 65
diff changeset
170 if sys.argv[1][0] != '@':
fa8c9eb8908f accepting command-line args
catherine@cordelia
parents: 65
diff changeset
171 my.do_connect(sys.argv.pop(1))
94
5df8e2477ca3 command-line args working
catherine@cordelia
parents: 93
diff changeset
172 for arg in sys.argv[1:]:
97
9c5371b5edf4 added assumeComplete
catherine@cordelia
parents: 94
diff changeset
173 if my.onecmd(arg, assumeComplete=True) == my._STOP_AND_EXIT: # ugh, filename gets ; appended
94
5df8e2477ca3 command-line args working
catherine@cordelia
parents: 93
diff changeset
174 return
60
4f80329a1905 loading fix
catherine.devlin@gmail.com
parents: 58
diff changeset
175 except IndexError:
4f80329a1905 loading fix
catherine.devlin@gmail.com
parents: 58
diff changeset
176 pass
0
9c87fa772ec1 before big refactor
catherine@serenity.wpafb.af.mil
parents:
diff changeset
177 my.cmdloop()
9c87fa772ec1 before big refactor
catherine@serenity.wpafb.af.mil
parents:
diff changeset
178
9c87fa772ec1 before big refactor
catherine@serenity.wpafb.af.mil
parents:
diff changeset
179 if __name__ == '__main__':
93
f40bb62c625f one cmd line arg works
catherine@cordelia
parents: 92
diff changeset
180 run()