Reviewers: ,
Description:
trytond: when initializing a database, try to read admin password from
TRYTONPASSFILE before asking…
Please review this at http://codereview.tryton.org/519002/
Affected files:
M bin/trytond
M trytond/server.py
Index: bin/trytond
===================================================================
--- a/bin/trytond
+++ b/bin/trytond
@@ -41,6 +41,10 @@
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:
Index: trytond/server.py
===================================================================
--- a/trytond/server.py
+++ b/trytond/server.py
@@ -142,7 +142,19 @@
for db_name in CONFIG['db_name']:
if init[db_name]:
- while True:
+ # try to read password from environment variable
+ # TRYTONPASSFILE, empty TRYTONPASSFILE ignored
+ passpath = os.getenv('TRYTONPASSFILE')
+ if passpath:
+ try:
+ with open(passpath) as passfile:
+ password = passfile.readline()[:-1]
+ except Exception, err:
+ password = ''
+ sys.stderr.write('Can not read password ' \
+ 'from "%s": "%s"\n' % (passpath, err))
+
+ while not password:
password = getpass('Admin Password for %s: ' % db_name)
password2 = getpass('Admin Password Confirmation: ')
if password != password2:
--
[email protected] mailing list