Форум сайта python.su
Есть конфиг ISPmanager
DbServer "MySQL" { Owner __Owner__ AccessType allow ChangePassword 2012-07-23 Hostname localhost Password qXb8fMwe SockPath /var/lib/mysql/mysql.sock Type mysql User root }
re.search(r'DbServer\s"MySQL"\s+ \{ (\s+.+\n)* \}', data, re.VERBOSE))
Option NoMysqlQuota #Option DisableSecurePhpBin Option LogLevel 9 DNS named Mirror http://ru.download.ispsystem.com/ extaction mindterm /mancgi/mindterm ip 194.44.0.219 shared _ ip 194.44.0.229 shared _ PluginSource http://download.ispsystem.com/plugins/ispmgr_plugins.xml PluginSource http://usings.ru/isp_plugins/ispmgr_plugins.xml path db4 /usr/bin/db_dump -p /etc/sasldb2 path DefaultHomeDir /var/www ApacheVersion 2 Web web WebModules apache path httpd.conf /etc/httpd/conf/httpd.conf path httpd /usr/sbin/apachectl path apachectl /usr/sbin/apachectl start Service "HTTP" { Confname httpd Monitored NO Process httpd Start /etc/rc.d/init.d/httpd start Stop /etc/rc.d/init.d/httpd stop Type www } Service "FTP" { Confname proftpd Monitored NO Process proftpd Start /etc/rc.d/init.d/proftpd start Stop /etc/rc.d/init.d/proftpd stop Type ftp } Service "POP3" { Confname dovecot Monitored NO Process dovecot Start /etc/rc.d/init.d/dovecot start Stop /etc/rc.d/init.d/dovecot stop Type pop3 } Service "MySQL" { Confname mysqld Monitored NO Process mysqld Start /etc/rc.d/init.d/mysqld start Stop /etc/rc.d/init.d/mysqld stop Type mysql Ip /var/lib/mysql/mysql.sock } Service "DNS" { Confname named Monitored NO Process named Start /etc/rc.d/init.d/named start Stop /etc/rc.d/init.d/named stop Type dns } ApacheProcName httpd ApacheUid 48 ApacheGid 48 Option Agree path genericstable /etc/mail/generic path accessdb /etc/mail/access path php-configs /etc/php.d path phpbinary /usr/bin/php-cgi path php.ini /etc/php.ini path php-extensions /usr/lib64/php/modules path dovecot.passwd /etc/dovecot/dovecot.passwd path dovecotpw-bin /usr/bin/doveadm pw POP3 dovecot path iptables /etc/sysconfig/iptables DbServer "MySQL" { Owner __Owner__ AccessType allow ChangePassword 2012-07-23 Hostname localhost Password qXb8fMwe SockPath /var/lib/mysql/mysql.sock Type mysql User root } SupportCenterServer MySQL
Офлайн
#!/usr/bin/env python3 import re with open('file.txt') as fin: text = fin.read() pat_sec = r'(\S+) "([^"]+)" {([^}]+)}' pat_kv = r'(\S+)\s+(\S+)' seclst = re.findall(pat_sec, text) for stype, sname, sbody in seclst: blst = re.findall(pat_kv, sbody) sectype = 'dbserver' secname = 'mysql' seckeys = ('hostname', 'password', 'type', 'user') if stype.lower() == sectype and \ sname.lower() == secname: print(stype, sname) for i in blst: print(i) bodydct = {k.lower(): v for k, v in blst} for k in seckeys: print(k, '->', bodydct[k])
[guest@localhost reconf]$ ./reconf.py
DbServer MySQL
('Owner', '__Owner__')
('AccessType', 'allow')
('ChangePassword', '2012-07-23')
('Hostname', 'localhost')
('Password', 'qXb8fMwe')
('SockPath', '/var/lib/mysql/mysql.sock')
('Type', 'mysql')
('User', 'root')
hostname -> localhost
password -> qXb8fMwe
type -> mysql
user -> root
[guest@localhost reconf]$
Офлайн