From 86aa97bdc2a36fe57b6b47c34cade5cd800706f8 Mon Sep 17 00:00:00 2001 From: Achilles Rasquinha Date: Wed, 14 Feb 2018 20:14:36 +0530 Subject: [PATCH 1/2] show progress of database restore --- frappe/model/db_schema.py | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/frappe/model/db_schema.py b/frappe/model/db_schema.py index 64d7daca71..b5b54af873 100644 --- a/frappe/model/db_schema.py +++ b/frappe/model/db_schema.py @@ -551,8 +551,30 @@ class DbManager: def restore_database(self,target,source,user,password): from frappe.utils import make_esc esc = make_esc('$ ') - os.system("mysql -u %s -p%s -h%s %s < %s" % \ - (esc(user), esc(password), esc(frappe.db.host), esc(target), source)) + + from distutils.spawn import find_executable + pipe = find_executable('pv') + if pipe: + pipe = '{pipe} {source} |'.format( + pipe = pipe, + source = source + ) + source = '' + else: + source = '< {source}'.format(source = source) + + if pipe: + print('Creating Database...') + + command = '{pipe} mysql -u {user} -p{password} -h{host} {target} {source}'.format( + pipe = pipe, + user = esc(user), + password = esc(password), + host = esc(frappe.db.host), + target = esc(target), + source = source + ) + os.system(command) def drop_table(self,table_name): """drop table if exists""" From b5393fd1eecb0b6ef77770ee4795b16c1035f43f Mon Sep 17 00:00:00 2001 From: Achilles Rasquinha Date: Tue, 20 Feb 2018 11:19:33 +0530 Subject: [PATCH 2/2] [FIX] empty if pipe not found --- frappe/model/db_schema.py | 1 + 1 file changed, 1 insertion(+) diff --git a/frappe/model/db_schema.py b/frappe/model/db_schema.py index b5b54af873..79b7a0bd4a 100644 --- a/frappe/model/db_schema.py +++ b/frappe/model/db_schema.py @@ -561,6 +561,7 @@ class DbManager: ) source = '' else: + pipe = '' source = '< {source}'.format(source = source) if pipe: