When a database is initialized, admin password could be read from a file.

issue2780
review519002
This commit is contained in:
Pierre-Louis Bonicoli
2012-09-14 16:10:41 +02:00
parent 4509595762
commit 301c6c8b20
2 changed files with 28 additions and 11 deletions
+4
View File
@@ -41,6 +41,10 @@ def parse_commandline():
parser.add_option("--disable-cron", dest="cron",
action="store_false", help="disable cron")
parser.epilog = 'The first time a database is initialized with "-i" admin'\
' password is read from file defined by TRYTONPASSFILE '\
'environment variable or interactively ask user'
(opt, _) = parser.parse_args()
if opt.config:
+24 -11
View File
@@ -142,17 +142,30 @@ class TrytonServer(object):
for db_name in CONFIG['db_name']:
if init[db_name]:
while True:
password = getpass('Admin Password for %s: ' % db_name)
password2 = getpass('Admin Password Confirmation: ')
if password != password2:
sys.stderr.write('Admin Password Confirmation ' \
'doesn\'t match Admin Password!\n')
continue
if not password:
sys.stderr.write('Admin Password is required!\n')
continue
break
# try to read password from environment variable
# TRYTONPASSFILE, empty TRYTONPASSFILE ignored
passpath = os.getenv('TRYTONPASSFILE')
password = ''
if passpath:
try:
with open(passpath) as passfile:
password = passfile.readline()[:-1]
except Exception, err:
sys.stderr.write('Can not read password ' \
'from "%s": "%s"\n' % (passpath, err))
if not password:
while True:
password = getpass('Admin Password for %s: ' % db_name)
password2 = getpass('Admin Password Confirmation: ')
if password != password2:
sys.stderr.write('Admin Password Confirmation ' \
'doesn\'t match Admin Password!\n')
continue
if not password:
sys.stderr.write('Admin Password is required!\n')
continue
break
database = Database(db_name).connect()
cursor = database.cursor()