Example #1
0
def migrate_txrc_file(txrc_file, txrc):
    """Migrate the txrc file, if needed."""
    if not os.path.exists(txrc_file):
        return txrc
    for section in txrc.sections():
        try:
            txrc.get(section, 'api_hostname')
        except configparser.NoOptionError:
            txrc.set(section, 'api_hostname',
                     DEFAULT_HOSTNAMES['api_hostname'])

        orig_hostname = txrc.get(section, 'hostname')
        hostname = visit_hostname(orig_hostname)
        if hostname != orig_hostname:
            msg = "Hostname %s should be changed to %s."
            logger.info(msg % (orig_hostname, hostname))
            if (sys.stdin.isatty() and sys.stdout.isatty()
                    and confirm('Change it now? ', default=True)):
                txrc.set(section, 'hostname', hostname)
                msg = 'Hostname changed'
                logger.info(msg)
            else:
                hostname = orig_hostname
        save_txrc_file(txrc_file, txrc)
    return txrc
Example #2
0
 def _migrate_txrc_file(self, txrc):
     """Migrate the txrc file, if needed."""
     for section in txrc.sections():
         orig_hostname = txrc.get(section, 'hostname')
         hostname = visit_hostname(orig_hostname)
         if hostname != orig_hostname:
             msg = "Hostname %s should be changed to %s."
             logger.info(msg % (orig_hostname, hostname))
             if (sys.stdin.isatty() and sys.stdout.isatty() and
                 confirm('Change it now? ', default=True)):
                 txrc.set(section, 'hostname', hostname)
                 msg = 'Hostname changed'
                 logger.info(msg)
             else:
                 hostname = orig_hostname
         self._save_txrc_file(txrc)
     return txrc
Example #3
0
 def _migrate_txrc_file(self, txrc):
     """Migrate the txrc file, if needed."""
     for section in txrc.sections():
         orig_hostname = txrc.get(section, 'hostname')
         hostname = visit_hostname(orig_hostname)
         if hostname != orig_hostname:
             msg = "Hostname %s should be changed to %s."
             logger.info(msg % (orig_hostname, hostname))
             if (sys.stdin.isatty() and sys.stdout.isatty()
                     and confirm('Change it now? ', default=True)):
                 txrc.set(section, 'hostname', hostname)
                 msg = 'Hostname changed'
                 logger.info(msg)
             else:
                 hostname = orig_hostname
         self._save_txrc_file(txrc)
     return txrc