From 6a2611d8df1fbd23a02680b86d230eb50b663f9e Mon Sep 17 00:00:00 2001 From: Marcos Sabater Date: Tue, 26 Jun 2018 09:35:49 +0200 Subject: [PATCH] added netrc2hgrc.py --- tests/netrc2hgrc.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 tests/netrc2hgrc.py diff --git a/tests/netrc2hgrc.py b/tests/netrc2hgrc.py new file mode 100644 index 0000000..1d87fe6 --- /dev/null +++ b/tests/netrc2hgrc.py @@ -0,0 +1,27 @@ +import netrc +import os +try: + from configparser import ConfigParser, DuplicateSectionError +except ImportError: + from ConfigParser import ConfigParser, DuplicateSectionError + + +def main(): + netrc_ = netrc.netrc(os.path.expanduser('~/.netrc')) + config = ConfigParser() + try: + config.add_section('auth') + except DuplicateSectionError: + pass + hgrc = os.path.expanduser('~/.hgrc') + config.read(hgrc) + for host, (login, _, password) in netrc_.hosts.items(): + config.set('auth', host + '.prefix', host) + config.set('auth', host + '.username', login) + config.set('auth', host + '.password', password) + with open(hgrc, 'w') as fp: + config.write(fp) + + +if __name__ == '__main__': + main()