@@ -1282,24 +1282,24 @@ def do_whoami(self, arg):
1282
1282
sql_getUserDetails = "select * from dba_users where username = '" + self .user + "'"
1283
1283
self .query_and_print (sql_getUserDetails , print_time = False )
1284
1284
1285
- def do_myquota (self , arg ):
1285
+ def do_myquota (self , arg , clear = True ):
1286
1286
"""
1287
1287
DB:Print information about quota status.
1288
1288
1289
1289
Usage: myquota
1290
1290
"""
1291
1291
sql_getquota = "select TABLESPACE_NAME, \
1292
1292
MBYTES_USED/1024 as GBYTES_USED, MBYTES_LEFT/1024 as GBYTES_LEFT from myquota"
1293
- self .query_and_print (sql_getquota , print_time = False )
1293
+ self .query_and_print (sql_getquota , print_time = False , clear = clear )
1294
1294
1295
- def do_mytables (self , arg ):
1295
+ def do_mytables (self , arg , clear = True ):
1296
1296
"""
1297
1297
DB:Lists table you have made in your 'mydb'
1298
1298
1299
1299
Usage: mytables
1300
1300
"""
1301
1301
query = "SELECT table_name FROM user_tables"
1302
- self .query_and_print (query , print_time = False , extra = "List of my tables" )
1302
+ self .query_and_print (query , print_time = False , extra = "List of my tables" , clear = clear )
1303
1303
1304
1304
def do_find_user (self , line ):
1305
1305
"""
@@ -1514,7 +1514,7 @@ def complete_show_index(self, text, line, begidx, lastidx):
1514
1514
return self ._complete_tables (text )
1515
1515
1516
1516
1517
- def do_load_table (self , line ):
1517
+ def do_load_table (self , line , name = '' ):
1518
1518
"""
1519
1519
DB:Loads a table from a file (csv or fits) taking name from filename and columns from header
1520
1520
@@ -1549,7 +1549,10 @@ def do_load_table(self, line):
1549
1549
print '\n Do not use extra . in filename\n '
1550
1550
return
1551
1551
else :
1552
- table = alls [0 ]
1552
+ if name == '' :
1553
+ table = alls [0 ]
1554
+ else :
1555
+ table = name
1553
1556
format = alls [1 ]
1554
1557
if format in ('csv' , 'tab' ):
1555
1558
if format == 'csv' : sepa = ','
@@ -1825,6 +1828,10 @@ def to_pandas(cur):
1825
1828
1826
1829
class connect (easy_or ):
1827
1830
def __init__ (self , section = '' , quiet = False ):
1831
+ """
1832
+ Creates a connection to the DB ans easyaccess commands, section is obtained frmo
1833
+ config file, can be bypass here, e.g., section = desoper
1834
+ """
1828
1835
self .quiet = quiet
1829
1836
conf = config_mod .get_config (config_file )
1830
1837
self .conf = conf
@@ -1873,6 +1880,35 @@ def describe_table(self, tablename):
1873
1880
self .do_describe_table (tablename ,False )
1874
1881
1875
1882
1883
+ def loadsql (self ,filename ):
1884
+ """
1885
+ Reads sql statement from a file, returns query to be parsed in query_and_save, query_to_pandas, etc.
1886
+ """
1887
+ query = read_buf (filename )
1888
+ if query .find (';' ) > - 1 :
1889
+ query = query .split (';' )[0 ]
1890
+ return query
1891
+
1892
+ def mytables (self ):
1893
+ """
1894
+ List tables in own schema
1895
+ """
1896
+ self .do_mytables ('' ,clear = False )
1897
+
1898
+ def myquota (self ):
1899
+ """
1900
+ Show quota in current database
1901
+ """
1902
+ self .do_myquota ('' ,clear = False )
1903
+
1904
+ def load_table (self , table_file , name = '' ):
1905
+ """
1906
+ Loads and create a table in the DB. If name is not passed, is taken from
1907
+ the filename. Formats supported are fits, csv and tab files
1908
+ """
1909
+ self .do_load_table (table_file , name = name )
1910
+
1911
+
1876
1912
# #################################################
1877
1913
1878
1914
class MyParser (argparse .ArgumentParser ):
@@ -1918,7 +1954,7 @@ def colored(line, color):
1918
1954
parser .add_argument ("-c" , "--command" , dest = 'command' , help = "Executes command and exit" )
1919
1955
parser .add_argument ("-l" , "--loadsql" , dest = 'loadsql' , help = "Loads a sql command, execute it and exit" )
1920
1956
parser .add_argument ("-lt" , "--load_table" , dest = 'loadtable' , help = "Loads a table directly into DB, using \
1921
- csv or fits format and getting name from filename" )
1957
+ csv, tab or fits format and getting name from filename" )
1922
1958
parser .add_argument ("-s" , "--db" , dest = 'db' , help = "bypass database name, [dessci, desoper or destest]" )
1923
1959
parser .add_argument ("-q" , "--quiet" , action = "store_true" , dest = 'quiet' , help = "quiet initialization" )
1924
1960
args = parser .parse_args ()
0 commit comments