def keep_running(self, buffer): try: buffer += self.irc.recv(2048) lines = str.split(buffer, "\r\n") buffer = lines.pop() for line in lines: logger.log("Received IRC message: " + line) for line in lines: self.handle_line(line) except KeyboardInterrupt: st = "QUIT :I have to go for now!" self.irc.send(st) raise except: title = "A error occurred in IRCbot %s" % sys.exc_info()[0] body = traceback.format_exc() logger.error(title) logger.error(body) git_issuer.handle_error(title, body) self.send_msg(title) return buffer
def execute(cmd=None): if not cmd: cmd = sys.argv[1:2] try: parser = ArgumentParser(description="Plebnet - a working-class bot") subparsers = parser.add_subparsers(dest="command") # create the setup subcommand parser_list = subparsers.add_parser("setup", help="Run the setup of PlebNet") parser_list.set_defaults(func=execute_setup) # create the check subcommand parser_list = subparsers.add_parser("check", help="Checks if the plebbot is able to clone") parser_list.set_defaults(func=execute_check) # create the conf subcommand parser_list = subparsers.add_parser("conf", help="Allows changing the configuration files") parser_list.set_defaults(func=execute_conf) # create the irc subcommand parser_list = subparsers.add_parser("irc", help="Provides access to the IRC client") parser_list.set_defaults(func=execute_irc) args = parser.parse_args(cmd) args.func() except: title = "An error occured!" body = traceback.format_exc() logger.error(title) logger.error(body) git_issuer.handle_error(title, body)
def purchase_choice_vpn(config): provider = plebnet_settings.get_instance().vpn_host() provider_instance = get_vpn_providers()[provider](child_account()) # no need to generate new child config wallet = TriblerWallet(plebnet_settings.get_instance().wallets_testnet_created()) c = cloudomate_providers['vpn'][provider] configurations = c.get_options() # option is assumbed to be the first vpn provider option option = configurations[0] try: transaction_hash = provider_instance.purchase(wallet, option) except: title = "Failed to purchase vpn: %s" % sys.exc_info()[0] body = traceback.format_exc() logger.error(title) logger.error(body) git_issuer.handle_error(title, body) git_issuer.handle_error("Failed to purchase server", sys.exc_info()[0], ['crash']) return plebnet_settings.FAILURE if not transaction_hash: logger.warning("VPN probably purchased, but transaction hash not returned") config.get('bought').append((provider, option, transaction_hash, config.get('child_index'))) config.get('transactions').append(transaction_hash) config.save() return plebnet_settings.SUCCESS
def init_irc(self): try: logger.log("start running an IRC connection on " + self.server + " " + self.channel) self.irc = socket.socket(socket.AF_INET, socket.SOCK_STREAM) self.irc.connect((self.server, self.port)) except: title = "A error occurred in IRCbot init_irc %s" % sys.exc_info()[0] body = traceback.format_exc() logger.error(title) logger.error(body) git_issuer.handle_error(title, body) git_issuer.handle_error("A error occurred in IRCbot", sys.exc_info()[0], ['crash'])
def purchase_choice(config): """ Purchase the cheapest provider in chosen_providers. If buying is successful this provider is moved to bought. In any case the provider is removed from choices. :param config: config :return: plebnet_settings errorcode """ (provider, option, _) = config.get('chosen_provider') provider_instance = cloudomate_providers['vps'][provider](child_account()) wallet = TriblerWallet( plebnet_settings.get_instance().wallets_testnet_created()) vps_option = get_vps_option(provider, option) try: transaction_hash = provider_instance.purchase(wallet, vps_option) except: title = "Failed to purchase server: %s" % sys.exc_info()[0] body = traceback.format_exc() logger.error(title) logger.error(body) git_issuer.handle_error(title, body) git_issuer.handle_error("Failed to purchase server", sys.exc_info()[0], ['crash']) return plebnet_settings.FAILURE # Cloudomate should throw an exception when purchase fails. The transaction hash is not in fact required, # and even when cloudomate fails to return it, the purchase itself could have been successful. if not transaction_hash: logger.warning( "Server probably purchased, but transaction hash not returned") config.get('bought').append( (provider, option, transaction_hash, config.get('child_index'))) config.get('transactions').append(transaction_hash) config.set('chosen_provider', None) config.save() return plebnet_settings.SUCCESS
def purchase_choice(config): """ Purchase the cheapest provider in chosen_providers. If buying is successful this provider is moved to bought. In any case the provider is removed from choices. :param config: config :return: plebnet_settings errorcode """ (provider, option, _) = config.get('chosen_provider') provider_instance = cloudomate_providers['vps'][provider](child_account()) wallet = TriblerWallet( plebnet_settings.get_instance().wallets_testnet_created()) c = cloudomate_providers['vps'][provider] configurations = c.get_options() option = configurations[option] try: transaction_hash = provider_instance.purchase(wallet, option) except: title = "Failed to purchase server: %s" % sys.exc_info()[0] body = traceback.format_exc() logger.error(title) logger.error(body) git_issuer.handle_error(title, body) git_issuer.handle_error("Failed to purchase server", sys.exc_info()[0], ['crash']) return plebnet_settings.FAILURE if not transaction_hash: return plebnet_settings.FAILURE config.get('bought').append( (provider, transaction_hash, config.get('child_index'))) config.get('transactions').append(transaction_hash) config.set('chosen_provider', None) config.save() return plebnet_settings.SUCCESS