Skip to content

Commit 17e85e0

Browse files
author
Ignacio Elizaga
authored
Merge pull request #41 from Zerpet/feature/prompt-user
Prompt user before running
2 parents e5fe866 + 3c00a7a commit 17e85e0

File tree

1 file changed

+29
-4
lines changed

1 file changed

+29
-4
lines changed

gpcheckintegrity

+29-4
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,15 @@ def parseargs():
3737
' verify that all the tables in a specific database can be accessed.',
3838
epilog='Source code available at github.com/ielizaga/gpcheckintegrity')
3939
parser.add_option('-v', '--verbose', action='store_true', help='Enables debug logging')
40+
parser.add_option('-y', '--yes', action='store_true', help='Assumes yes and do not prompt to confirm')
4041
parser.add_option('-A', '--all', action='store_true', help='Check all databases')
4142
parser.add_option('-d', '--database', help='Database to connect to')
4243
parser.add_option('-s', '--schema', help='Checks all the tables in this schema')
4344
parser.add_option('-S', '--schema-list', dest='schema_list',
4445
help='Comma-separated list of schemas to check tables from. Example: s1,s2,s3')
4546
parser.add_option('-t', '--table', help='Check just this table')
46-
parser.add_option('-B', '--parallel', type=int, default=DEFAULT_NUM_THREADS, help='Number of parallel workers (Default: 32)')
47+
parser.add_option('-B', '--parallel', type=int, default=DEFAULT_NUM_THREADS,
48+
help='Number of parallel workers (Default: 32)')
4749
(options_object, args_object) = parser.parse_args()
4850

4951
USER = os.getenv('USER')
@@ -84,8 +86,8 @@ def connect(user=None, password=None, host=None, port=None, database=None, utili
8486
database = os.environ.get('PGDATABASE', 'template1')
8587
try:
8688
logger.debug('connecting to %s:%s %s' % (host, port, database))
87-
db_conn = pg.connect(host=host, port=port, user=user,
88-
passwd=password, dbname=database, opt=conf)
89+
db_conn = pg.connect(host=host, port=port, user=user,
90+
passwd=password, dbname=database, opt=conf)
8991
except pg.InternalError, ex:
9092
logger.error('could not connect to %s: "%s"' %
9193
(database, str(ex).strip()))
@@ -290,6 +292,11 @@ def _spawn_threads(database):
290292
if options.table is None and options.schema is None and options.schema_list is None:
291293
tables.extend(get_tables(database))
292294

295+
if options.yes is not True \
296+
and prompt_user(database, tables) is False:
297+
logger.info('User cancelled the program, aborting...')
298+
sys.exit(0)
299+
293300
dbids = get_gp_segment_configuration() # get Greenplum segment information
294301
threads = []
295302
for dbid in dbids:
@@ -306,6 +313,24 @@ def _spawn_threads(database):
306313
return
307314

308315

316+
def prompt_user(database, tables):
317+
logger.info('We are going to check the following. Make sure you intended to run on those tables '
318+
'and nothing is missing')
319+
320+
for table_obj in tables:
321+
logger.info('DB: %(database)s - %(schema)s.%(table)s' % {'database': database, 'schema': table_obj['schema'],
322+
'table': table_obj['table']})
323+
while True:
324+
logger.info('\nDo you want to proceed? [Y/N]')
325+
line = sys.stdin.readline()
326+
327+
if line[:-1] in ('Y', 'y', 'yes', 'Yes'):
328+
return True
329+
330+
if line[:-1] in ('N', 'n', 'no', 'No'):
331+
return False
332+
333+
309334
class CheckIntegrity(Thread):
310335
def __init__(self, tables, hostname, database, content, port):
311336
Thread.__init__(self)
@@ -398,7 +423,7 @@ if __name__ == '__main__':
398423
logger.info("Checking database %s" % db['datname'])
399424
_spawn_threads(db['datname'])
400425
else:
401-
_spawn_threads(options.database)
426+
_spawn_threads(options.database)
402427

403428
logger.info("ERROR REPORT SUMMARY %s" % datetime.now())
404429
logger.info("============================================")

0 commit comments

Comments
 (0)