1
1
#!/usr/bin/env python
2
2
__author__ = 'Matias Carrasco Kind'
3
- __version__ = '1.0.0 '
3
+ __version__ = '1.0.1 '
4
4
# TODO:
5
5
# add other formats in load tables from fits (like boolean or complex)
6
6
# clean up, comments
7
- # readline bug (GNU vs libedit)
7
+ # readline bug (GNU vs libedit) for history
8
8
# self upgrade
9
9
10
10
import warnings
@@ -167,7 +167,7 @@ def __init__(self, conf, desconf, db, interactive=True):
167
167
self .password = self .desconfig .get ('db-' + self .dbname , 'passwd' )
168
168
kwargs = {'host' : self .dbhost , 'port' : self .port , 'service_name' : self .dbname }
169
169
dsn = cx_Oracle .makedsn (** kwargs )
170
- print 'Connecting to DB %s ...' % self .dbname
170
+ print 'Connecting to DB ** %s ** ...' % self .dbname
171
171
self .con = cx_Oracle .connect (self .user , self .password , dsn = dsn )
172
172
self .cur = self .con .cursor ()
173
173
self .cur .arraysize = self .prefetch
@@ -749,16 +749,19 @@ def do_exit(self, line):
749
749
except :
750
750
pass
751
751
try :
752
- cur .close ()
752
+ self .cur .close ()
753
+ except :
754
+ pass
755
+ try :
756
+ self .con .commit ()
757
+ self .con .close ()
753
758
except :
754
759
pass
755
- self .con .commit ()
756
- self .con .close ()
757
760
if readline_present :
758
761
readline .write_history_file (history_file )
759
762
if self .writeconfig :
760
763
config_mod .write_config (config_file , self .config )
761
- sys . exit (0 )
764
+ os . _exit (0 )
762
765
763
766
def do_clear (self , line ):
764
767
"""
@@ -1302,23 +1305,26 @@ def to_pandas(cur):
1302
1305
1303
1306
1304
1307
class connect ():
1305
- def __init__ (self ):
1308
+ def __init__ (self , section = '' ):
1306
1309
conf = config_mod .get_config (config_file )
1307
1310
pd .set_option ('display.max_rows' , conf .getint ('display' , 'max_rows' ))
1308
1311
pd .set_option ('display.width' , conf .getint ('display' , 'width' ))
1309
1312
pd .set_option ('display.max_columns' , conf .getint ('display' , 'max_columns' ))
1310
- desconf = config_mod .get_desconfig (desfile )
1311
- db = conf .get ('easyaccess' , 'database' )
1313
+ if section == '' :
1314
+ db = conf .get ('easyaccess' , 'database' )
1315
+ else :
1316
+ db = section
1312
1317
self .prefetch = conf .getint ('easyaccess' , 'prefetch' )
1313
1318
self .dbname = db
1314
1319
#connect to db
1320
+ desconf = config_mod .get_desconfig (desfile , self .dbname )
1315
1321
self .user = desconf .get ('db-' + self .dbname , 'user' )
1316
1322
self .dbhost = desconf .get ('db-' + self .dbname , 'server' )
1317
1323
self .port = desconf .get ('db-' + self .dbname , 'port' )
1318
1324
self .password = desconf .get ('db-' + self .dbname , 'passwd' )
1319
1325
kwargs = {'host' : self .dbhost , 'port' : self .port , 'service_name' : self .dbname }
1320
1326
dsn = cx_Oracle .makedsn (** kwargs )
1321
- print 'Connecting to DB...'
1327
+ print 'Connecting to DB ** %s ** ...' % self . dbname
1322
1328
self .con = cx_Oracle .connect (self .user , self .password , dsn = dsn )
1323
1329
1324
1330
def ping (self ):
@@ -1358,16 +1364,17 @@ def error(self, message):
1358
1364
1359
1365
try :
1360
1366
import readline
1361
- #save = sys.stdout
1362
- #sys.stdout = open("/dev/null","w")
1363
- readline .read_history_file (history_file )
1364
- #sys.stdout = save
1365
1367
readline_present = True
1366
- readline .set_history_length (conf .getint ('easyaccess' , 'histcache' ))
1367
1368
except :
1368
- print sys .exc_info ()
1369
1369
readline_present = False
1370
1370
1371
+ if readline_present == True :
1372
+ try :
1373
+ readline .read_history_file (history_file )
1374
+ readline .set_history_length (conf .getint ('easyaccess' , 'histcache' ))
1375
+ except :
1376
+ 'Print readline might give problems accesing the history of commands'
1377
+
1371
1378
parser = MyParser (description = 'Easy Access' , version = "version: %s" % __version__ )
1372
1379
parser .add_argument ("-c" , "--command" , dest = 'command' , help = "Executes command and exit" )
1373
1380
parser .add_argument ("-l" , "--loadsql" , dest = 'loadsql' , help = "Loads a sql command, execute it and exit" )
@@ -1376,27 +1383,29 @@ def error(self, message):
1376
1383
parser .add_argument ("-s" , "--db" , dest = 'db' , help = "bypass database name, [dessci, desoper or destest]" )
1377
1384
args = parser .parse_args ()
1378
1385
1379
- desconf = config_mod .get_desconfig (desfile )
1380
1386
1381
1387
if args .db is not None :
1382
1388
db = args .db
1389
+ if db [:3 ] == 'db-' : db = db [3 :]
1383
1390
else :
1384
1391
db = conf .get ('easyaccess' , 'database' )
1385
1392
1393
+ desconf = config_mod .get_desconfig (desfile ,db )
1394
+
1386
1395
if args .command is not None :
1387
1396
cmdinterp = easy_or (conf , desconf , db , interactive = False )
1388
1397
cmdinterp .onecmd (args .command )
1389
- sys . exit (0 )
1398
+ os . _exit (0 )
1390
1399
elif args .loadsql is not None :
1391
1400
cmdinterp = easy_or (conf , desconf , db , interactive = False )
1392
1401
linein = "loadsql " + args .loadsql
1393
1402
cmdinterp .onecmd (linein )
1394
- sys . exit (0 )
1403
+ os . _exit (0 )
1395
1404
elif args .loadtable is not None :
1396
1405
cmdinterp = easy_or (conf , desconf , db , interactive = False )
1397
1406
linein = "load_table " + args .loadtable
1398
1407
cmdinterp .onecmd (linein )
1399
- sys . exit (0 )
1408
+ os . _exit (0 )
1400
1409
else :
1401
1410
os .system (['clear' , 'cls' ][os .name == 'nt' ])
1402
1411
easy_or (conf , desconf , db ).cmdloop ()
0 commit comments