def main(): ui = userinput.UserInput() jobnumber = ui.jobnumber bandpathtxt = ui.bandpath btxt = os.path.split(bandpathtxt)[-1] tile = btxt.split('_')[0][1:] print(tile) #/scratch/project_2001106/S2L2A_2018/T35VMK/S2A_MSIL2A_20180811T095031_N0208_R079_T35VMK_20180811T124846.SAFE/GRANULE/ # L2A_T35VMK_A016378_20180811T095029/IMG_DATA/R10m/T35VMK_20180811T095031_B04_10m.jp2 shapedir = ui.shapedir namelist = os.listdir(shapedir)[0].split('_') shapename = '_'.join(namelist[:-1]) tileshapename = shapename + '_' + tile shapefile = os.path.join(shapedir, tileshapename) projectname = ui.projectname if not jobnumber is None: for ext in ['.shp', '.shx', '.prj', '.dbf']: shp = shapefile + ext if os.path.isfile(shp): print(shp) jobdir = os.path.join(projectname, jobnumber) dst = os.path.join(jobdir, tileshapename + ext) if not os.path.exists(jobdir): os.makedirs(jobdir) copyfile(shp, dst) if dst.endswith('.shp'): shpfile = dst else: shpfile = shapefile + '.shp' shapeobj = shapeobject.ShapeObject(shpfile) shpfile = shapeobj.checkProjection(bandpathtxt) extractarray(bandpathtxt, shpfile, tile, projectname, ui)
def makebandpaths(): ui = userinput.UserInput() #from all filepaths, extend to matching band paths filepaths = makefilepaths(ui) bandpaths = [] for filepath in filepaths: granulepath = os.path.join(filepath, 'GRANULE') betweenpath = os.path.join(granulepath, os.listdir(granulepath)[0]) imgpath = os.path.join(betweenpath, 'IMG_DATA') r10 = os.path.join(imgpath, 'R10m') r20 = os.path.join(imgpath, 'R20m') r60 = os.path.join(imgpath, 'R60m') bandlist = makebandname(ui) #print(bandlist) for rdir in [r10, r20, r60]: mylist = [ os.path.join(rdir, bandfile) for bandfile in os.listdir(rdir) if bandfile.split('_')[-2] + '_' + bandfile.split('_')[-1][:3] in bandlist ] bandpaths.extend(mylist) #print(mylist) to_txt(bandpaths)
def testrequest(self): fakeuser = ['', 'wrongport'] try: ui = userinput.UserInput(dlxii.Device(), testdata=fakeuser) ui.request() self.assertTrue(False, msg="did not fault on empty debug list") except IndexError: pass ports = getports.GetPorts().get() fakeuser += getports.GetPorts().get() + \ ['junk', 'dlx2', 'mytest.txt'] ui = userinput.UserInput(dlxii.Device(), testdata=fakeuser) ui.request() self.assertEqual(ports[0], ui.comm_port) self.assertEqual('mytest.txt', ui.inputfn) self.assertTrue(isinstance(ui.controller_type, dlxii.Device))
def test_charset_remove_missing(self): x = userinput.UserInput() # my favourite character :) try: x.remove_character('+') self.assertFalse(False) except KeyError: self.assertTrue(True)
def testprocessLoop(self): ui = userinput.UserInput(dlxii.Device()) ui.comm_port = Testutils.sdevice utili = utils.Utils(ui, controller.Controller(ui), testing=True, showhelp=False) utili.process_loop()
def process_cmdline(_available_ports: List[str], _testcmdline=None): """process_cmdline(_available_ports, _testcmdline="") _available_ports is a list? of port names _testcmdline can be list of strings that can be used to fake a command line. If None, the default command line processing is performed, otherwise, the list of strings in the argument is used. processes the command line arguments returns a tuple of (ui, verbose, cmdl_debug) if arguments are ok, Otherwise raises an exception """ msg: str = '' _tcl = [] if _testcmdline: _tcl = _testcmdline tempargs = sys.argv[1:] + _tcl help_processing(_available_ports, tempargs) if _testcmdline: args = _PARSER.parse_args(_testcmdline) else: args = _PARSER.parse_args() if args.logdebug: LOGGER.setLevel(logging.DEBUG) elif args.loginfo: LOGGER.setLevel(logging.INFO) possible_port: str = args.Port if args.Controller: possible_ctrl = args.Controller else: possible_ctrl = 'dlxii' if len(_available_ports) != 1: if not args.Port.upper() in _available_ports: msg = f'Port {args.Port} not available: available ports are: {_available_ports}, aborting' raise Exception(msg) else: possible_port = _available_ports[0] ctrl: Tuple[str, Any] = knowncontrollers.select_controller(possible_ctrl) if not ctrl: msg = f'Controller {args.Controller} not available: available controlers are: {knowncontrollers.get_controller_ids()}, aborting' raise Exception(msg) verbose: bool = args.verbose cmdl_debug = args.cldebug _ui = userinput.UserInput(ctrl[1]) _ui.comm_port = possible_port if verbose: msg = f'[verbose] ctrl:{ctrl}, port:{_ui.comm_port}, dbg:{cmdl_debug}, verbose: True' return (_ui, verbose, cmdl_debug)
def testresetCmdNames(self): ui = userinput.UserInput(dlxii.Device()) ui.comm_port = Testutils.sdevice utili = utils.Utils(ui, controller.Controller(ui), testing=True, showhelp=False) myserial.MySerial._dbidx = -1 utili.reset_cmd_names()
def testcreation(self): ui = userinput.UserInput(dlxii.Device()) ui.comm_port = Testutils.sdevice c = controller.Controller(ui) utili = utils.Utils(ui, c, testing=False, showhelp=False) self.assertFalse(utili.testing) utili = utils.Utils(ui, c, testing=True, showhelp=False) self.assertTrue(utili.testing) utili = utils.Utils(ui, c, testing=True, showhelp=True)
def __init__(self, width, height): # init vars self.uiobj = ui.UI(width, height) self.userinputobj = userinput.UserInput() self.gameobj = entity.Game(entity.Player(), entity.Player()) self.logicobj = logic.Logic() # update ui at start self.uiobj.update(self.gameobj, userinput)
def main(screen, metricPatterns, interval, collectd): curses.curs_set(0) liveData = livedata.LiveData(metricPatterns, interval, collectd) simpleView = views.simple.Simple(screen) meansView = views.means.Means(screen) liveData.addView(simpleView) liveData.addView(meansView) meansView.onTop() userinput.UserInput(liveData, screen, simpleView, meansView) liveData.go()
def main(screen, metricPatterns, interval, collectd): curses.curs_set(0) liveData = livedata.LiveData(metricPatterns, interval, collectd) simpleView = views.simple.Simple(screen) aggregateView = views.aggregate.Aggregate(screen) liveData.addView(simpleView) liveData.addView(aggregateView) aggregateView.onTop() userinput.UserInput(liveData, screen, simpleView, aggregateView) liveData.go()
def __init__(self): self.scanner = uiatools.Scanner() mih = userinput.MouseInputHandler(self._on_mouse_click, self.scanner.get_item_path) kih = userinput.KeyboardInputHandler(self._on_key_press) self.input = userinput.UserInput(mih, kih) self.action_queue = queue.Queue() self.keyboard_buffer = '' self.keyboard_item = None self.is_running = False
def __init__(self): """__init__ """ self.game = gamecore.GameCore('') self.unhappy = unhappy.Unhappy() self.userinput = userinput.UserInput() # TODO: move to configuration or such.. self.wordselection = wordselection.WordSelection('../data/nouns.txt') self.wordselection.read_file() self.word_group = (self.wordselection.pick_word_group()) self.wordselection.create_word_structure() self.ingame = True
def main(metricPatterns, interval, collectd): aggregateView = views.aggregate.Aggregate() simpleView = views.simple.Simple() userInput = userinput.UserInput() loop = urwid.MainLoop(aggregateView.widget(), unhandled_input=userInput) userInput.setLoop(loop) userInput.setMap(M=aggregateView, S=simpleView) liveData = livedata.LiveData(metricPatterns, interval, collectd) liveData.addView(simpleView) liveData.addView(aggregateView) liveDataThread = threading.Thread(target=lambda: liveData.go(loop)) liveDataThread.daemon = True liveDataThread.start() loop.run()
def teststr(self): ui = userinput.UserInput(dlxii.Device()) ui.comm_port = Testutils.sdevice c = controller.Controller(ui) utili = utils.Utils(ui, c, testing=False, showhelp=False) self.assertEqual( 'testing:False, cmds: -acr, -rmn, -ran, -rmd, -cacn, -q', str(utili)) utili = utils.Utils(ui, c, testing=True, showhelp=False) self.assertEqual( 'testing:True, cmds: -acr, -rmn, -ran, -rmd, -cacn, -q', str(utili)) # if showhelp true then something like """
def fancyUserInterface(metricPatterns, interval, metric_source): aggregateView = views.aggregate.Aggregate() simpleView = views.simple.Simple() userInput = userinput.UserInput() loop = urwid.MainLoop(aggregateView.widget(), unhandled_input=userInput) userInput.setLoop(loop) userInput.setMap(M=aggregateView, S=simpleView) liveData = livedata.LiveData(metricPatterns, interval, metric_source) liveData.addView(simpleView) liveData.addView(aggregateView) liveDataThread = threading.Thread(target=lambda: liveData.go(loop)) liveDataThread.daemon = True liveDataThread.start() try: loop.run() except KeyboardInterrupt: pass
def testopen(self): """testopen() """ self.assertTrue(myserial.MySerial._debugging) ui = userinput.UserInput(dlxii.Device()) ui.inputfn = "cmdreadertest.txt" ui.comm_port = Testuserinput.sdevice self.assertTrue(ui.open(detect_br=False)) sp = ui.serial_port self.assertTrue(sp.isOpen()) self.assertEqual(Testuserinput.sdevice, sp.port) self.assertEqual(9600, sp.baudrate) ui.close() ui.close() self.assertFalse(sp.isOpen()) self.assertFalse(ui.serial_port.isOpen()) # prep for test with baudrate finder myserial.MySerial._dbidx = 0 myserial.MySerial._debugreturns = [ b'preread ignored', b'9600 fail try 1 MF>', b'preread ignored', b'9600 fail try 2 MF>', b'preread ignored', b'19200 fail try 1 TMF>', b'preread ignored', b'19200 succeed try 2 DTMF>' ] self.assertTrue(ui.open()) self.assertEqual(19200, sp.baudrate) self.assertTrue(sp.isOpen()) ui.close() myserial.MySerial._debugreturns = [ b'preread ignored', b'9600 fail try 1 MF>', b'preread ignored', b'9600 fail try 2 MF>', b'preread ignored', b'19200 fail try 1 TMF>', b'preread ignored', b'19200 succeed try 2 DTMF>' ] myserial.MySerial._dbidx = 0 ui.open(detect_br=False) self.assertEqual(9600, sp.baudrate) # 9600 is the default ui.close()
def fancyUserInterface(metricPatterns, interval, metric_source, ttl): aggregateView = views.aggregate.Aggregate() simpleView = views.simple.Simple() userInput = userinput.UserInput() loop = urwid.MainLoop(aggregateView.widget(), unhandled_input=userInput) userInput.setLoop(loop) userInput.setMap(M=aggregateView, S=simpleView) try: liveData = livedata.LiveData(metricPatterns, interval, metric_source, ttl) except Exception as inst: print("scyllatop failed connecting to Scylla With an error: {error}".format(error=inst)) sys.exit(1) liveData.addView(simpleView) liveData.addView(aggregateView) liveDataThread = threading.Thread(target=lambda: liveData.go(loop)) liveDataThread.daemon = True liveDataThread.start() try: loop.run() except KeyboardInterrupt: pass
def test1_open(self): """testopen() """ _cr = CommandReader(TestCommandreader.ui) _fcr = None try: self.assertTrue(_cr.atts['is_closed']) self.assertEqual("", _cr.get()) _cr.close() self.assertTrue(_cr.open()) eres = '[CommandReader closed: False, [UserInput: , cmdreadertest.txt]]' self.assertEqual(eres, str(_cr)) self.assertEqual(eres, repr(_cr)) self.assertFalse(_cr.atts['is_closed']) try: _cr.open() assert "did not detect multiple attempts to open" except AssertionError: pass _cr.close() self.assertTrue(_cr.atts['is_closed']) fakeui = userinput.UserInput(dlxii.Device()) fakeui.inputfn = 'totaljunk.txt' _fcr = CommandReader(fakeui) self.assertFalse(_fcr.open()) self.assertEqual( "[Errno 2] No such file or directory: 'totaljunk.txt'", str(_fcr.atts['lasterror'])) self.assertTrue(_fcr.atts['is_closed']) finally: if _fcr: _fcr.close() _cr.close()
def test_charset_initialization(self): x = userinput.UserInput() self.assertEqual(x.character_set, userinput.CHARACTERS)
def testdoit(self): msclass = myserial.MySerial devs: List[str] = getports.GetPorts().get() port = 'COM3' if devs: port = devs[0] else: self.fail('no ports available') msclass._debugging = True msclass._dbidx = 0 # test same date and time msclass._debugreturns = [ b'preread ignored\r', b'\n9600 open default succeed DTMF>', b'DTMF>N029\r', b'\nThis is Wednesday, 01-03-2018\r', b'\nOK\r', b'\nDTMF>', b'DTMF>N027\r', b'\nThe time is 12:23 P.M.\r', b'\nOK\r', b'\nDTMF>', ] ui = userinput.UserInput(ctype=dlxii.Device()) ui.controller_type = dlxii.Device() ui.comm_port = port ui.inputfn = 'updatetest.txt' matchtime = time.strptime("03 Jan 2018 12 23 00", "%d %b %Y %H %M %S") stuff = updatetime.Stuff((ui, False, False)) res = stuff.doit(debug_time=matchtime) self.assertTrue(res[2]) self.assertEqual(14, res[0]) self.assertTrue(14, res[1]) msclass._dbidx = 0 # test same date differnt time msclass._debugreturns = [ b'preread ignored\r', b'\n9600 open default succeed DTMF>', b'DTMF>N029\r', b'\nThis is Wednesday, 01-03-2018\r', b'\nOK\r', b'\nDTMF>', b'DTMF>N027\r', b'\nThe time is 12:23 P.M.\r', b'\nOK\r', b'\nDTMF>', b'DTMF>N02507071\r', b'\nTime set to 12:02 P.M.\r', b'\nOK\r', b'\nOK\r', b'\nDTMF>', b'DTMF>N029\r', b'\nThis is Wednesday, 01-03-2018\r', b'\nOK\r', b'\nDTMF>', b'DTMF>N027\r', b'\nThe time is 12:02 P.M.\r', b'\nOK\r', b'\nDTMF>', b'\nDTMF>', b'\nDTMF>', b'\nDTMF>', b'\nDTMF>', b'\nDTMF>', b'\nDTMF>', b'\nDTMF>', ] matchtime = time.strptime("03 Jan 2018 12 02 00", "%d %b %Y %H %M %S") res = stuff.doit(debug_time=matchtime) self.assertTrue(res[1]) self.assertEqual(13, res[0]) self.assertFalse(res[2]) msclass._dbidx = 0 # test differnt time and different date msclass._debugreturns = [ b'preread ignored\r', b'\n9600 open default succeed DTMF>', b'DTMF>N029\r', b'\nThis is Tuesday, 01-02-2018\r', b'\nOK\r', b'\nDTMF>', b'DTMF>N0280103184\r', b'\nThis is Wednesday, 01-03-2018\r', b'\nOK\r', b'\nDTMF>', b'DTMF>N029\r', b'\nThis is Wednesday, 01-03-2018\r', b'\nOK\r', b'\nDTMF>', b'DTMF>N027\r', b'\nThe time is 12:23 P.M.\r', b'\nOK\r', b'\nDTMF>', b'DTMF>N02507071\r', b'\nTime set to 12:02 P.M.\r', b'\nOK\r', b'\nOK\r', b'\nDTMF>', b'DTMF>N029\r', b'\nThis is Wednesday, 01-03-2018\r', b'\nOK\r', b'\nDTMF>', b'DTMF>N027\r', b'\nThe time is 12:02 P.M.\r', b'\nOK\r', b'\nDTMF>', b'\nDTMF>', b'\nDTMF>', b'\nDTMF>', b'\nDTMF>', b'\nDTMF>', b'\nDTMF>', b'\nDTMF>', ] matchtime = time.strptime("03 Jan 2018 12 02 00", "%d %b %Y %H %M %S") res = stuff.doit(debug_time=matchtime) self.assertTrue(res[1]) self.assertEqual(12, res[0]) self.assertFalse(res[2]) # still need to test the debug option in the affected code to make sure the time change is not sent to the controler msclass._debugging = False
def __init__(self): self.ui = userinput.UserInput() self.gameboard = gameboard.Gameboard() self.validator = validate.Validate() self.color = 'white' self.captured_pieces = [] self.white_pieces = [] self.black_pieces = [] for i in 'abcdefgh': self.white_pieces.append( piece.Piece(i + '2', name='pawn', color='white', name_representation='\u2659')) self.black_pieces.append( piece.Piece(i + '7', name='pawn', color='black', name_representation='\u265F')) for i in 'ah': self.white_pieces.append( piece.Piece(i + '1', name='rook', color='white', name_representation='\u2656')) self.black_pieces.append( piece.Piece(i + '8', name='rook', color='black', name_representation='\u265C')) for i in 'bg': self.white_pieces.append( piece.Piece(i + '1', name='knight', color='white', name_representation='\u2658')) self.black_pieces.append( piece.Piece(i + '8', name='knight', color='black', name_representation='\u265E')) for i in 'cf': self.white_pieces.append( piece.Piece(i + '1', name='bishop', color='white', name_representation='\u2657')) self.black_pieces.append( piece.Piece(i + '8', name='bishop', color='black', name_representation='\u265D')) self.white_pieces.append( piece.Piece('d1', name='queen', color='white', name_representation='\u2655')) self.black_pieces.append( piece.Piece('d8', name='queen', color='black', name_representation='\u265B')) self.white_pieces.append( piece.Piece('e1', name='king', color='white', name_representation='\u2654')) self.black_pieces.append( piece.Piece('e8', name='king', color='black', name_representation='\u265A'))
def test_charset_display(self): x = userinput.UserInput() self.assertEqual(str(x.character_set), str(x.display_characters()))
def test_charset_remove(self): x = userinput.UserInput() # my favourite character :) x.remove_character('پ') self.assertNotIn('پ', x.character_set)
def test_creation(self): x = userinput.UserInput() self.assertNotEqual(x, None)
def process_cmdline(_available_ports: List[str], _testcmdline: List[str] = None) -> Tuple[Any, Any, Any]: """process_cmdline(_available_ports, _testcmdline="") _available_ports is a list? of port names _testcmdline can be list of strings that can be used to fake a command line. If None, the default command line processing is performed, otherwise, the list of strings in the argument is used. processes the command line arguments returns a tuple of (ui, verbose, cmdl_debug) if arguments are ok, Otherwise raises an exception """ _tcl = [] if _testcmdline: _tcl = _testcmdline tempargs = sys.argv[1:] + _tcl proc1(tempargs, _available_ports) # if not ('-h' in tempargs or '--help' in tempargs): # if _available_ports.isEmpty(): #msg = 'no available communication port: aborting' #raise SystemExit(msg) # if '-h' in tempargs or '--help' in tempargs: # _PARSER.print_help() #raise SystemExit() if _testcmdline: args = _PARSER.parse_args(_testcmdline) else: args = _PARSER.parse_args() _aa = proc2(args, ) possible_port = _aa[0] possible_ctrl = _aa[1] # if args.logdebug: # LOGGER.setLevel(logging.DEBUG) # elif args.loginfo: # LOGGER.setLevel(logging.INFO) #possible_port = args.Port # if args.Controller: #possible_ctrl = args.Controller # else: #possible_ctrl = 'dlxii' if len(_available_ports) != 1: if not args.Port.upper() in _available_ports: msg = 'Port {} not available: available ports are: {}, aborting' \ .format(args.Port, _available_ports) raise Exception(msg) else: possible_port = _available_ports[0] ctrl = knowncontrollers.select_controller(possible_ctrl) if not ctrl: msg = 'Controller {} not available: available controlers are: {}, aborting' \ .format(args.Controller, knowncontrollers.get_controller_ids()) raise Exception(msg) verbose = args.verbose cmdl_debug = args.cldebug _ui = userinput.UserInput(ctrl[1]) _ui.comm_port = possible_port if verbose: msg = '[verbose] ctrl:{}, port:{}, dbg:{}, verbose: True'\ .format(ctrl, _ui.comm_port, cmdl_debug) return (_ui, verbose, cmdl_debug)
class TestCommandreader(unittest.TestCase): """command reader test""" ctrl = knowncontrollers.select_controller('dlxii')[1] ui = userinput.UserInput(ctrl) def setUp(self): pass def tearDown(self): pass @classmethod def setUpClass(cls): TestCommandreader.ui.inputfn = "cmdreadertest.txt" @classmethod def tearDownClass(cls): pass def test0_inst(self): _cr = CommandReader(TestCommandreader.ui) eres = '[CommandReader closed: True, [UserInput: , cmdreadertest.txt]]' self.assertEqual(eres, str(_cr)) self.assertEqual(eres, repr(_cr)) def test1_open(self): """testopen() """ _cr = CommandReader(TestCommandreader.ui) _fcr = None try: self.assertTrue(_cr.atts['is_closed']) self.assertEqual("", _cr.get()) _cr.close() self.assertTrue(_cr.open()) eres = '[CommandReader closed: False, [UserInput: , cmdreadertest.txt]]' self.assertEqual(eres, str(_cr)) self.assertEqual(eres, repr(_cr)) self.assertFalse(_cr.atts['is_closed']) try: _cr.open() assert "did not detect multiple attempts to open" except AssertionError: pass _cr.close() self.assertTrue(_cr.atts['is_closed']) fakeui = userinput.UserInput(dlxii.Device()) fakeui.inputfn = 'totaljunk.txt' _fcr = CommandReader(fakeui) self.assertFalse(_fcr.open()) self.assertEqual( "[Errno 2] No such file or directory: 'totaljunk.txt'", str(_fcr.atts['lasterror'])) self.assertTrue(_fcr.atts['is_closed']) finally: if _fcr: _fcr.close() _cr.close() def test0_close(self): """"check for close working""" _cr = CommandReader(TestCommandreader.ui) if (_cr.atts['is_closed']): _cr.open() self.assertFalse(_cr.atts['is_closed']) _cr.close() self.assertTrue(_cr.atts['is_closed']) def test3_get(self): """testget """ _cr = CommandReader(TestCommandreader.ui) try: _cr.open() lines = [] while True: line = _cr.get() if line == "": break lines.append(line) # should have read all lines from a stream so the stream should automatically # close self.assertTrue(_cr.atts['is_closed']) self.assertEqual(7, len(lines)) lastline = lines[6] self.assertFalse(lastline.endswith("\n")) emptyline = lines[5] self.assertEqual("\n", emptyline) self.assertEqual("line 4\n", lines[3]) finally: _cr.close() self.assertTrue(_cr.atts['is_closed'])