def init_machines(self): """ initializes the machines for the simulation """ if is_iterable(self.reward_probability_function) and len(self.rewards.shape) > 1: for i in range(self.N): self.machine_list[i] = Machine(self.rewards[i, :], self.reward_probability_function[i]()) elif is_iterable(self.reward_probability_function): for i in range(self.N): self.machine_list[i] = Machine(self.rewards, self.reward_probability_function[i]()) elif len(self.rewards.shape) > 1: for i in range(self.N): self.machine_list[i] = Machine(self.rewards[i, :], self.reward_probability_function()) else: for i in range(self.N): self.machine_list[i] = Machine(self.rewards, self.reward_probability_function())
def get(self, machine_id): machine_colection = mydb["machine"] machine = machine_colection.find_one({"_id": machine_id}) if machine: return Machine(**machine).machine_to_JSON() else: return {"error": "Not found"}, 404
def GetMachines(self): machines_file = self.alternative_machines_file if machines_file == "": machines_file = wx.GetApp().cam_dir + "/nc/machines.xml" import re import xml.etree.ElementTree as ET with open(machines_file) as f: xml = f.read() root = ET.fromstring( re.sub(r"(<\?xml[^>]+\?>)", r"\1<root>", xml) + "</root>") #root = tree.getroot() machines = [] for item in root.findall('Machine'): machine = Machine() machine.post = item.attrib['post'] machine.reader = item.attrib['reader'] machine.suffix = item.attrib['suffix'] machine.description = item.attrib['description'] machines.append(machine) return machines
def GetMachines(self): machines_file = self.alternative_machines_file if machines_file == "": machines_file = HeeksCNC.heekscnc_path + "/nc/machines2.txt" print 'machines_file = ', machines_file f = open(machines_file) machines = [] while (True): line = f.readline() if (len(line) == 0): break line = line.rstrip('\n') machine = Machine() space_pos = line.find(' ') if space_pos == -1: machine.file_name = line machine.description = line else: machine.file_name = str(line)[0:space_pos] machine.description = line[space_pos:] machines.append(machine) return machines
def __init__(self, N=4, turn='human', strategy='random'): self.board = Board(NW=N) human = Human(color=Stone.BLACK) machine = Machine(color=Stone.WHITE, strategy=strategy) self.player = [human, machine] self.turn = 0 if turn == 'machine': self.turn = 1
def __init__(self, turn='human'): pygame.init() self.board = Board() self.human = Human('Taro') self.machine = Machine('Computer') self.turn = False if turn == 'human' else True self.clock = pygame.time.Clock() self.FPS = 10
def __init__(self, turn='human', strategy='random'): pygame.init() self.board = Board(str=strategy + ' is selected!') self.human = Human('Taro') self.machine = Machine('Computer', strategy) self.turn = False if turn == 'human' else True self.clock = pygame.time.Clock() self.FPS = 10
def mechineSetup(self): toolKit = MyToolKit() roto1 = toolKit.genRotor(allRotors["IC - 1924"]) roto2 = toolKit.genRotor(allRotors["IIC - 1924"]) roto3 = toolKit.genRotor(allRotors["IIIC - 1924"]) plugboard = MyToolKit.genPlugboard({'E': 'W', 'L': 'Y'}) reflector = MyToolKit.genReflector(len(MyToolKit.alphabet)) self.__machine = Machine( rotors=[roto1, roto2, roto3], charset=MyToolKit.genAlphaNum(MyToolKit.alphabet), reflector=reflector, plugboard=plugboard)
def __init__(self, master): tk.Frame.__init__(self) master.geometry(set_size(master, 520, 450)) master.resizable(False, True) master.title("自动布线机 v1.0") self.machine = Machine() self.gcoder = Gcoder() self.serialPort = SerialPort() # Initialized when the connector opened
def getClusterFromFile(filename): # This method reads the "machines" from the given file and output a "cluster" cluster = [] # that is a list which includes all information of these machines with open(filename, 'r') as f: for line in f: config = line.rstrip('\n').split('\t') machineID = int(config[0]) cpu = float(config[1]) mem = float(config[2]) # cpu = 40 # mem = 128 m = Machine(machineID, cpu, mem) cluster.append(m) return cluster
def repl(): print('Press CTRL + D or type "exit" to quit') while True: try: source = input("> ") # 将生成器转为列表 code = list(parse(source)) Machine(code).run() except (RuntimeError, IndexError) as e: print("IndexError: {}".format(e)) except KeyboardInterrupt: print("\nKeyboardInterrupt") break
def __settingUpMachine(self, _dir): while True: print("\nSetting up...") name = input("Enter the machine name: ") ip = input("Enter the machine IP address: ") port = input("Enter the connection port: ") print("\nName:" + name + ", IP:" + ip + ", Port:" + port + "\n") cmd = input("Confirm ? y/n ") if cmd == "y": break machine = Machine(name, ip, port) self.__dumpMachine(machine, _dir) return machine
def settingUpLocalMachine(_dir): while True: root.debug("Setting up...") name = input("Enter the machine name: ") ip = input("Enter the machine IP address: ") port = input("Enter the connection port: ") print("\nName:" + name + ", IP:" + ip + ", Port:" + port + "\n") cmd = input("Confirm ? y/n ") if cmd == "y": break localMachine = Machine(name, ip, port) dumpLocalMachine(localMachine, _dir) return localMachine
def test(machine_info, constants, branch): machine = Machine(machine_info, constants) machine.initialize() initial_branch = machine.get_active_branch() branch_created_flag = False if not machine.switch_branch(branch): branch_created_flag = machine.create_branch(branch) machine.switch_branch(branch) machine.pull_changes_from_remote_branch(branch) machine.build_application() machine.copy_log_to_log_dir() machine.switch_branch(initial_branch) if branch_created_flag: machine.remove_branch(branch) machine.power_down_virtual_machine() return True
def __init__(self): KBEngine.Proxy.__init__(self) self.money self.barNum self.sevenNum self.starNum self.watermelonNum self.bellNum self.snakemelonNum self.orangeNum self.appleNum self.winScore self.resultItem = '' self.betPaid self.bigSmall = 0 self.machine = Machine()
def post(self): keys = request.form.keys() no_keys = True for k in keys: no_keys = False kj = json.loads(k) machine_colection = mydb["machine"] machine_id = kj["machine_id"] machine = machine_colection.find_one({"_id": machine_id}) if machine: return {"result": False}, 400 name = kj["name"] owner = "" if 'username' in session: owner = session['username'] new_machine = Machine(_id=machine_id, name=name, owner=owner) machine_colection.insert_one(new_machine.machine_to_DB()) return new_machine.machine_to_JSON() if no_keys: return {"result": False}, 400
def readMachineFromStorage(self, manager): rf = open(self.filePath, "r") if rf.mode == 'r': contents = rf.read() info = contents.split("|") # print(info) # print(int(len(info)/4)) for i in range(int(len(info) / 4)): user = int(info[i * 4]) time = info[i * 4 + 1] if time != "0": time = datetime.datetime.strptime(time, "%Y-%m-%d %H:%M:%S.%f") s = info[i * 4 + 2] if s == "True": hasNotified = True else: hasNotified = False machType = info[i * 4 + 3] newMachine = Machine(machType) newMachine.use(user, time, hasNotified) manager.addEntity(newMachine)
def createStations(): resource = (G.CMSDData.getElementsByTagName('Resource')) #loop through the resources for item in resource: try: ResourceType = item.getElementsByTagName('ResourceType') ResourceType = ResourceType[0].toxml().replace( '<ResourceType>', '').replace('</ResourceType>', '') #if it is station or machine, read id and name and create it if ResourceType == 'station' or ResourceType == 'machine': id = item.getElementsByTagName('Identifier') id = id[0].toxml().replace('<Identifier>', '').replace('</Identifier>', '') name = item.getElementsByTagName('Name') name = name[0].toxml().replace('<Name>', '').replace('</Name>', '') M = Machine(id, name) G.MachineList.append(M) G.ObjList.append(M) except IndexError: continue
def readResources(): G.SourceList = [] G.MachineList = [] G.ExitList = [] G.QueueList = [] G.RepairmanList = [] G.AssemblyList = [] G.DismantleList = [] G.ConveyerList = [] resource = (G.CMSDData.getElementsByTagName('Resource')) #this loop will search in all the objects for repairmen and create them. #repairmen have to be created first since they may be used in the creation of the other objects for i in range(len(resource)): #get the class try: resourceClass = resource[i].getElementsByTagName( 'ResourceClassIdentifier') resourceClass = resourceClass[0].toxml().replace( '<ResourceClassIdentifier>', '').replace('</ResourceClassIdentifier>', '') except IndexError: continue if resourceClass == 'Repairman': id = resource[i].getElementsByTagName('Identifier') id = id[0].toxml().replace('<Identifier>', '').replace('</Identifier>', '') name = resource[i].getElementsByTagName('Name') name = name[0].toxml().replace('<Name>', '').replace('</Name>', '') property = resource[i].getElementsByTagName('Property') for j in range(len(property)): propertyName = property[j].getElementsByTagName('Name') propertyName = propertyName[0].toxml().replace( '<Name>', '').replace('</Name>', '') if propertyName == 'capacity': capacity = property[j].getElementsByTagName('Value') capacity = int(capacity[0].toxml().replace( '<Value>', '').replace('</Value>', '')) R = Repairman(id, name, capacity) G.RepairmanList.append(R) for i in range(len(resource)): #get the class try: resourceClass = resource[i].getElementsByTagName( 'ResourceClassIdentifier') resourceClass = resourceClass[0].toxml().replace( '<ResourceClassIdentifier>', '').replace('</ResourceClassIdentifier>', '') except IndexError: continue if resourceClass == 'Source': id = resource[i].getElementsByTagName('Identifier') id = id[0].toxml().replace('<Identifier>', '').replace('</Identifier>', '') name = resource[i].getElementsByTagName('Name') name = name[0].toxml().replace('<Name>', '').replace('</Name>', '') property = resource[i].getElementsByTagName('Property') for j in range(len(property)): propertyName = property[j].getElementsByTagName('Name') propertyName = propertyName[0].toxml().replace( '<Name>', '').replace('</Name>', '') if propertyName == 'partType': partType = property[j].getElementsByTagName('Value') partType = (partType[0].toxml().replace( '<Value>', '').replace('</Value>', '')) entity = str_to_class(partType) elif propertyName == 'interarrivalTime': unit = property[j].getElementsByTagName('Unit') unit = unit[0].toxml().replace('<Unit>', '').replace('</Unit>', '') distribution = property[j].getElementsByTagName( 'Distribution') distributionType = distribution[0].getElementsByTagName( 'Name') distributionType = distributionType[0].toxml().replace( '<Name>', '').replace('</Name>', '') distributionParameter = distribution[ 0].getElementsByTagName('DistributionParameter') distributionParameterName = distributionParameter[ 0].getElementsByTagName('Name') distributionParameterName = distributionParameterName[ 0].toxml().replace('<Name>', '').replace('</Name>', '') mean = distributionParameter[0].getElementsByTagName( 'Value') mean = float(mean[0].toxml().replace('<Value>', '').replace( '</Value>', '')) S = Source(id, name, distributionType, mean, entity) G.SourceList.append(S) G.ObjList.append(S) elif resourceClass == 'Machine': id = resource[i].getElementsByTagName('Identifier') id = id[0].toxml().replace('<Identifier>', '').replace('</Identifier>', '') name = resource[i].getElementsByTagName('Name') name = name[0].toxml().replace('<Name>', '').replace('</Name>', '') property = resource[i].getElementsByTagName('Property') for j in range(len(property)): propertyName = property[j].getElementsByTagName('Name') propertyName = propertyName[0].toxml().replace( '<Name>', '').replace('</Name>', '') if propertyName == 'ProcessTime': unit = property[j].getElementsByTagName('Unit') unit = unit[0].toxml().replace('<Unit>', '').replace('</Unit>', '') distribution = property[j].getElementsByTagName( 'Distribution') distributionType = distribution[0].getElementsByTagName( 'Name') distributionType = distributionType[0].toxml().replace( '<Name>', '').replace('</Name>', '') distributionParameter = distribution[ 0].getElementsByTagName('DistributionParameter') mean = 0 stdev = 0 min = 0 max = 0 availability = 0 failureDistribution = None for k in range(len(distributionParameter)): distributionParameterName = distributionParameter[ 0].getElementsByTagName('Name') distributionParameterName = distributionParameterName[ 0].toxml().replace('<Name>', '').replace('</Name>', '') if distributionParameterName == 'mean': mean = distributionParameter[ 0].getElementsByTagName('Value') mean = float(mean[0].toxml().replace( '<Value>', '').replace('</Value>', '')) elif distributionParameterName == 'stdev': stdev = distributionParameter[ 0].getElementsByTagName('Value') stdev = float(stdev[0].toxml().replace( '<Value>', '').replace('</Value>', '')) elif distributionParameterName == 'min': min = distributionParameter[ 0].getElementsByTagName('Value') min = float(mean[0].toxml().replace( '<Value>', '').replace('</Value>', '')) elif distributionParameterName == 'max': max = distributionParameter[ 0].getElementsByTagName('Value') max = float(mean[0].toxml().replace( '<Value>', '').replace('</Value>', '')) elif propertyName == 'MeanTimeToFailure': unit = property[j].getElementsByTagName('Unit') unit = unit[0].toxml().replace('<Unit>', '').replace('</Unit>', '') distribution = property[j].getElementsByTagName( 'Distribution') failureDistribution = distribution[0].getElementsByTagName( 'Name') failureDistribution = failureDistribution[0].toxml( ).replace('<Name>', '').replace('</Name>', '') distributionParameter = distribution[ 0].getElementsByTagName('DistributionParameter') for k in range(len(distributionParameter)): distributionParameterName = distributionParameter[ 0].getElementsByTagName('Name') distributionParameterName = distributionParameterName[ 0].toxml().replace('<Name>', '').replace('</Name>', '') if distributionParameterName == 'mean': MTTF = distributionParameter[ 0].getElementsByTagName('Value') MTTF = float(MTTF[0].toxml().replace( '<Value>', '').replace('</Value>', '')) elif distributionParameterName == 'availability': availability = distributionParameter[ 0].getElementsByTagName('Value') availability = (availability[0].toxml().replace( '<Value>', '').replace('</Value>', '')) elif propertyName == 'MeanTimeToRepair': unit = property[j].getElementsByTagName('Unit') unit = unit[0].toxml().replace('<Unit>', '').replace('</Unit>', '') distribution = property[j].getElementsByTagName( 'Distribution') failureDistribution = distribution[0].getElementsByTagName( 'Name') failureDistribution = failureDistribution[0].toxml( ).replace('<Name>', '').replace('</Name>', '') distributionParameter = distribution[ 0].getElementsByTagName('DistributionParameter') for k in range(len(distributionParameter)): distributionParameterName = distributionParameter[ 0].getElementsByTagName('Name') distributionParameterName = distributionParameterName[ 0].toxml().replace('<Name>', '').replace('</Name>', '') if distributionParameterName == 'mean': MTTR = distributionParameter[ 0].getElementsByTagName('Value') MTTR = float(MTTR[0].toxml().replace( '<Value>', '').replace('</Value>', '')) elif distributionParameterName == 'availability': availability = distributionParameter[ 0].getElementsByTagName('Value') availability = (availability[0].toxml().replace( '<Value>', '').replace('</Value>', '')) elif propertyName == 'RepairmanRequired': repairmanID = property[j].getElementsByTagName( 'ResourceIdentifier') repairmanID = (repairmanID[0].toxml().replace( '<ResourceIdentifier>', '').replace('</ResourceIdentifier>', '')) if repairmanID == 'None': repairman = repairmanID else: for j in range(len(G.RepairmanList)): if (G.RepairmanList[j].id == repairmanID): repairman = G.RepairmanList[j] M = Machine(id, name, 1, distribution=distributionType, failureDistribution=failureDistribution, MTTF=MTTF, MTTR=MTTR, availability=availability, repairman=repairman, mean=mean, stdev=stdev, min=min, max=max) G.MachineList.append(M) G.ObjList.append(M) elif resourceClass == 'Queue': id = resource[i].getElementsByTagName('Identifier') id = id[0].toxml().replace('<Identifier>', '').replace('</Identifier>', '') name = resource[i].getElementsByTagName('Name') name = name[0].toxml().replace('<Name>', '').replace('</Name>', '') property = resource[i].getElementsByTagName('Property') isDummy = 0 capacity = 2 for j in range(len(property)): propertyName = property[j].getElementsByTagName('Name') propertyName = propertyName[0].toxml().replace( '<Name>', '').replace('</Name>', '') if propertyName == 'capacity': capacity = property[j].getElementsByTagName('Value') capacity = int(capacity[0].toxml().replace( '<Value>', '').replace('</Value>', '')) if propertyName == 'isDummy': capacity = property[j].getElementsByTagName('Value') capacity = int(capacity[0].toxml().replace( '<Value>', '').replace('</Value>', '')) Q = Queue(id, name, capacity, isDummy) G.QueueList.append(Q) G.ObjList.append(Q) elif resourceClass == 'Exit': id = resource[i].getElementsByTagName('Identifier') id = id[0].toxml().replace('<Identifier>', '').replace('</Identifier>', '') name = resource[i].getElementsByTagName('Name') name = name[0].toxml().replace('<Name>', '').replace('</Name>', '') E = Exit(id, name) G.ExitList.append(E) G.ObjList.append(E)
myconnection = None errorCount += 1 time.sleep(15) mychannel = myconnection.channel() mychannel.queue_declare(queue=myqueue) return myconnection, mychannel host = os.environ.get('RABBITMQ_HOST', "localhost") delay = int(os.environ.get('DELAY', '2')) rabbitport = int(os.environ.get('RABBITMQ_PORT', '5672')) user = os.environ.get('RABBITMQ_DEFAULT_USER', "cisco") passwd = os.environ.get('RABBITMQ_DEFAULT_PASS', "C1sco123") queue = os.environ.get('RABBITMQ_QUEUE', "HackZurich16") port = int(os.environ.get('PORT', '5000')) print "##################################" print "# Starting Machine Simulator #" print "# (c) 2016 Cisco #" print "# Server: %s #" % (host.ljust(22)) print "# Port: %s #" % (os.environ.get('RABBITMQ_PORT', '5672').ljust(24)) print "# Queue: %s #" % (queue.ljust(23)) print "# User: %s #" % (user.ljust(24)) print "# Password: %s #" % (passwd.ljust(20)) print "# Delay: %s #" % (os.environ.get('DELAY', '2').ljust(23)) print "# Port: %s #" % (os.environ.get('PORT', '5000').ljust(24)) print "##################################" time.sleep(2) connection, channel = connect(host, rabbitport, user, passwd, queue, 10) m = Machine(5) app.run(host="0.0.0.0",port=port)
def __init__(self): super(Window, self).__init__() self.glWidget = GLWidget(self) self.glWidget.move(0, 0) self.glWidget.resize(1920, 1080) self.resize(1920, 1080) self.setWindowTitle("5-Axis Simulator") self.machine = Machine() self.machine.base = Axis('base') self.machine.base.loadModel('base_frame.obj') self.machine.base.setColor(200, 200, 200) self.machine.base.setRelativePosition(1.5, -0.85, -1.15) x_axis = Axis('x_axis') x_axis.loadModel('x_axis.obj') x_axis.setColor(200, 25, 25) x_axis.defineMovement(type='linear', axis='x') x_axis.setRelativePosition(-1.5, 4.55, 0.35) y_axis = Axis('y_axis') y_axis.loadModel('y_axis.obj') y_axis.setColor(25, 200, 25) y_axis.defineMovement(type='linear', axis='z', negative=True) y_axis.setRelativePosition(0, 0, 3.125) z_axis = Axis('z_axis') z_axis.loadModel('z_axis.obj') z_axis.setColor(25, 25, 200) z_axis.defineMovement(type='linear', axis='y') z_axis.setRelativePosition(0, -0.15, 0) a_axis = Axis('a_axis') a_axis.loadModel('a_axis.obj') a_axis.setColor(200, 200, 25) a_axis.defineMovement(type='rotation', axis='y') a_axis.setRelativePosition(0, -2.8, 0) b_axis = Axis('b_axis') b_axis.loadModel('b_axis_tool.obj') b_axis.setColor(200, 25, 200) b_axis.defineMovement(type='rotation', axis='z') b_axis.setRelativePosition(0, 0, 0.8) b_axis.setToolEndOffset(0, -0.75, 0) self.machine.base.addChild(x_axis) self.machine.base.addChild(y_axis) x_axis.addChild(z_axis) z_axis.addChild(a_axis) a_axis.addChild(b_axis) self.machine.x_axis = x_axis self.machine.y_axis = y_axis self.machine.z_axis = z_axis self.machine.a_axis = a_axis self.machine.b_axis = b_axis self.machine.buildMachinState() x_axis.setAxisPositionInMM(0) y_axis.setAxisPositionInMM(0) z_axis.setAxisPositionInMM(0) a_axis.setAxisPositionInDeg(0) b_axis.setAxisPositionInDeg(0) self.machine.buildMachinState() self.machine.setToolPath(circle(500, [1.5, 2, 1])) self.machine.ready = True self.timer = QTimer() self.timer.timeout.connect(self.timer_step) self.timer.setInterval(1 / 60) self.timer.start() self.time_step = 0
__author__ = 'richard.m' __version__ = "$Revision: 1.1$" import Logging from Machine import Machine SQL_SERVICE = "MSSQLSERVER" this_computer = Machine() # Begin logging Logging.log_i("Beginning Config on %s", this_computer.machine_name) Logging.log_i("OS is %s", this_computer.os_name_long) if this_computer.os_bitness: Logging.log_i("64 bit") elif not this_computer.os_bitness: Logging.log_i("32 bit") else: Logging.log_w("Abnormal return in OS bitness test") # Ask initial questions # Compile the list of services on the machine # Ask workgroup question if False in this_computer.initial_config(): Logging.failed("Failed during initial setup") else: Logging.log_i("Set workgroup name to '%s'", this_computer.workgroup_name) Logging.log_i("Set voice recording to '%s'", this_computer.using_voice_recording) Logging.log_i("Set VNC password to '%s'", this_computer.vnc_password) Logging.log_i("Set CTI server name to '%s'", this_computer.cti_server)
''' from os import sys from Machine import Machine ''' Metodo principal (main) Se debe mandar como parametro el archivo del codigo objeto generado con el siguiente formato: > python main.py <arhivo_objeto> ''' if __name__ == '__main__': #Verificar que exista el argumento del archivo objeto if len(sys.argv) > 1: #Leer el archivo de programa pgm_path = sys.argv[1] try: pgm = open(pgm_path, "r") except: print("TM Error: no se existe el archivo '" + pgm_path + "'", file=sys.stderr) exit(1) machine = Machine(pgm) machine.run() else: print( "TM Error: formato del programa 'python main.py <arhivo_objeto>'")
import Transition import Action import Port # def getTransitionTable(source, line, cahche_transition): # return if __name__ == "__main__": source = open( "/Users/gujiawei/Desktop/Edinburgh/MscProject/ProtoGen/MSI_Proto.m") line = source.readline() is_cache_get = False is_directory_get = False is_event_get = False cache_machine = Machine() directory_machine = Machine() while line: line = source.readline() if line.__contains__("s_cache: enum") and not is_cache_get: cache_machine.getStatesOrEvents(source, line, 1) is_cache_get = True elif line.__contains__("s_directory: enum") and not is_directory_get: directory_machine.getStatesOrEvents(source, line, 1) is_directory_get = True elif line.__contains__("MessageType: enum") and not is_event_get: cache_machine.getStatesOrEvents(source, line, 2) is_event_get = True elif is_cache_get and is_directory_get and is_event_get: cache_machine.getTransition()
from Rotor import Rotor from MyToolKit import MyToolKit from Machine import Machine from RotorList import allRotors toolKit = MyToolKit() roto1 = toolKit.genRotor(allRotors["IC - 1924"]) roto2 = toolKit.genRotor(allRotors["IIC - 1924"]) roto3 = toolKit.genRotor(allRotors["IIIC - 1924"]) plugboard = MyToolKit.genPlugboard({'E': 'W', 'L': 'Y'}) reflector = MyToolKit.genReflector(len(MyToolKit.alphabet)) machineBox = Machine( rotors=[roto1, roto2, roto3], charset=MyToolKit.genAlphaNum(MyToolKit.alphabet), reflector=reflector, plugboard=plugboard) inputText = "UXVTI IGW TRP YTH" inputArray = [char for char in inputText] outputText = "" for item in inputArray: outputText += machineBox.enter(item) print(outputText)
def createMachine(): states = ["q1", "q2"] commands = {("q1", "1"): ("q2", "R"), ("q1", "_"): ("q1", "R")} return Machine(states, commands, createTape())
def __setMachineList(self, __debug): # Command Line Interface if __debug in ['True', 'true']: while True: print("\n\nSetting up slave machines.") print("----------Menu------------") print("d) Use default setting.") print("a) Add a new machine") print("v) View current Machine List") print("r) Remove Machine") print("q) Finish") cmd = input("What's your command ? ") if cmd == 'd': print("\nThis is the default setting.") print("Name:localhost, IP:127.0.0.1, Port:9487") print("Name:slave1, IP:192.168.249.141, Port:9487") print("Name:slave2, IP:192.168.249.142, Port:9487") print("Name:slave3, IP:192.168.249.143, Port:9487") cmd = input("Confirm? y/n ") if cmd == "y": self.addMachine( Machine("slave1", "192.168.249.141", "9487")) self.addMachine( Machine("slave2", "192.168.249.142", "9487")) self.addMachine( Machine("slave3", "192.168.249.143", "9487")) else: print("Back to menu") elif cmd == 'a': while True: print("\nAdd a machine") name = input("Enter the name of the machine: ") while name == "q": print("This is an illegal name. Try another.") name = input("Enter the name of the machine: ") ip = input("Enter the ip address of the machine: ") port = input("Enter the port of the machine: ") print("\nName:" + name + ", IP:" + ip + ", Port:" + port) cmd = input("Confirm? y/n ") if cmd == "y": print("Input Accepted") self.addMachine(Machine(name, ip, port)) break else: cmd = input("Re-entering or quit? r/q ") if cmd == "r": pass else: break elif cmd == 'v': machines = self.__sqlDB.execute( 'SELECT name, ip FROM machine_list') for machine in machines: print(machine) elif cmd == 'r': while True: machines = self.__sqlDB.execute( 'SELECT name, ip FROM machine_list') for machine in machines: print(machine) # end of for-loop name = input( 'Enter the machine name to remove it or input q to quit ' ) if name == 'q': break else: pass try: self.__sqlDB.execute( 'DELETE from machine_list where name = ?', (name, )) self.__sqlDB.commit() except sqlite3.Error as e: print(e.args[0]) # end of while-loop elif cmd == 'q': break else: print("\nIllegal command:" + cmd) else: pass # reload rows = self.__sqlDB.execute( 'SELECT name, ip, content FROM machine_list') for row in rows: machine = self.__sqlContentToObject(row[2]) self.__machineTable_name[row[0]] = machine self.__machineTable_ip[row[1]] = row[0] self.__machineList.append(machine) self.__machineNameList.append(machine.getName())
def createMachineList(self, machines_num): self.machines = [] for index in range(machines_num): machine = Machine(index) self.machines.append(machine)
def createMachines(): for i in range(machinesCount): reward = nmp.random.normal(0, 1) machines.append(Machine(reward)) createMachinesProperties()
def newMachine(self, name): machine = Machine(name) self.allMachines.append(machine) return machine