예제 #1
0
파일: interface.py 프로젝트: powertieke/mur
def interface(clients, udpport_sync, moviefolder):
	syncre = re.compile(r'^sync:(.*)$')
	skipre = re.compile(r'^skip:(.*)$')
	playre = re.compile(r'^play:(.*)$')
	while True:
		command = input('--> Type "play:<moviefile>" or "sync:<moviefile>" : ')
		if command == '':
			pass
		elif playre.match(command):
			moviename = playre.match(command).group(1)
			print("Which screen?\n")
			for key in clients.keys():
				print(key)
			while True:
				client = input("--> Type the name of the screen you would like to show the presentation on or type cancel:")
				if client in clients.keys():
					controller.play_single(moviefolder + "/Single/" + moviename + ".mp4", clients[client])
					break
				elif client == "cancel":
					break
				else:
					print(client + " not in screen list. Try again.\n")
			
		elif syncre.match(command):
			moviename = syncre.match(command).group(1)
			print(controller.play_sync(moviefolder + "/Sync/" + moviename, clients, udpport_sync))
		elif command == "quit":
			break
		else:
			pass
예제 #2
0
def webinterface(clients, udpport_sync, moviefolder, killqueue):
	inpipe_path = "/tmp/fromwebapp"
	outpipe_path = "/tmp/towebapp"
	lockfile_path = "/tmp/locked"
	runningfile_path = "/tmp/running"
	
	if os.path.exists(lockfile_path):
		os.remove(lockfile_path)
	
	if not os.path.exists(runningfile_path):
		open(runningfile_path, "a")
	
	if not os.path.exists(inpipe_path):
		os.mkfifo(inpipe_path)
	
	if not os.path.exists(outpipe_path):
		os.mkfifo(outpipe_path)
		
	syncre = re.compile(r'^sync:(.*)$')
	playre = re.compile(r'^play:(.*)$')
	statre = re.compile(r'^stat:(.*)$')
	stopre = re.compile(r'^stop:(.*)$')
	bootre = re.compile(r'^boot:(.*)$')
	while True:
		command = getmessage(inpipe_path)
		if command == '':
			putmessage(outpipe_path, "")
		elif playre.match(command):
			client, moviename = playre.match(command).group(1).split(",")
			controller.play_single(moviefolder + "/Single/" + moviename + ".mp4", clients[client])
			putmessage(outpipe_path, json.dumps({x : clients[x][1] for x in clients.keys()}))
			
		elif syncre.match(command):
			moviename = syncre.match(command).group(1)
			killqueue.put("kill")
			controller.startSyncThread(moviefolder + "/Sync/" + moviename, clients, udpport_sync, killqueue)
			putmessage(outpipe_path, json.dumps({x : clients[x][1] for x in clients.keys()}))
		elif statre.match(command): # here for fun, not used yet
			piname = statre.match(command).group(1)
			if piname == all:
				statstring = ""
				clientrecord = []
				for client in clients.keys():
					clientrecord.append("/".join([client, clients[client][1]]))
		elif stopre.match(command):
			client = stopre.match(command).group(1)
			clients[client][1] = controller.message_to_pi(clients[client], 'shutdown')
			putmessage(outpipe_path, json.dumps({x : clients[x][1] for x in clients.keys()}))
		elif bootre.match(command):
			client = bootre.match(command).group(1)
			clients[client][1] = controller.message_to_pi(clients[client], 'reboot')
			putmessage(outpipe_path, json.dumps({x : clients[x][1] for x in clients.keys()}))
		elif command == "updateall":
			for client in clients.keys():
				clients[client][1] = controller.message_to_pi(clients[client], 'update')
			putmessage(outpipe_path, json.dumps({x : clients[x][1] for x in clients.keys()}))
		elif command == "quit":
			for client in clients.keys():
				clients[client][1] = controller.message_to_pi(clients[client], 'shutdown')
			putmessage(outpipe_path, json.dumps({x : clients[x][1] for x in clients.keys()}))
		elif command == "status":
			putmessage(outpipe_path, json.dumps({x : clients[x][1] for x in clients.keys()}))
		elif command == "quit_c":
			putmessage(outpipe_path, json.dumps({"shutdown":True}))
			while os.path.exists(lockfile_path) :
				time.sleep(0.1)
			if os.path.exists(runningfile_path) :
				os.remove(runningfile_path)
				
			# os.remove(runningfile_path)
			player.shutdown()
		else:
			# print(command)
			putmessage(outpipe_path, json.dumps({x : clients[x][1] for x in clients.keys()}))
			pass