Experimente augeas . Ele oferece ambas as ligações do Python e uma interface de linha de comando - augtool .
[dba@pgsql ~]$ augtool
augtool> defvar pghba /files/var/lib/pgsql/data/pg_hba.conf
augtool> ####################################
augtool> ls $pghba
#comment[1] = this is a comment
1/ = (none)
2/ = (none)
#comment[2] = this another comment
3/ = (none)
augtool> ####################################
augtool> ls $pghba/1
type = local
database = all
user = all
method = trust
augtool> ####################################
augtool> insert 01 after $pghba/2
augtool> set $pghba/01/type host
augtool> set $pghba/01/database db1
augtool> set $pghba/01/user user1
augtool> set $pghba/01/address 127.0.0.1
augtool> set $pghba/01/method md5
augtool> ####################################
augtool> save
Saved 1 file(s)
(os comentários começam com #
)