<commit_before>"""
The dummy connection is a virtual printer connection which simulates the connection to a printer without doing anything.
This is only enabled when you have a development version. And is used for debugging.
"""
__copyright__ = "Copyright (C) 2013 <NAME> - Released under terms of the AGPLv3 License"

import threading
import json
import httplib as httpclient
import urllib
import time

from Cura.util.printerConnection import printerConnectionBase

class dummyConnectionGroup(printerConnectionBase.printerConnectionGroup):
	"""
	Group used for dummy conections. Always shows 2 dummy connections for debugging.
	Has a very low priority so it does not prevent other connections from taking priority.
	"""
	def __init__(self):
		super(dummyConnectionGroup, self).__init__("Dummy")
		self._list = [dummyConnection("Dummy 1"), dummyConnection("Dummy 2")]

	def getAvailableConnections(self):
		return self._list

	def getIconID(self):
		return 5

	def getPriority(self):
		return -100

class dummyConnection(printerConnectionBase.printerConnectionBase):
	"""
	A dummy printer class to debug printer windows.
	"""
	def __init__(self, name):
		super(dummyConnection, self).__init__(name)

		self._printing = False
		self._lineCount = 0
		self._progressLine = 0

		self.printThread = threading.Thread(target=self._dummyThread)
		self.printThread.daemon = True
		self.printThread.start()

	#Load the data into memory for printing, returns True on success
	def loadGCodeData(self, dataStream):
		if self._printing:
			return False
		self._lineCount = 0
		for line in dataStream:
			#Strip out comments, we do not need to send comments
			if ';' in line:
				line = line[:line.index(';')]
			#Strip out whitespace at the beginning/end this saves data to send.
			line = line.strip()

			if len(line) < 1:
				continue
			self._lineCount += 1
		self._doCallback()
		return True

	#Start printing the previously loaded file
	def startPrint(self):
		print 'startPrint', self._printing, self._lineCount
		if self._printing or self._lineCount < 1:
			return
		self._progressLine = 0
		self._printing = True

	#Abort the previously loaded print file
	def cancelPrint(self):
		self._printing = False

	def isPrinting(self):
		return self._printing

	#Amount of progression of the current print file. 0.0 to 1.0
	def getPrintProgress(self):
		if self._lineCount < 1:
			return 0.0
		return float(self._progressLine) / float(self._lineCount)

	# Return if the printer with this connection type is available
	def isAvailable(self):
		return True

	# Get the connection status string. This is displayed to the user and can be used to communicate
	#  various information to the user.
	def getStatusString(self):
		return "DUMMY!:%i %i:%i" % (self._progressLine, self._lineCount, self._printing)

	def _dummyThread(self):
		while True:
			if not self._printing:
				time.sleep(5)
				self._doCallback()
			else:
				time.sleep(0.01)
				self._progressLine += 1
				if self._progressLine == self._lineCount:
					self._printing = False
				self._doCallback()
<commit_msg>Add debugging stubs to DummyConnection<commit_after>"""
The dummy connection is a virtual printer connection which simulates the connection to a printer without doing anything.
This is only enabled when you have a development version. And is used for debugging.
"""
__copyright__ = "Copyright (C) 2013 <NAME> - Released under terms of the AGPLv3 License"

import threading
import json
import httplib as httpclient
import urllib
import time

from Cura.util.printerConnection import printerConnectionBase

class dummyConnectionGroup(printerConnectionBase.printerConnectionGroup):
	"""
	Group used for dummy conections. Always shows 2 dummy connections for debugging.
	Has a very low priority so it does not prevent other connections from taking priority.
	"""
	def __init__(self):
		super(dummyConnectionGroup, self).__init__("Dummy")
		self._list = [dummyConnection("Dummy 1"), dummyConnection("Dummy 2")]

	def getAvailableConnections(self):
		return self._list

	def getIconID(self):
		return 5

	def getPriority(self):
		return -100

class dummyConnection(printerConnectionBase.printerConnectionBase):
	"""
	A dummy printer class to debug printer windows.
	"""
	def __init__(self, name):
		super(dummyConnection, self).__init__(name)

		self._printing = False
		self._lineCount = 0
		self._progressLine = 0

		self.printThread = threading.Thread(target=self._dummyThread)
		self.printThread.daemon = True
		self.printThread.start()

	#Load the data into memory for printing, returns True on success
	def loadGCodeData(self, dataStream):
		if self._printing:
			return False
		self._lineCount = 0
		for line in dataStream:
			#Strip out comments, we do not need to send comments
			if ';' in line:
				line = line[:line.index(';')]
			#Strip out whitespace at the beginning/end this saves data to send.
			line = line.strip()

			if len(line) < 1:
				continue
			self._lineCount += 1
		self._doCallback()
		return True

	#Start printing the previously loaded file
	def startPrint(self):
		print 'startPrint', self._printing, self._lineCount
		if self._printing or self._lineCount < 1:
			return
		self._progressLine = 0
		self._printing = True

	#Abort the previously loaded print file
	def cancelPrint(self):
		self._printing = False

	def isPrinting(self):
		return self._printing

	#Amount of progression of the current print file. 0.0 to 1.0
	def getPrintProgress(self):
		if self._lineCount < 1:
			return 0.0
		return float(self._progressLine) / float(self._lineCount)

	# Return if the printer with this connection type is available
	def isAvailable(self):
		return True

	# Get the connection status string. This is displayed to the user and can be used to communicate
	#  various information to the user.
	def getStatusString(self):
		return "DUMMY!:%i %i:%i" % (self._progressLine, self._lineCount, self._printing)
	
	def coolDown(self):
		pass

	def disableSteppers(self):
		pass

	def _dummyThread(self):
		while True:
			if not self._printing:
				time.sleep(5)
				self._doCallback()
			else:
				time.sleep(0.01)
				self._progressLine += 1
				if self._progressLine == self._lineCount:
					self._printing = False
				self._doCallback()

{'fraction_non_alphanumeric': 0.08393632416787265, 'fraction_numerical': 0.009969448464383341, 'mean_word_length': 4.191986644407345, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5822390', 'n_tokens_mistral': 2052, 'n_tokens_neox': 1814, 'n_words': 648}