def __init__(self, **kwargs): global fromAppBuilt if not fromAppBuilt: return super(CryptoPricerGUI, self).__init__(**kwargs) self.dropDownMenu = CustomDropDown(owner=self) if os.name == 'posix': configPath = '/sdcard/cryptopricer.ini' else: configPath = 'c:\\temp\\cryptopricer.ini' self.toggleAppSizeButton.text = 'Half' # correct on Windows version ! self.configMgr = ConfigurationManager(configPath) self.controller = Controller(GuiOutputFormater(self.configMgr, activateClipboard=True), self.configMgr) self.dataPath = self.configMgr.dataPath self.histoListItemHeight = int(self.configMgr.histoListItemHeight) self.histoListMaxVisibleItems = int(self.configMgr.histoListVisibleSize) self.maxHistoListHeight = self.histoListMaxVisibleItems * self.histoListItemHeight self.appSize = self.configMgr.appSize self.defaultAppPosAndSize = self.configMgr.appSize self.appSizeHalfProportion = float(self.configMgr.appSizeHalfProportion) self.applyAppPosAndSize() # loading the load at start history file if defined pathFilename = self.configMgr.loadAtStartPathFilename if pathFilename != '': self.loadPathFilename(pathFilename)
class TestConfigurationManager(unittest.TestCase): def setUp(self): self.cm = ConfigurationManager() def testReadConnections(self): self.cm.read_config('settings-test.py') self.assertEquals(len(self.cm.list_connections()), 2) for conn in self.cm.list_connections(): assert(conn.has_key('endpoint')) assert(conn.has_key('channels'))
def setUp(self): if os.name == 'posix': FILE_PATH = '/sdcard/cryptopricer.ini' else: FILE_PATH = 'c:\\temp\\cryptopricer.ini' self.configMgr = ConfigurationManager(FILE_PATH) self.priceRequester = PriceRequester()
def setUp(self): if os.name == 'posix': FILE_PATH = '/sdcard/cryptopricer.ini' else: FILE_PATH = 'c:\\temp\\cryptopricer.ini' configMgr = ConfigurationManager(FILE_PATH) self.printer = GuiOutputFormater(configMgr)
def setUp(self): if os.name == 'posix': FILE_PATH = '/sdcard/cryptopricer.ini' else: FILE_PATH = 'c:\\temp\\cryptopricer.ini' self.configMgr = ConfigurationManager(FILE_PATH) self.priceRequester = PriceRequester() self.crypCompExchanges = CrypCompExchanges() self.processor = Processor(self.configMgr, self.priceRequester, self.crypCompExchanges)
class Dickler(object): def __init__(self, configuration): self.identity = None self.configuration = configuration self.connections = set([]) self.configmanager = ConfigurationManager() def connect(self): if not self.configmanager.read_config(self.configuration): return False for conn in self.configmanager.list_connections(): c = IRCConnection(conn, self.configmanager.get_identity()) #for plugin, conf in self.configmanager.list_plugins(): #c.msg_handler.register_plugin(plugin.create_plugin(c, conf)) self.connections.add(c) for conn in self.connections: conn.make_connection() conn.start() return True
def main(): ''' Maincl means main command line ! Command line main which instanciate a Controller which uses a ConsoleOutputFormatter instead of a GuiOutputFormatter, what maingui does ! ''' if os.name == 'posix': configPath = '/sdcard/cryptopricer.ini' else: configPath = 'c:\\temp\\cryptopricer.ini' configMgr = ConfigurationManager(configPath) controller = Controller(ConsoleOutputFormatter(configMgr), configMgr, PriceRequester()) controller.commandLineLoop()
def testConfigurationManagerInstanciation(self): self.configMgr = ConfigurationManager(self.filePath) self.assertEqual(self.configMgr.localTimeZone, 'Europe/Zurich') self.assertEqual(self.configMgr.dateTimeFormat, 'DD/MM/YY HH:mm') self.assertEqual(self.configMgr.dateOnlyFormat, 'DD/MM/YY') if os.name == 'posix': self.assertEqual(self.configMgr.dataPath, '/sdcard/CryptoPricerData') self.assertEqual(self.configMgr.appSize, 'Half') self.assertEqual(self.configMgr.histoListItemHeight, '90') else: self.assertEqual(self.configMgr.dataPath, 'c:\\temp') self.assertEqual(self.configMgr.appSize, 'Full') self.assertEqual(self.configMgr.histoListItemHeight, '35') self.assertEqual(self.configMgr.loadAtStartPathFilename, '') self.assertEqual(self.configMgr.histoListVisibleSize, '3') self.assertEqual(self.configMgr.appSizeHalfProportion, '0.62') self.assertEqual(self.configMgr.referenceCurrency, 'USD')
def testWithSlash(self): from configurationmanager import ConfigurationManager from guioutputformater import GuiOutputFormater from controller import Controller import os SeqDiagBuilder.activate('Controller', 'getPrintableResultForInput') # activate sequence diagram building if os.name == 'posix': FILE_PATH = '/sdcard/cryptopricer.ini' else: FILE_PATH = 'c:\\temp\\cryptopricer.ini' configMgr = ConfigurationManager(FILE_PATH) controller = Controller(GuiOutputFormater(configMgr), configMgr) inputStr = 'mcap btc 0 all' _, _, _, _ = controller.getPrintableResultForInput( inputStr) SeqDiagBuilder.createDiagram('c:/temp', 'GUI', None, 20)
def testConfigurationManagerInstanciationOneMissingKey(self): #removing second line in config file with open(self.filePath, 'r') as configFile: lines = configFile.readlines() with open(self.filePath, 'w') as configFile: # first line contains [General] section name ! configFile.write(''.join(lines[0:1] + lines[2:])) self.configMgr = ConfigurationManager(self.filePath) self.assertEqual(self.configMgr.localTimeZone, 'Europe/Zurich') self.assertEqual(self.configMgr.dateTimeFormat, 'DD/MM/YY HH:mm') self.assertEqual(self.configMgr.dateOnlyFormat, 'DD/MM/YY') if os.name == 'posix': self.assertEqual(self.configMgr.dataPath, '/sdcard/CryptoPricerData') else: self.assertEqual(self.configMgr.dataPath, 'c:\\temp') self.assertEqual(self.configMgr.loadAtStartPathFilename, '') self.assertEqual(self.configMgr.histoListVisibleSize, '3') self.assertEqual(self.configMgr.appSizeHalfProportion, '0.62') self.assertEqual(self.configMgr.referenceCurrency, 'USD')
self.parsedParmData[self.MINUTE] = str(localNow.minute) if __name__ == '__main__': from configurationmanager import ConfigurationManager from pricerequester import PriceRequester from crypcompexchanges import CrypCompExchanges from processor import Processor import os if os.name == 'posix': FILE_PATH = '/sdcard/cryptopricer.ini' else: FILE_PATH = 'c:\\temp\\cryptopricer.ini' cm = ConfigurationManager(FILE_PATH) pr = PriceRequester() cryp = CrypCompExchanges() proc = Processor(cm, pr, cryp) cpr = CommandPrice(proc, cm) print('HISTORICAL') cpr.parsedParmData[cpr.CRYPTO] = 'btc' cpr.parsedParmData[cpr.FIAT] = 'usd' cpr.parsedParmData[cpr.EXCHANGE] = 'bittrex' cpr.parsedParmData[cpr.DAY] = '12' cpr.parsedParmData[cpr.MONTH] = '9' cpr.parsedParmData[cpr.YEAR] = '2017' cpr.parsedParmData[cpr.HOUR] = '10'
COMMAND_ERROR_TYPE_KEY] = self.commandError.COMMAND_ERROR_TYPE_INVALID_COMMAND self.commandError.parsedParmData[ self.commandError. COMMAND_ERROR_MSG_KEY] = self.commandError.FIAT_LIST_MISSING_MSG return self.commandError, fiatDataList, flag else: return cryptoDataList, fiatDataList, flag if __name__ == '__main__': from configurationmanager import ConfigurationManager import os filePath = None if os.name == 'posix': filePath = '/sdcard/cryptopricer_test.ini' else: filePath = 'c:\\temp\\cryptopricer_test.ini' r = Requester(ConfigurationManager(filePath)) r.commandPrice = CommandPrice() inputStr = "btc usd Kraken 10/9/17 12:45" # groupL = r._parseGroups(r.PATTERN_FULL_PRICE_REQUEST_WITH_OPTIONAL_COMMAND_DATA, inputStr) # print(groupL) # print(r._validateFullCommandPriceParsedGroupsOrder(groupL)) print(r.getCommand(inputStr))
def setUp(self): self.cm = ConfigurationManager()
class CryptoPricerGUI(BoxLayout): requestInput = ObjectProperty() requestList = ObjectProperty() resultOutput = ObjectProperty() statusBar = ObjectProperty() showRequestList = False def __init__(self, **kwargs): global fromAppBuilt if not fromAppBuilt: return super(CryptoPricerGUI, self).__init__(**kwargs) self.dropDownMenu = CustomDropDown(owner=self) if os.name == 'posix': configPath = '/sdcard/cryptopricer.ini' else: configPath = 'c:\\temp\\cryptopricer.ini' self.toggleAppSizeButton.text = 'Half' # correct on Windows version ! self.configMgr = ConfigurationManager(configPath) self.controller = Controller(GuiOutputFormater(self.configMgr, activateClipboard=True), self.configMgr) self.dataPath = self.configMgr.dataPath self.histoListItemHeight = int(self.configMgr.histoListItemHeight) self.histoListMaxVisibleItems = int(self.configMgr.histoListVisibleSize) self.maxHistoListHeight = self.histoListMaxVisibleItems * self.histoListItemHeight self.appSize = self.configMgr.appSize self.defaultAppPosAndSize = self.configMgr.appSize self.appSizeHalfProportion = float(self.configMgr.appSizeHalfProportion) self.applyAppPosAndSize() # loading the load at start history file if defined pathFilename = self.configMgr.loadAtStartPathFilename if pathFilename != '': self.loadPathFilename(pathFilename) def toggleAppPosAndSize(self): if self.appSize == self.configMgr.APP_SIZE_HALF: self.appSize = self.configMgr.APP_SIZE_FULL if self.defaultAppPosAndSize == self.configMgr.APP_SIZE_FULL: # on the smartphone, we do not want to reposition the cursor ob # the input field since this would display the keyboard ! self.refocusOnRequestInput() else: self.appSize = self.configMgr.APP_SIZE_HALF # the case on the smartphone. Here, positioning the cursor on # the input field after having pressed the 'half' button # automatically displays the keyboard self.refocusOnRequestInput() self.applyAppPosAndSize() def applyAppPosAndSize(self): if self.appSize == self.configMgr.APP_SIZE_HALF: sizeHintY = float(self.appSizeHalfProportion) self.size_hint_y = sizeHintY self.pos_hint = {'x': 0, 'y': 1 - sizeHintY} self.toggleAppSizeButton.text = 'Full' else: self.size_hint_y = 1 self.pos_hint = {'x': 0, 'y': 0} self.toggleAppSizeButton.text = 'Half' def toggleRequestList(self): ''' called by 'History' toggle button to toggle the display of the history request list. ''' if self.showRequestList: self.requestList.size_hint_y = None self.requestList.height = '0dp' self.disableRequestListItemButtons() self.showRequestList = False else: listItemNumber = len(self.requestList.adapter.data) self.requestList.height = min(listItemNumber * self.histoListItemHeight, self.maxHistoListHeight) self.showRequestList = True self.resetListViewScrollToEnd() self.refocusOnRequestInput() def submitRequest(self): ''' Submit the request, output the result and add the request to the request list :return: ''' # Get the request from the TextInput requestStr = self.requestInput.text self.updateStatusBar(requestStr) # purpose of the informations obtained from the business layer: # outputResultStr - for the output text zone # fullRequestStr - for the request history list # fullRequestStrWithOptions - for the status bar # fullRequestStrWithSaveModeOptions - for the request history list outputResultStr, fullRequestStr, fullRequestStrWithOptions, fullRequestStrWithSaveModeOptions = self.controller.getPrintableResultForInput( requestStr) self.outputResult(outputResultStr) if fullRequestStrWithSaveModeOptions != None: if fullRequestStr in self.requestList.adapter.data: # if the full request string corresponding to the full request string with options is already # in the history list, it is removed before the full request string with options is added # to the list. Otherwise, this would engender a duplicate ! self.requestList.adapter.data.remove(fullRequestStr) if not fullRequestStrWithSaveModeOptions in self.requestList.adapter.data: self.requestList.adapter.data.extend([fullRequestStrWithSaveModeOptions]) # Reset the ListView self.resetListViewScrollToEnd() elif fullRequestStr != '' and not fullRequestStr in self.requestList.adapter.data: # Add the full request to the ListView if not already in self.requestList.adapter.data.extend([fullRequestStr]) # if an identical full request string with options is in the history, it is not # removed automatically. If the user wants to get rid of it, he must do it exolicitely # using the delete button ! # Reset the ListView self.resetListViewScrollToEnd() self.manageStateOfRequestListButtons() self.requestInput.text = '' # displaying request and result in status bar if 'ERROR' in outputResultStr: if requestStr == '': self.updateStatusBar('REPLAY --> ' + outputResultStr) elif requestStr: self.updateStatusBar(requestStr + ' --> ' + outputResultStr) else: if fullRequestStrWithSaveModeOptions: if requestStr == '': self.updateStatusBar('REPLAY --> ' + fullRequestStrWithSaveModeOptions) elif requestStr: self.updateStatusBar(requestStr + ' --> ' + fullRequestStrWithSaveModeOptions) else: if not fullRequestStrWithOptions: fullRequestStrWithOptions = fullRequestStr if requestStr == '': self.updateStatusBar('REPLAY --> ' + fullRequestStrWithOptions) elif requestStr: self.updateStatusBar(requestStr + ' --> ' + fullRequestStrWithOptions) self.refocusOnRequestInput() def clearOutput(self): self.resultOutput.text = '' self.statusBar.text = '' self.clearResultOutputButton.disabled = True self.refocusOnRequestInput() def resetListViewScrollToEnd(self): listView = self.requestList maxVisibleItemNumber = self.histoListMaxVisibleItems listLength = len(listView.adapter.data) if listLength > maxVisibleItemNumber: listView.scroll_to(listLength - maxVisibleItemNumber) else: listView.scroll_to(0) listView._trigger_reset_populate() def manageStateOfRequestListButtons(self): ''' Enable or disable history request list related controls according to the status of the list: filled with items or empty. :return: ''' if len(self.requestList.adapter.data) == 0: # request list is empty self.toggleHistoButton.state = 'normal' self.toggleHistoButton.disabled = True self.replayAllButton.disabled = True self.requestList.height = '0dp' self.dropDownMenu.saveButton.disabled = True else: self.toggleHistoButton.disabled = False self.replayAllButton.disabled = False self.dropDownMenu.saveButton.disabled = False def outputResult(self, resultStr): if len(self.resultOutput.text) == 0: self.resultOutput.text = resultStr else: self.resultOutput.text = self.resultOutput.text + '\n' + resultStr # self.outputResultScrollView.scroll_to(100000) # self.resultOutput.cursor = (10000,0) self.clearResultOutputButton.disabled = False def refocusOnRequestInput(self): # defining a delay of 0.1 sec ensure the # refocus works in all situations. Leaving # it empty (== next frame) does not work # when pressing a button ! Clock.schedule_once(self._refocusTextInput, 0.1) def _refocusTextInput(self, *args): ''' This method is here to be used as callback by Clock and must not be called directly :param args: :return: ''' self.requestInput.focus = True def deleteRequest(self, *args): # If a list item is selected if self.requestList.adapter.selection: # Get the text from the item selected selection = self.requestList.adapter.selection[0].text # Remove the matching item self.requestList.adapter.data.remove(selection) # Reset the ListView self.resetListViewScrollToEnd() self.requestInput.text = '' self.disableRequestListItemButtons() self.manageStateOfRequestListButtons() self.refocusOnRequestInput() def replaceRequest(self, *args): # If a list item is selected if self.requestList.adapter.selection: # Get the text from the item selected selection = self.requestList.adapter.selection[0].text # Remove the matching item self.requestList.adapter.data.remove(selection) # Get the request from the TextInputs requestStr = self.requestInput.text # Add the updated data to the list if not already in if not requestStr in self.requestList.adapter.data: self.requestList.adapter.data.extend([requestStr]) # Reset the ListView self.requestList._trigger_reset_populate() self.requestInput.text = '' self.disableRequestListItemButtons() self.refocusOnRequestInput() def historyItemSelected(self, instance): requestStr = str(instance.text) # counter-intuitive, but test must be defined that way ! if instance.is_selected: # disabling the 2 history request list item related buttons self.disableRequestListItemButtons() else: self.enableRequestListItemButtons() self.requestInput.text = requestStr self.refocusOnRequestInput() self.dropDownMenu.saveButton.disabled = False def enableRequestListItemButtons(self): self.deleteButton.disabled = False self.replaceButton.disabled = False def disableRequestListItemButtons(self): self.deleteButton.disabled = True self.replaceButton.disabled = True def replayAllRequests(self): # output blank line self.outputResult('') for request in self.requestList.adapter.data: outputResultStr, fullRequestStr, fullRequestStrWithOptions, fullRequestStrWithSaveModeOptions = self.controller.getPrintableResultForInput( request) self.outputResult(outputResultStr) # self.resultOutput.do_cursor_movement('cursor_pgdown') self.refocusOnRequestInput() def openDropDownMenu(self, widget): self.dropDownMenu.open(widget) def displayHelp(self): self.dropDownMenu.dismiss() popup = Popup(title='CryptoPricer', content=Label(text='Version 2.1'), size_hint=(None, None), size=(400, 400)) popup.open() def updateStatusBar(self, messageStr): self.statusBar.text = messageStr # --- file chooser code --- def getStartPath(self): return "D:\\Users\\Jean-Pierre" def dismissPopup(self): ''' Act as a call back function for the cancel button of the load and save dialog :return: nothing ''' self.updateStatusBar('') self.popup.dismiss() def openLoadHistoryFileChooser(self): fileChooserDialog = LoadDialog(load=self.load, cancel=self.dismissPopup) fileChooserDialog.fileChooser.rootpath = self.dataPath self.popup = Popup(title="Load file", content=fileChooserDialog, size_hint=(0.9, 0.6), pos_hint={'center': 1, 'top': 1}) self.popup.open() self.dropDownMenu.dismiss() def openSaveHistoryFileChooser(self): fileChooserDialog = SaveDialog(save=self.save, cancel=self.dismissPopup) fileChooserDialog.owner = self fileChooserDialog.fileChooser.rootpath = self.dataPath self.popup = Popup(title="Save file", content=fileChooserDialog, size_hint=(0.9, 0.6), pos_hint={'center': 1, 'top': 1}) self.popup.open() self.dropDownMenu.dismiss() def load(self, path, filename): if not filename: # no file selected. Load dialog remains open .. return pathFilename = os.path.join(path, filename[0]) self.loadPathFilename(pathFilename) self.dismissPopup() def loadPathFilename(self, pathFilename): # emptying the list self.requestList.adapter.data[:] = [] with open(pathFilename) as stream: lines = stream.readlines() lines = list(map(lambda line: line.strip('\n'), lines)) self.requestList.adapter.data.extend(lines) # Reset the ListView self.resetListViewScrollToEnd() self.manageStateOfRequestListButtons() self.refocusOnRequestInput() def save(self, path, filename, isLoadAtStart): if not filename: # no file selected. Save dialog remains open .. return pathFileName = os.path.join(path, filename) with open(pathFileName, 'w') as stream: for line in self.requestList.adapter.data: line = line + '\n' stream.write(line) # saving in config file if the saved file # is to be loaded at application start if isLoadAtStart: self.configMgr.loadAtStartPathFilename = pathFileName else: if self.configMgr.loadAtStartPathFilename == pathFileName: self.configMgr.loadAtStartPathFilename = '' self.configMgr.storeConfig() self.dismissPopup() self.refocusOnRequestInput() # --- end file chooser code --- def isLoadAtStart(self, filePathName): return self.configMgr.loadAtStartPathFilename == filePathName
def __init__(self, configuration): self.identity = None self.configuration = configuration self.connections = set([]) self.configmanager = ConfigurationManager()