Setting database admin password programmatically

113 views
Skip to first unread message

Dr. Praveen Bhatia

unread,
Jun 9, 2017, 10:50:38 AM6/9/17
to tryton
Hi,
    I have written a convoluted program like this to set the password of the database admin which then prompts for the password. 

import trytond
import trytond.admin

class Mytest() : 
    def __init__(self) :
        self.database_names=[ 'mydb']
        self.update=''
        self.languages=''
        self.update_modules_list=['country']
        self.password='mypassword'        ### Would like this password to be set

xx = Mytest()

trytond.admin.run(xx)




=================
Is there a simpler easier way to set the admin password by code?

Sergi Almacellas Abellana

unread,
Jun 9, 2017, 10:55:20 AM6/9/17
to try...@googlegroups.com
El 09/06/17 a les 16:50, Dr. Praveen Bhatia ha escrit:
>
>
> =================
> Is there a simpler easier way to set the admin password by code?
You can use the TRYTONPASSFILE environment variable in conjunction with
the trytond-admin --password flag. Running:

trytond-admin --help

Will give the full reference.

Hope it helps.

--
Sergi Almacellas Abellana
www.koolpi.com
Twitter: @pokoli_srk

Dr. Praveen Bhatia

unread,
Jun 9, 2017, 12:07:18 PM6/9/17
to tryton


On Friday, June 9, 2017 at 11:55:20 PM UTC+9, Sergi Almacellas Abellana wrote:
El 09/06/17 a les 16:50, Dr. Praveen Bhatia ha escrit:
>
>
> =================
> Is there a simpler easier way to set the admin password by code?
You can use the TRYTONPASSFILE environment variable in conjunction with
the trytond-admin  --password flag. Running:

trytond-admin --help


I want to do it within the python program and not go to the  cmd shell. The reason is that I am experimenting with the company, and changing the program, dropping the database, creating again and restarting. So going to the command shell every time is irritating. 

Sergi Almacellas Abellana

unread,
Jun 9, 2017, 12:17:32 PM6/9/17
to try...@googlegroups.com


On 9 de juny de 2017 18.07.18 CEST, "Dr. Praveen Bhatia" <praveen...@sumpurn.com> wrote:
>
>
>On Friday, June 9, 2017 at 11:55:20 PM UTC+9, Sergi Almacellas Abellana
>
>wrote:
>>
>> El 09/06/17 a les 16:50, Dr. Praveen Bhatia ha escrit:
>> >
>> >
>> > =================
>> > Is there a simpler easier way to set the admin password by code?
>> You can use the TRYTONPASSFILE environment variable in conjunction
>with
>> the trytond-admin --password flag. Running:
>>
>> trytond-admin --help
>>
>>
>I want to do it within the python program and not go to the cmd shell.
>The
>reason is that I am experimenting with the company, and changing the
>program, dropping the database, creating again and restarting. So going
>to
>the command shell every time is irritating.
>

Then you should call the run [1]method of trytond.admin module.

Hope it helps!

[1] http://hg.tryton.org/trytond/file/9810c81cebe7/trytond/admin.py#l19

--
Enviado desde mi dispositivo Android con K-9 Mail. Por favor, disculpa mi brevedad.

Dr. Praveen Bhatia

unread,
Jun 9, 2017, 12:35:45 PM6/9/17
to tryton
Yes, I am already using it (trytond.admin.run())  in the example code that I wrote above.  ie. 

trytond.admin.run(xx)

It prompts me twice to input and confirm the new password, which is also a little bit irritating for programming in each iteration. 
Is their a better way, when I can just set a fixed password in the program, without having to type a new one twice.

Something like:
setAdminPassword('mypassword')
and I am not prompted for passwords.....  

Sergi Almacellas Abellana

unread,
Jun 9, 2017, 12:42:49 PM6/9/17
to try...@googlegroups.com


On 9 de juny de 2017 18.35.45 CEST, "Dr. Praveen Bhatia" <praveen...@sumpurn.com> wrote:
>
>
>On Saturday, June 10, 2017 at 1:17:32 AM UTC+9, Sergi Almacellas
>Abellana
>wrote:
>>
>>
>>
>> On 9 de juny de 2017 18.07.18 CEST, "Dr. Praveen Bhatia" <
Use the TRYTONDPASSFILE environment variable that should point tk a file that contains the password.

Dr. Praveen Bhatia

unread,
Jun 10, 2017, 12:28:04 AM6/10/17
to tryton
Yes. That worked like a charm...... Thanks !
Reply all
Reply to author
Forward
0 new messages