Skip to content

Commit

Permalink
Merge pull request #126 from mgckind/migration
Browse files Browse the repository at this point in the history
Migration
  • Loading branch information
mgckind authored May 23, 2017
2 parents 9b7a07a + 8553d47 commit 74e52e9
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 26 deletions.
27 changes: 18 additions & 9 deletions easyaccess/config_ea.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
configcomment = """#
# Easyaccess default parameters
#
# database : Default is dessci, change to desoper, destest and others
# database : Default is dessci, change to desoper, destest, oldsci and others
# Make sure the db-"database" section is in the .desservices.ini
# editor : Default editor to open from inside easyaccess if $EDITOR is not set
# prefetch : Prefetch number of rows to get from oracle (not the number of total rows)
Expand Down Expand Up @@ -165,10 +165,10 @@ def get_desconfig(desfile, db, verbose=True, user=None, pw1=None):
if not db[:3] == 'db-':
db = 'db-' + db

if db == 'db-dessci':
if db == 'db-oldsci':
db_alter = 'db-desoper'
elif db == 'db-desoper':
db_alter = 'db-dessci'
db_alter = 'db-oldsci'
else:
db_alter = None
config = configparser.ConfigParser()
Expand All @@ -183,11 +183,11 @@ def get_desconfig(desfile, db, verbose=True, user=None, pw1=None):
if verbose:
print()

databases = ['db-desoper', 'db-dessci', 'db-destest', 'db-newsci'] # most used ones anyways
databases = ['db-desoper', 'db-dessci', 'db-destest', 'db-oldsci'] # most used ones anyways

if db not in databases and not config.has_section(db):
check_db = input(
'\nDB entered is not dessci, desoper, destest or newsci '
'\nDB entered is not dessci, desoper, destest or oldsci '
'or in DES_SERVICE file, continue anyway [y]/n\n')
if check_db in ('n', 'N', 'no', 'No', 'NO'):
sys.exit(0)
Expand All @@ -196,8 +196,10 @@ def get_desconfig(desfile, db, verbose=True, user=None, pw1=None):
if verbose:
print('\nAdding section %s to des_service file\n' % db)
configwrite = True
if db == 'db-newsci':
if db == 'db-dessci':
kwargs = {'host': server_2, 'port': port_n, 'service_name': 'dessci'}
elif db == 'db-oldsci':
kwargs = {'host': server_n, 'port': port_n, 'service_name': 'dessci'}
else:
kwargs = {'host': server_n, 'port': port_n, 'service_name': db[3:]}
dsn = cx_Oracle.makedsn(**kwargs)
Expand All @@ -213,7 +215,7 @@ def get_desconfig(desfile, db, verbose=True, user=None, pw1=None):
except:
(type, value, traceback) = sys.exc_info()
print()
if value.message.code == 28001:
if value.args[0].code == 28001:
print("ORA-28001: the password has expired or cannot be the default one")
print("Need to create a new password\n")
password = pw1
Expand All @@ -236,7 +238,7 @@ def get_desconfig(desfile, db, verbose=True, user=None, pw1=None):
print('\n Check your credentials and/or database access\n')
sys.exit(0)
print(value)
if value.message.code == 1017:
if value.args[0].code == 1017:
pass
else:
sys.exit(0)
Expand All @@ -254,13 +256,20 @@ def get_desconfig(desfile, db, verbose=True, user=None, pw1=None):
if not config.has_option(db, 'passwd'):
configwrite = True
config.set(db, 'passwd', pw1)
if db == 'db-newsci':
if db == 'db-dessci':
if not config.has_option(db, 'name'):
configwrite = True
config.set(db, 'name', 'dessci')
if not config.has_option(db, 'server'):
configwrite = True
config.set(db, 'server', server_2)
if db == 'db-oldsci':
if not config.has_option(db, 'name'):
configwrite = True
config.set(db, 'name', 'dessci')
if not config.has_option(db, 'server'):
configwrite = True
config.set(db, 'server', server_n)
else:
if not config.has_option(db, 'name'):
configwrite = True
Expand Down
4 changes: 2 additions & 2 deletions easyaccess/eaparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ def get_args(config_file):
parser.add_argument("--memsize", dest='memsize', type=int, default=None,
help=" Size of chunk to be read at a time in Mb. Use with --load_table or "
"--append_table")
parser.add_argument("-s", "--db", dest='db', choices=['dessci', 'desoper', 'destest', 'newsci'],
help="Override database name [dessci,desoper,destest,newsci]")
parser.add_argument("-s", "--db", dest='db', choices=['dessci', 'desoper', 'destest', 'oldsci'],
help="Override database name [dessci,desoper,destest,oldsci]")
parser.add_argument("-q", "--quiet", action="store_true", dest='quiet',
help="Silence initialization, no loading bar")
parser.add_argument("-u", "--user", dest='user')
Expand Down
28 changes: 14 additions & 14 deletions easyaccess/easyaccess.py
Original file line number Diff line number Diff line change
Expand Up @@ -939,7 +939,7 @@ def query_results(self, query):

def get_tables_names(self):

if self.dbname in ('dessci', 'desoper', 'destest', 'newsci'):
if self.dbname in ('dessci', 'desoper', 'destest', 'oldsci'):
query = """
select table_name from DES_ADMIN.CACHE_TABLES
union select table_name from user_tables
Expand All @@ -964,7 +964,7 @@ def get_tables_names_user(self, user):
user.upper(), "cyan", self.ct))
print(tnames)
else:
if self.dbname in ('dessci', 'desoper'):
if self.dbname in ('dessci', 'desoper', 'oldsci'):
query = """
select count(username) as cc from des_users
where upper(username) = upper('%s')""" % user
Expand All @@ -982,9 +982,9 @@ def get_tables_names_user(self, user):
user.upper(), 'cyan', self.ct))

def get_userlist(self):
if self.dbname in ('dessci', 'desoper'):
if self.dbname in ('dessci', 'desoper', 'oldsci'):
query = 'select distinct username from des_users order by username'
if self.dbname in ('destest', 'newsci'):
if self.dbname in ('destest'):
query = 'select distinct username from dba_users order by username'
temp = self.cur.execute(query)
tnames = pd.DataFrame(temp.fetchall())
Expand Down Expand Up @@ -1380,7 +1380,7 @@ def do_execproc(self, line):

def do_set_password(self, arg):
"""
DB:Set a new password on this and all other DES instances (DESSCI, DESOPER)
DB:Set a new password on this DES instance
Usage: set_password
"""
Expand All @@ -1403,9 +1403,9 @@ def do_set_password(self, arg):
self.query_and_print(query, print_time=False, suc_arg=confirm)
self.desconfig.set('db-'+self.dbname, 'passwd', pw1)
config_mod.write_desconfig(desfile, self.desconfig)
if self.dbname not in ('dessci', 'desoper'):
if self.dbname not in ('oldsci', 'desoper'):
return
dbases = ['DESSCI', 'DESOPER']
dbases = ['OLDSCI', 'DESOPER']
for db in dbases:
kwargs = {'host': self.dbhost, 'port': self.port, 'service_name': self.service_name}
dsn = cx_Oracle.makedsn(**kwargs)
Expand All @@ -1418,7 +1418,7 @@ def do_set_password(self, arg):
temp_con.commit()
temp_cur.close()
temp_con.close()
self.desconfig.set('db-dessci', 'passwd', pw1)
self.desconfig.set('db-oldsci', 'passwd', pw1)
self.desconfig.set('db-desoper', 'passwd', pw1)
config_mod.write_desconfig(desfile, self.desconfig)
except:
Expand Down Expand Up @@ -1462,7 +1462,7 @@ def do_show_db(self, arg):

def do_change_db(self, line):
"""
DB: Change to another database, namely dessci, desoper or destest
DB: Change to another database, namely dessci, desoper, destest or oldsci
Usage:
change_db DB # Changes to DB, it does not refresh metadata, e.g.: change_db desoper
Expand All @@ -1472,7 +1472,7 @@ def do_change_db(self, line):
return self.do_help('change_db')
line = " ".join(line.split())
key_db = line.split()[0]
if key_db in ('dessci', 'desoper', 'destest', 'newsci'):
if key_db in ('dessci', 'desoper', 'destest', 'oldsci'):
if key_db == self.dbname:
print(colored("Already connected to : %s" % key_db, "green", self.ct))
return
Expand Down Expand Up @@ -1523,7 +1523,7 @@ def do_change_db(self, line):
return

def complete_change_db(self, text, line, start_index, end_index):
options_db = ['desoper', 'dessci', 'destest', 'newsci']
options_db = ['desoper', 'dessci', 'destest', 'oldsci']
if text:
return [option for option in options_db if option.startswith(text.lower())]
else:
Expand All @@ -1538,7 +1538,7 @@ def do_whoami(self, arg):
# It might be useful to print user roles as well
# select GRANTED_ROLE from USER_ROLE_PRIVS

if self.dbname in ('dessci', 'desoper'):
if self.dbname in ('dessci', 'desoper', 'oldsci'):
sql_getUserDetails = """
select d.username, d.email, d.firstname as first, d.lastname as last,
trunc(sysdate-t.ptime,0)||' days ago' last_passwd_change,
Expand Down Expand Up @@ -1595,7 +1595,7 @@ def do_find_user(self, line):
return self.do_help('find_user')
line = " ".join(line.split())
keys = line.split()
if self.dbname in ('dessci', 'desoper'):
if self.dbname in ('dessci', 'desoper', 'oldsci'):
query = 'select * from des_users where '
if self.dbname in ('destest'):
query = 'select * from dba_users where '
Expand Down Expand Up @@ -2555,7 +2555,7 @@ def __init__(self, section='', user=None, passwd=None, quiet=False, refresh=Fals
Parameters:
-----------
section : DB connection : dessci, desoper, destest, newsci
section : DB connection : dessci, desoper, destest, oldsci
user : Manualy use username
passwd : password for username (if not enter is prompted)
quiet : Don't print much
Expand Down
2 changes: 1 addition & 1 deletion easyaccess/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def last_pip_version():
return sorted(uploads, key=lambda x: x[1])[-1][0]


version_tag = (1, 4, 1, 'dev-e5fc75')
version_tag = (1, 4, 1, 'dev-d5cc31b')
__version__ = '.'.join(map(str, version_tag[:3]))

if len(version_tag) > 3:
Expand Down

0 comments on commit 74e52e9

Please sign in to comment.