def start(): """ Starts Tribler by using the twistd plugin. :return: boolean representing the success of starting Tribler """ env = os.environ.copy() env['PYTHONPATH'] = setup.tribler_home() command = [ 'twistd', '--pidfile=' + setup.tribler_pid(), 'plebnet', '-p', '8085' ] if setup.wallets_testnet(): command.append('--testnet') if setup.tribler_exitnode(): command.append('--exitnode') try: exitcode = subprocess.call(command, cwd=setup.tribler_home(), env=env) if exitcode != 0: logger.error('Failed to start Tribler', "tribler_controller") return False logger.success('Tribler is started', "tribler_controller") logger.log('testnet: ' + str(setup.wallets_testnet())) return True except subprocess.CalledProcessError as e: logger.error(e.output, "tribler_controller") return False
def start(): """ Start tribler :return: """ env = os.environ.copy() env['PYTHONPATH'] = setup.tribler_home() try: if setup.wallets_testnet(): success = subprocess.call([ 'twistd', '--pidfile=' + setup.tribler_pid(), 'plebnet', '-p', '8085' '--testnet' ], cwd=setup.tribler_home(), env=env) else: success = subprocess.call([ 'twistd', '--pidfile=' + setup.tribler_pid(), 'plebnet', '-p', '8085' ], cwd=setup.tribler_home(), env=env) if not success: logger.error('Failed to start Tribler', "tribler_controller") return False logger.success('Tribler is started', "tribler_controller") logger.log('market running: ' + str(market_controller.is_market_running())) return True except subprocess.CalledProcessError as e: logger.error(e.output, "Tribler starter", "tribler_controller") return False
def create_gist(username, password): try: # the log files filename = plebnet_settings.get_instance().logger_file() content = open(filename, 'r').read() # Our url to create issues via POST url = 'https://api.github.com/gists' # Create an authenticated session to create the issue session = requests.Session() session.auth = (username, password) # Create our issue gist = { "description": "the description for this gist", "public": True, "files": { "logfile.txt": { "content": content } } } r = session.post(url, json.dumps(gist)) if r.status_code == 201: logger.success('Successfully created gist') else: logger.warning('Could not create gist') logger.log(r.content, 'Response:') return r.json()['url'], r.json()['html_url'] except: logger.error(sys.exc_info()[0], "git_issuer gist") logger.error(traceback.format_exc())
def setup(args): logger.log("Setting up PlebNet") # Prepare Cloudomate if args.test_net: settings.wallets_testnet("1") settings.settings.write() fake_generator.generate_child_account() # TODO: change --> Prepare plebnet config = PlebNetConfig() config.set('expiration_date', time.time() + 30 * plebnet_settings.TIME_IN_DAY) config.save() # handle the DNA dna = DNA() dna.read_dictionary(cloudomate_controller.get_vps_providers()) dna.write_dictionary() # Prepare the IRC Client irc_handler.init_irc_client() irc_handler.start_irc_client() logger.success("PlebNet is ready to roll!")
def create_gist(filename=None): """ This method can be used to send a file to github via gist. :param filename: the file to send, if left empty, the log file is send :type filename: String """ # Only execute if PlebNet is activated settings = plebnet_settings.get_instance() if not settings.github_active(): return if not filename: filename = settings.logger_file() try: # Collect variables username = settings.github_username() password = settings.github_password() bot_name = settings.irc_nick() # Get the log files content = open(filename, 'r').read() # Our url to create issues via POST url = 'https://api.github.com/gists' # Create an authenticated session to create the issue session = requests.Session() session.auth = (username, password) # Create our issue gist = { "description": "The logfile for %s" % bot_name, "public": True, "files": { "logfile.txt": { "content": content } } } r = session.post(url, json.dumps(gist)) # Inform about the results if r.status_code == 201: logger.success('Successfully created gist') else: logger.warning('Could not create gist') logger.log(r.content, 'Response:') return r.json()['url'], r.json()['html_url'] except: logger.error(sys.exc_info()[0], "git_issuer gist") logger.error(traceback.format_exc()) return None, None
def setup(args): """ This method should only be called once and is responsible for the initial setup of the PlebNet agent. All necessary configuration files are created and IRC communication is started. :param args: If running in Testnet mode. """ global qtable, config logger.log("Setting up PlebNet") # Set general info about the PlebNet agent settings.irc_nick(settings.irc_nick_def() + str(random.randint(1000, 10000))) config = PlebNetConfig() config.set('expiration_date', time.time() + TIME_ALIVE) # Prepare the QTable configuration qtable = QTable() if args.test_net: settings.wallets_testnet("1") qtable.read_dictionary({ 'proxhost': cloudomate_controller.get_vps_providers()['proxhost'] }) else: providers = cloudomate_controller.get_vps_providers() if providers.has_key('proxhost'): del providers["proxhost"] # Create QTable if it does not exist qtable.read_dictionary(providers) if args.exit_node: logger.log("Running as exitnode") settings.tribler_exitnode('1') settings.settings.write() # Prepare first child configuration fake_generator.generate_child_account() # Prepare the IRC Client irc_handler.init_irc_client() irc_handler.start_irc_client() config.save() # add learning_consumer as a consumer for qtable channel in addressbook qtable.address_book.receiver.register_consumer("qtable", learning_consumer) logger.success("PlebNet is ready to roll!")
def setup(args): """ This method should only be called once and is responsible for the initial setup of the PlebNet agent. All necessary configuration files are created and IRC communication is started. :param args: If running in Testnet mode. """ global dna, config logger.log("Setting up PlebNet") # Prepare the DNA configuration dna = DNA() if args.test_net: settings.wallets_testnet("1") settings.settings.write() dna.read_dictionary({ 'proxhost': cloudomate_controller.get_vps_providers()['proxhost'] }) else: dna.read_dictionary(cloudomate_controller.get_vps_providers()) if 'proxhost' in dna.vps.keys(): dna.remove_provider('proxhost') dna.write_dictionary() if args.exit_node: logger.log("Running as exitnode") settings.tribler_exitnode('1') # Prepare first child configuration fake_generator.generate_child_account() # Set general info about the PlebNet agent settings.irc_nick(settings.irc_nick_def() + str(random.randint(1000, 10000))) config = PlebNetConfig() config.set('expiration_date', time.time() + 30 * plebnet_settings.TIME_IN_DAY) # Prepare the IRC Client irc_handler.init_irc_client() irc_handler.start_irc_client() if dna.get_own_tree() == '': logger.log("tree set to %s" % settings.irc_nick()) dna.set_own_tree(settings.irc_nick()) config.save() logger.success("PlebNet is ready to roll!")
def test_add_multiple_logs(self): logger.log(msg1) logger.warning(msg2) logger.success(msg3) logger.error(msg4) f = open(logfile) for line in f: if msg1 in line: self.assertTrue("INFO" in line) if msg2 in line: self.assertTrue("WARNING" in line) if msg3 in line: self.assertTrue("INFO" in line) if msg4 in line: self.assertTrue("ERROR" in line)
def attempt_purchase_vpn(): """ Attempts to purchase a VPN, checks first if balance is sufficient The success message is stored to prevent further unecessary purchases. """ provider = settings.vpn_host() if settings.wallets_testnet(): domain = 'TBTC' else: domain = 'BTC' if market_controller.get_balance( domain) >= cloudomate_controller.calculate_price_vpn(provider): logger.log("Try to buy a new VPN from %s" % provider, log_name) success = cloudomate_controller.purchase_choice_vpn(config) if success == plebnet_settings.SUCCESS: logger.success("Purchasing VPN succesful!", log_name) elif success == plebnet_settings.FAILURE: logger.error("Error purchasing vpn", log_name)
def create_issue(title, body, labels): """ This method creates a github issue when called. :param title: The title of the issue :type title: String :param body: The body text of the issue :type body: String :param labels: The labels which should be attached to the issue :type labels: String[] """ # Only execute if PlebNet is activated settings = plebnet_settings.get_instance() if not settings.github_active(): return try: # Collect variables username = settings.github_username() password = settings.github_password() repo_owner = settings.github_owner() repo_name = settings.github_repo() # Our url to create issues via POST url = 'https://api.github.com/repos/%s/%s/issues' % (repo_owner, repo_name) # Create an authenticated session to create the issue session = requests.Session() session.auth = (username, password) # Create our issue issue = {'title': title, 'body': body, 'labels': labels} # Add the issue to our repository r = session.post(url, json.dumps(issue)) # Inform about the results if r.status_code == 201: logger.success('Successfully created Issue "%s"' % title) else: logger.warning('Could not create Issue "%s"' % title) logger.log(r.content, 'Response:') except: logger.error(sys.exc_info()[0], "git_issuer send") logger.error(traceback.format_exc())
def create_issue(username, password, repo_owner, repo_name, title, body, labels): try: # Our url to create issues via POST url = 'https://api.github.com/repos/%s/%s/issues' % (repo_owner, repo_name) # Create an authenticated session to create the issue session = requests.Session() session.auth = (username, password) # Create our issue issue = {'title': title, 'body': body, 'labels': labels} # Add the issue to our repository r = session.post(url, json.dumps(issue)) if r.status_code == 201: logger.success('Successfully created Issue "%s"' % title) else: logger.warning('Could not create Issue "%s"' % title) logger.log(r.content, 'Response:') except: logger.error(sys.exc_info()[0], "git_issuer send") logger.error(traceback.format_exc())
def start(): """ Starts Tribler by using the twistd plugin. :return: boolean representing the success of starting Tribler """ env = os.environ.copy() # env['PYTHONPATH'] = os.path.join(setup.plebnet_home(), 'plebnet') + ":" # #env['PYTHONPATH'] += os.path.join(setup.plebnet_home(), 'plebnet/twisted/plugins') + ":" # env['PYTHONPATH'] += os.path.join(setup.plebnet_home(), 'tribler/src/pyipv8') + ":" # env['PYTHONPATH'] += os.path.join(setup.plebnet_home(), 'tribler/src/anydex') + ":" # env['PYTHONPATH'] += os.path.join(setup.plebnet_home(), 'tribler/src/tribler-common') + ":" # env['PYTHONPATH'] += os.path.join(setup.plebnet_home(), 'tribler/src/tribler-core') #print(env['PYTHONPATH']) command = ['systemctl', 'start', 'tribler.service'] # if setup.wallets_testnet(): # command.append('--testnet') # if setup.tribler_exitnode(): command.append('*****@*****.**') else: command.append('*****@*****.**') try: exitcode = subprocess.call(command, cwd=os.path.join(setup.plebnet_home(), 'plebnet'), env=env) print("Exitcode was: " + str(exitcode)) if exitcode != 0: logger.error('Failed to start Tribler', "tribler_controller") return False logger.success('Tribler is started', "tribler_controller") logger.log('testnet: ' + str(setup.wallets_testnet())) return True except subprocess.CalledProcessError as e: logger.error(e.output, "tribler_controller") return False