def import_masternode_conf(self, filename): """Import a masternode.conf file.""" pw = None if self.manager.wallet.has_password(): pw = self.gui.password_dialog(msg=_('Please enter your password to import Masternode information.')) if pw is None: return if not os.path.exists(filename): QMessageBox.critical(self, _('Error'), _('File does not exist')) return with open(filename, 'r') as f: lines = f.readlines() # Show an error if the conf file is malformed. try: conf_lines = parse_masternode_conf(lines) except Exception as e: QMessageBox.critical(self, _('Error'), _(str(e))) return num = self.masternodes_widget.import_masternode_conf_lines(conf_lines, pw) if not num: return QMessageBox.warning(self, _('Failed to Import'), _('Could not import any masternode configurations. Please ensure that they are not already imported.')) # Grammar is important. configurations = 'configuration' if num == 1 else 'configurations' adjective = 'this' if num == 1 else 'these' noun = 'masternode' if num == 1 else 'masternodes' words = {'adjective': adjective, 'configurations': configurations, 'noun': noun, 'num': num,} msg = '{num} {noun} {configurations} imported.\n\nPlease wait for transactions involving {adjective} {configurations} to be retrieved before activating {adjective} {noun}.'.format(**words) QMessageBox.information(self, _('Success'), _(msg))
def import_masternode_conf(self, filename): """Import a masternode.conf file.""" pw = None if self.manager.wallet.has_password(): pw = self.gui.password_dialog(msg=_('Please enter your password to import Masternode information.')) if pw is None: return if not os.path.exists(filename): QMessageBox.critical(self, _('Error'), _('File does not exist')) return with open(filename, 'r') as f: lines = f.readlines() # Show an error if the conf file is malformed. try: conf_lines = parse_masternode_conf(lines) except Exception as e: QMessageBox.critical(self, _('Error'), _(str(e))) return num = self.masternodes_widget.import_masternode_conf_lines(conf_lines, pw) if not num: return QMessageBox.warning(self, _('Failed to Import'), _('Could not import any masternode configurations. Please ensure that they are not already imported.')) # Grammar is important. configurations = 'configuration' if num == 1 else 'configurations' adjective = 'this' if num == 1 else 'these' noun = 'masternode' if num == 1 else 'masternodes' words = {'adjective': adjective, 'configurations': configurations, 'noun': noun, 'num': num,} msg = '{num} {noun} {configurations} imported.\n\nPlease wait for transactions involving {adjective} {configurations} to be retrieved before activating {adjective} {noun}.'.format(**words) QMessageBox.information(self, _('Success'), _(msg))
def test_parse(self): lines = [ 'mn1 127.0.0.2:19999 XJo71yhAvayar2geJiJocDMXVSwQCm14gNZvMmk7Pc1M8Bv8Ev7L 2bcd3c84c84f87eaa86e4e56834c92927a07f9e18718810b92e0d0324456a67c 0', ] conf_lines = parse_masternode_conf(lines) expected = [ MasternodeConfLine('mn1', '127.0.0.2:19999', 'XJo71yhAvayar2geJiJocDMXVSwQCm14gNZvMmk7Pc1M8Bv8Ev7L', '2bcd3c84c84f87eaa86e4e56834c92927a07f9e18718810b92e0d0324456a67c', 0), ] for i, conf in enumerate(conf_lines): self.assertEqual(expected[i], conf)
def test_parse(self): lines = [ 'mn1 127.0.0.2:19999 XJo71yhAvayar2geJiJocDMXVSwQCm14gNZvMmk7Pc1M8Bv8Ev7L 2bcd3c84c84f87eaa86e4e56834c92927a07f9e18718810b92e0d0324456a67c 0', ] conf_lines = parse_masternode_conf(lines) expected = [ MasternodeConfLine('mn1', '127.0.0.2:19999', 'XJo71yhAvayar2geJiJocDMXVSwQCm14gNZvMmk7Pc1M8Bv8Ev7L', '2bcd3c84c84f87eaa86e4e56834c92927a07f9e18718810b92e0d0324456a67c', 0), ] for i, conf in enumerate(conf_lines): self.assertEqual(expected[i], conf)