Exemplo n.º 1
0
 def init_remote(self):
     #   connects to specified url via ssl server/client and controls it
     self.remote = Remote(self.control)
     self.threadRemote = QtCore.QThread(self)
     self.remote.moveToThread(self.threadRemote)
     self.control.threads.append(self.threadRemote)
     self.threadRemote.start()
Exemplo n.º 2
0
def main():

	#提示输入参数
	parser = optparse.OptionParser('usage %prog -f <xls file name> -p <inpute password>')
	parser.add_option('-f', dest='fileName', type='string', help='specify xls file name')
	parser.add_option('-p', dest='password', type='string', help='specify connect scp password')

	#提取输入参数
	(options, args) = parser.parse_args()    
	fileName 	 = options.fileName
	password 	 = options.password

	if fileName == None or password == None :        
		print(parser.usage)        
		exit(0)
	else:
		#实例化AccessXls对象处理xls文件
		accessXlsObj = AccessXls()
		#实例化Remote对象执行远程代码
		remoteObj 	 = Remote()
		#实例化logs对象执行写入日志信息
		logsObj = logs()

		#打开Xls文件
		accessXlsObj.OpenFile(fileName)

		#获取ip和uuid和数据的数量
		ip 	 = accessXlsObj.ReadMessageLine(34)
		uuid = accessXlsObj.ReadMessageLine(2)
		count = accessXlsObj.ReadMessageCount()

		#初始化一个list
		data = []

		#将数据提取到一个list里面
		for value in range(count):
			tmp = {}
			tmp["ip"] 	= ip[0]
			tmp["uuid"] = uuid[0]
			del ip[0],uuid[0]
			data.append(tmp)

		for value in data:
			#开启写入日志状态
			logsObj.Start("../logs/log.txt")
			#连接到服务器
			remoteObj.Connect(value["ip"],'root',password)
			#传输文件到服务器
			os.system("sshpass -p " + password  + " scp -r " + catalog + " root@" + value["ip"] + ":/root/")
			#修改配置文件,server_ip的信息
			remoteObj.SendCommand('sed -i -e "s/server_ip =.*/server_ip = ' + value["ip"] + '/g"' + " /root/Linux_agent_minion/config.ini")
			remoteObj.SendCommand('sed -i -e "s/uuid =.*/uuid = ' + value["uuid"] + '/g"' + " /root/Linux_agent_minion/config.ini")
			#执行安装agent
			#remoteObj.SendCommand('cd /root/Linux_agent_minion && bash install.sh')
			#关闭写入日志状态
			logsObj.Close()
			#打印执行状态
			print "ip:" + value["ip"] +" uuid:" + value["uuid"] + " date:" + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) +"\033[0;32;40m success\033[0m"
Exemplo n.º 3
0
    def creerConnexion(self, serveur):
        """
        Crée une connexion au serveur en SSH via un objet Remote (voir Remote.py)

        :param serveur:
        :return Remote:
        """
        r = Remote()
        r.connexion(serveur)

        return r
Exemplo n.º 4
0
    def __init__(self):
        if Controller.__instance != None:  # if the constructor of this class is called more than once
            raise Exception("This class is a singleton!")
        else:
            # puts the created instance in the "__instance" variable
            Controller.__instance = self
            self.cameraBool = True
            self.ledBool = True
            self.previousRoutine = " "
            self.actionList = [511, 511, 511, 511, "man"]
            self.motorState = [511, 511]
            GPIO.setmode(GPIO.BCM)
            self.remote = Remote.getInstance()
            self.mvcontroller = MovementController.getInstance()
            self.microphone = Microphone.getInstance()
            self.beatCount = 0
            self.prevLow = 0
            self.forward = 0
            try:  # try catch so the program can still run if the camera is not plugged in
                self.objDetector = ObjectDetector.getInstance()
            except Exception:
                self.cameraBool = False
                pass
            try:  # try catch so the program can still run if the camera is not plugged in
                self.ledStrip = LedStrip(16, 19)
            except Exception:
                self.ledBool = False
                pass

            self.prevLowToneValue = 0
Exemplo n.º 5
0
	def send(self, key, hold=None):
		"""
		Prepare, send and check return of a remote command to Remote class

		@param key string defines the remote button used
		@param hold enum (0,1,2) represents Button Press Down or UP
		@returns bool the request was successful and the return is valid
		"""
		if len(self.stbip) == 0:
			mb = MessageBox('error')
			mb.mostrar("Set an ip", "Please set an ip to send a command")
			return False

		for ip in self.stbip:
			wdg_retorno = self.get_wdg("txtRetorno")
			if(self.first_command):
				self.first_command = False
				
			if hold is None:
				hold = self.get_wdg("cbRemoteType").get_active()
			rem = Remote(ip)

			ret = rem.send(hold, key)
			msg = "ip: %s\n" % (ip)

			if ret is not None:
				if(rem.return_is_valid(ret, key, hold)):
					complete="Success!"
					tag = "success"
					
					self.show_message(msg + self.__make_rem_readable(ret) + "\n" + complete, tag)
				else:
					complete="Fail."
					tag = "error"
					self.stbip.remove(ip)
			else:
				complete = 'Fail.'
				tag = 'error'
				self.stbip.remove(ip)
				msg += "Timeout Connection\n"
				self.show_message(msg + complete, tag)


			
		
		return True if len(self.stbip) else False
Exemplo n.º 6
0
 def connect(self, throwaway=None):
     try:
         # Ignore all this if we're dealing with the local machine
         if self.hostname is not 'queen':
             self.connection = Remote(self.hostname,
                                      self.username,
                                      self.password,
                                      port=self.port)
             # If not assigned a number, get the number of cores from the remote machine
             print("Connected to {0}".format(self.hostname))
             self.lastInactive = None
     except Exception as anyException:
         print("{0}@{1}: {2}".format(self.username, self.hostname,
                                     anyException))
         self.connection = None
         self.lastInactive = time()
Exemplo n.º 7
0
'''
Created on Jun 29, 2016

@author: ubuntu
'''

import threading
import time
from Remote import Remote
import asyncio
import random
from random import randint

if __name__ == '__main__':
    sensor = Remote()
    
    c = 25 
    
    while True:
        
        i = c
        if (randint(0,1) == 0):
            i += randint(2,5)
        else:
            i -= randint(2,5)
        
        asyncio.get_event_loop().run_until_complete(sensor.sendInfo("temperature", "%d" %(i)))
        time.sleep(60);
        
        
    
Exemplo n.º 8
0
 def remote(self):
     return Remote(self.inbox,self.outbox)
Exemplo n.º 9
0
class Devices(QtCore.QObject):
    audiodev = None
    audiodevout = None
    cameras = OrderedDict()  # container for cameras
    cam_properties = OrderedDict()
    camera_threads = OrderedDict()

    def __init__(self,
                 control,
                 parent=None,
                 audio_input=True,
                 audio_output=False,
                 video_input=False):
        QtCore.QObject.__init__(self, parent)

        self.control = control
        self.cfg = control.cfg

        # init
        if control.cfg['audio_input']:
            self.init_audio_input()
        if control.cfg['audio_output']:
            self.init_audio_output()
        if control.cfg['video_input']:
            self.init_video_input(control.cfg['selected_cameras'])
        if control.cfg['remote']:
            self.init_remote()

    def init_audio_output(self):
        # Audio Output
        self.audiodevout = AudioDevOut(self.control)
        self.threadAudioOut = QtCore.QThread(self)
        self.audiodevout.moveToThread(self.threadAudioOut)
        self.control.threads.append(self.threadAudioOut)
        self.threadAudioOut.start()

        self.control.sig_start_playback.connect(self.audiodevout.play)
        self.audiodevout.sig_playback_finished.connect(
            self.control.playback_finished)
        print('audio output initialized')

    def init_video_input(self, camera_device_search_range):
        # Video
        if self.control.main.debug:
            cam = DummyCamera(self.control)
            cam.name = 'DummyCam'
            self.cameras[cam.name] = cam

        elif self.control.cfg['pointgrey']:
            if not camera_modules['pointgrey']:
                sys.exit('No Pointgrey-camera found')
            cam_num = get_available_flycap_cameras()
            print('Number of flycap-cameras: {}'.format(cam_num))

            # put cameras into dictionary
            for j in range(cam_num):
                cam = pgCamera(self.control,
                               j,
                               fast_and_small_video=self.control.
                               cfg['fast_and_small_video'],
                               triggered=self.control.cfg['trigger'])
                cam.name = str(j)
                self.cameras[str(j)] = cam

        else:
            if not camera_modules['opencv']:
                sys.exit('No OpenCV-cameras found')
            # camera_device_search_range = range(0, 3)
            camera_device_search_range = self.control.selected_cameras
            # camera_device_search_range = [0, 1, 2]
            camera_name_format = 'cv_camera%02i'
            cams = [
                CvCamera(self.control, device_no=i)
                for i in camera_device_search_range
            ]
            tmp = [cam for cam in cams if cam.is_working()]
            # put cameras into dictionary
            for j, cam in enumerate(tmp):
                cam.name = camera_name_format % j
                self.cameras[cam.name] = cam
                self.cam_properties[cam.name] = CvCamera(
                    self.control, device_no=j).get_properties()

        # create threads for cameras
        for cam_name, cam in self.cameras.items():
            self.camera_threads[cam_name] = QtCore.QThread()
            cam.moveToThread(self.camera_threads[cam_name])
            self.camera_threads[cam_name].start()
            self.control.threads.append(self.camera_threads[cam_name])

            # connections
            self.control.sig_start_capture.connect(cam.start_capture)
            self.control.sig_start_recordings.connect(cam.new_recording)
            self.control.sig_stop_recordings.connect(cam.stop_saving)
            print('cam: {} connected'.format(cam_name))

        print('video input initialized')

    def connect_trigger(self):
        # connect cameras to audio trigger
        if self.control.triggered_video:
            for cam_name, cam in self.cameras.items():
                self.audiodev.sig_grab_frame.connect(cam.grab_frame)
        else:
            for cam_name, cam in self.cameras.items():
                self.sig_start_capture.connect(cam.start_capture)

    def init_remote(self):
        #   connects to specified url via ssl server/client and controls it
        self.remote = Remote(self.control)
        self.threadRemote = QtCore.QThread(self)
        self.remote.moveToThread(self.threadRemote)
        self.control.threads.append(self.threadRemote)
        self.threadRemote.start()

        # self.control.sig_remote_connect.connect(self.remote_connect.connect)
        # print('remote connected initialized')

    def init_audio_input(self):
        # Audio Input
        self.audiodev = AudioDev(self.control)
        self.threadAudio = QtCore.QThread(self)
        self.audiodev.moveToThread(self.threadAudio)
        self.control.threads.append(self.threadAudio)
        self.threadAudio.start()

        # start stop
        self.control.sig_start_saving.connect(self.audiodev.start_saving)
        self.control.sig_start_capture.connect(self.audiodev.start_capture)

        print('audio input initialized')
Exemplo n.º 10
0
import traceback

try:
    import RPi.GPIO as GPIO
    from GPIORemote import GPIORemote
    #RPi usable, use GPIO Remote
    remote = GPIORemote()
    print "Using GPIO Remote"
except Exception as e:
    print e
    traceback.print_exc()
    #No RPI Usable, use Remote without functionality
    from Remote import Remote
    remote = Remote()
    print "Using Debug Remote"