Skip to content

Commit aa2182b

Browse files
Matias Carrasco KindMatias Carrasco Kind
authored andcommitted
Python API Changes
1 parent 40a681d commit aa2182b

File tree

1 file changed

+43
-7
lines changed

1 file changed

+43
-7
lines changed

easyaccess.py

Lines changed: 43 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1282,24 +1282,24 @@ def do_whoami(self, arg):
12821282
sql_getUserDetails = "select * from dba_users where username = '" + self.user + "'"
12831283
self.query_and_print(sql_getUserDetails, print_time=False)
12841284

1285-
def do_myquota(self, arg):
1285+
def do_myquota(self, arg, clear=True):
12861286
"""
12871287
DB:Print information about quota status.
12881288
12891289
Usage: myquota
12901290
"""
12911291
sql_getquota = "select TABLESPACE_NAME, \
12921292
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)
12941294

1295-
def do_mytables(self, arg):
1295+
def do_mytables(self, arg, clear = True):
12961296
"""
12971297
DB:Lists table you have made in your 'mydb'
12981298
12991299
Usage: mytables
13001300
"""
13011301
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)
13031303

13041304
def do_find_user(self, line):
13051305
"""
@@ -1514,7 +1514,7 @@ def complete_show_index(self, text, line, begidx, lastidx):
15141514
return self._complete_tables(text)
15151515

15161516

1517-
def do_load_table(self, line):
1517+
def do_load_table(self, line, name=''):
15181518
"""
15191519
DB:Loads a table from a file (csv or fits) taking name from filename and columns from header
15201520
@@ -1549,7 +1549,10 @@ def do_load_table(self, line):
15491549
print '\nDo not use extra . in filename\n'
15501550
return
15511551
else:
1552-
table = alls[0]
1552+
if name == '':
1553+
table = alls[0]
1554+
else:
1555+
table =name
15531556
format = alls[1]
15541557
if format in ('csv', 'tab'):
15551558
if format == 'csv': sepa = ','
@@ -1825,6 +1828,10 @@ def to_pandas(cur):
18251828

18261829
class connect(easy_or):
18271830
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+
"""
18281835
self.quiet = quiet
18291836
conf = config_mod.get_config(config_file)
18301837
self.conf = conf
@@ -1873,6 +1880,35 @@ def describe_table(self, tablename):
18731880
self.do_describe_table(tablename ,False)
18741881

18751882

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+
18761912
# #################################################
18771913

18781914
class MyParser(argparse.ArgumentParser):
@@ -1918,7 +1954,7 @@ def colored(line, color):
19181954
parser.add_argument("-c", "--command", dest='command', help="Executes command and exit")
19191955
parser.add_argument("-l", "--loadsql", dest='loadsql', help="Loads a sql command, execute it and exit")
19201956
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")
19221958
parser.add_argument("-s", "--db", dest='db', help="bypass database name, [dessci, desoper or destest]")
19231959
parser.add_argument("-q", "--quiet", action="store_true", dest='quiet', help="quiet initialization")
19241960
args = parser.parse_args()

0 commit comments

Comments
 (0)