Esempio n. 1
0
class Controller:
    '''
    Instanciate the app components and
    control the rep loop
    :seqdiag_note Entry point of the business layer
    '''
    def __init__(self, printer, configMgr):
        if os.name == 'posix':
            FILE_PATH = '/sdcard/cryptopricer.ini'
        else:
            FILE_PATH = 'c:\\temp\\cryptopricer.ini'

        self.configMgr = configMgr
        self.priceRequester = PriceRequester()
        self.crypCompTranslator = CrypCompExchanges()
        self.processor = Processor(self.configMgr, self.priceRequester, self.crypCompTranslator)
        self.requester = Requester(self.configMgr)

        self.commandPrice = CommandPrice(self.processor, self.configMgr)
        self.commandCrypto = CommandCrypto(self.processor)
        self.requester.commandPrice = self.commandPrice
        self.requester.commandCrypto = self.commandCrypto

        self.commandQuit = CommandQuit(sys)
        self.requester.commandQuit = self.commandQuit

        self.commandError = CommandError(None)
        self.requester.commandError = self.commandError

        self.printer = printer
        

    def run(self):
        '''
        Used essentially by the command line version of CryptoPricer.

        :return: nothing
        '''
        while True:
            command = self.requester.request()
            result = command.execute()

            if result != '':
                strToPrint = self.printer.getPrintableData(result)
                print(strToPrint)


    def getPrintableResultForInput(self, inputStr):
        '''
        Return the printable request result, the full request command without any command option and
        the full request command with any specified save mode option (option which is to be saved in the
        command history list.

        :param inputStr:
        :seqdiag_return printResult, fullCommandStr, fullCommandStrWithOptions, fullCommandStrWithSaveModeOptions
        :return: 1/ printable request result
                 2/ full request command without any command option
                 3/ full request command with any non save command option
                 4/ full request command with any specified save mode option, None if no save mode option
                    is in effect

                 Ex: 1/ 0.1 ETH/36 USD on Bitfinex: 21/11/17 10:00 360
                     2/ eth usd 0 bitfinex
                     3/ None (value command with save mode in effect !)
                     4/ eth usd 0 bitfinex -vs0.1eth

                     1/ 0.1 ETH/36 USD on Bitfinex: 21/11/17 10:00 360
                     2/ eth usd 0 bitfinex
                     3/ eth usd 0 bitfinex -v0.1eth
                     4/ None (no value command save option in effect)

                     1/ ETH/USD on Bitfinex: 21/11/17 10:00 360
                     2/ eth usd 0 bitfinex
                     3/ None (no value command in effect)
                     4/ None (no value command save option in effect)
        '''
        command = self.requester.getCommand(inputStr)
        result = command.execute()

        if result != '':
            printResult = self.printer.getPrintableData(result)
            fullCommandStr, fullCommandStrWithOptions, fullCommandStrWithSaveModeOptions = self.printer.getFullCommandString(result)
            
            return printResult, fullCommandStr, fullCommandStrWithOptions, fullCommandStrWithSaveModeOptions
Esempio n. 2
0
class Controller:
	"""
	Instanciate the app components and
	control the rep loop.
	
	:seqdiag_note Client in the GOF Command pattern. Entry point of the business layer. Instanciates the business layer classes.
	"""
	def __init__(self, printer, configMgr, priceRequester):
		self.configMgr = configMgr
		self.priceRequester = priceRequester
		self.crypCompTranslator = CrypCompExchanges()
		self.processor = Processor(self.configMgr, self.priceRequester, self.crypCompTranslator)
		self.requester = Requester(self.configMgr)

		self.commandPrice = CommandPrice(self.processor, self.configMgr)
		self.commandCrypto = CommandCrypto(self.processor)
		self.requester.commandPrice = self.commandPrice
		self.requester.commandCrypto = self.commandCrypto

		self.commandQuit = CommandQuit(sys)
		self.requester.commandQuit = self.commandQuit

		self.commandError = CommandError(None)
		self.requester.commandError = self.commandError

		self.printer = printer
		

	def commandLineLoop(self):
		"""
		Used essentially by the command line version of CryptoPricer.
		"""
		while True:
			command = self.requester.getCommandFromCommandLine()
			result = command.execute()

			if result != '':
				strToPrint = self.printer.getCommandOutputResult(result)
				print(strToPrint)


	def getPrintableResultForInput(self, inputStr):
		'''
		Return the printable request result, the full request command without any command option,
		the full request command with any specified NON save mode option (information used by
		the GUI to define the status bar content, which differs according to the type of the
		request, full or partial and finally the full request command with any specified save
		mode option (option which is to be saved in the	command history list. A detailed
		explanation of the usefulness of the returned values is availablein the
		GuiOutputFormatter.getFullCommandString(( method documentation.

		:param inputStr:
		:seqdiag_return printResult, fullCommandStrNoOptions, fullCommandStrWithNoSaveOptions, fullCommandStrWithSaveOptionsForHistoryList, fullCommandStrForStatusBar

		:return: 1/ printable request result
				 2/ full request command without any command option
				 3/ full request command with any non save command option(s)
				 4/ full request command with any specified save mode option(s), None if no save mode option
					is in effect
				 5/ full command string for status bar

				 Ex: 1/ 0.1 ETH/36 USD on Bitfinex: 21/11/17 10:00 360
					 2/ eth usd 0 bitfinex
					 3/ None (one command option with save mode in effect !)
					 4/ eth usd 0 bitfinex -vs0.1eth

					 1/ 0.1 ETH/36 USD on Bitfinex: 21/11/17 10:00 360
					 2/ eth usd 0 bitfinex
					 3/ eth usd 0 bitfinex -v0.1eth
					 4/ None (no command save option in effect)

					 1/ ETH/USD on Bitfinex: 21/11/17 10:00 360
					 2/ eth usd 0 bitfinex
					 3/ None (no command option in effect)
					 4/ None (no command save option in effect)
		'''
		command = self.requester.getCommand(inputStr)
		resultData = command.execute()

		if resultData != '':
			commandOutputResult = self.printer.getCommandOutputResult(resultData)
			
			fullCommandStrNoOptions, \
			fullCommandStrWithNoSaveOptions, \
			fullCommandStrWithSaveOptionsForHistoryList, \
			fullCommandStrForStatusBar = self.printer.getFullCommandString(resultData)
			
			return commandOutputResult, fullCommandStrNoOptions, fullCommandStrWithNoSaveOptions, fullCommandStrWithSaveOptionsForHistoryList, fullCommandStrForStatusBar