コード例 #1
0
    def lineReceived(self, line):
        if line == 'ENDMSG':
            self._display_response(self.buffer)
            self.buffer = []

        elif line.startswith('SEARCH'):

            data = clean_and_split_input(line)
            filename = data[1]
            files = []
            files = [
                f for f in os.listdir(self.factory.files_path)
                if os.path.isfile(os.path.join(self.factory.files_path, f))
            ]
            if filename in files:
                self.sendLine('sresponse true')

            else:
                self.sendLine('sresponse false')

        elif line.startswith('HASH'):
            # Received a file name and hash, server is sending us a file

            data = clean_and_split_input(line)

            filename = data[1]
            file_hash = data[2]

            self.file_data = (filename, file_hash)
            self.setRawMode()
        else:
            self.buffer.append(line)
コード例 #2
0
ファイル: client.py プロジェクト: tahyuu/paimai
    def lineReceived(self, line):

        if line == 'ENDMSG':

            self.factory.deferred.callback(self.buffer)

            self.buffer = []

        elif line.startswith('HASH'):

            # Received a file name and hash, server is sending us a file

            data = clean_and_split_input(line)



            filename = data[1]

            file_hash = data[2]

            

            self.file_data = (filename, file_hash)

            self.setRawMode()

        else:

            self.buffer.append(line)
コード例 #3
0
ファイル: client.py プロジェクト: tahyuu/paimai
    def _sendCommand(self, line):
        """ Sends a command to the server. """

        data = clean_and_split_input(line)
        if len(data) == 0 or data == '':
            return

        command = data[0].lower()
        if not command in COMMANDS:
            self._display_message('Invalid command')
            return

        if command == 'list' or command == 'help' or command == 'quit':
            self.connection.transport.write('%s\n' % (command))
        elif command == 'get':
            try:
                filename = data[1]
            except IndexError:
                self._display_message('Missing filename')
                return

            self.connection.transport.write('%s %s\n' % (command, filename))
        elif command == 'put':
            try:
                file_path = data[1]
                filename = data[2]
            except IndexError:
                self._display_message(
                    'Missing local file path or remote file name')
                return

            if not os.path.isfile(file_path):
                self._display_message('This file does not exist')
                return

            file_size = os.path.getsize(file_path) / 1024

            print 'Uploading file: %s (%d KB)' % (filename, file_size)

            self.connection.transport.write(
                'PUT %s %s\n' % (filename, get_file_md5_hash(file_path)))
            self.setRawMode()

            for bytes in read_bytes_from_file(file_path):
                self.connection.transport.write(bytes)

            self.connection.transport.write('\r\n')

            # When the transfer is finished, we go back to the line mode
            self.setLineMode()
        else:
            self.connection.transport.write('%s %s\n' % (command, data[1]))

        self.factory.deferred.addCallback(self._display_response)
コード例 #4
0
    def _sendCommand(self, line):
        """ Sends a command to the server. """
        
        data = clean_and_split_input(line) 
        if len(data) == 0 or data == '':
            return 

        command = data[0].lower()
        if not command in COMMANDS:
            self._display_message('Invalid command')
            return
        
        if command == 'list' or command == 'help' or command == 'quit':
            self.connection.transport.write('%s\n' % (command))
        elif command == 'get':
            try:
                filename = data[1]
            except IndexError:
                self._display_message('Missing filename')
                return
            
            self.connection.transport.write('%s %s\n' % (command, filename))
        elif command == 'put':
            try:
                file_path = data[1]
                filename = data[2]
            except IndexError:
                self._display_message('Missing local file path or remote file name')
                return
            
            if not os.path.isfile(file_path):
                self._display_message('This file does not exist')
                return

            file_size = os.path.getsize(file_path) / 1024
            
            print 'Uploading file: %s (%d KB)' % (filename, file_size)
            
            self.connection.transport.write('PUT %s %s\n' % (filename, get_file_md5_hash(file_path)))
            self.setRawMode()
            
            for bytes in read_bytes_from_file(file_path):
                self.connection.transport.write(bytes)
            
            self.connection.transport.write('\r\n')   
            
            # When the transfer is finished, we go back to the line mode 
            self.setLineMode()
        else:
            self.connection.transport.write('%s %s\n' % (command, data[1]))

        self.factory.deferred.addCallback(self._display_response)
コード例 #5
0
    def lineReceived(self, line):
        if line == 'ENDMSG':
            self.factory.deferred.callback(self.buffer)
            self.buffer = []
        elif line.startswith('HASH'):
            # Received a file name and hash, server is sending us a file
            data = clean_and_split_input(line)

            filename = data[1]
            file_hash = data[2]

            self.file_data = (filename, file_hash)
            self.setRawMode()
        else:
            self.buffer.append(line)
コード例 #6
0
ファイル: client_protocol.py プロジェクト: adamxu0220/SCT
 def __update_status(self, line):
     """ Download a file from the server. """
     data = clean_and_split_input(line)
     if len(data) == 0 or data == '' or self.transport == None:
         return False
     command = data[0].lower()
     if command == 'hb':
         self.transport.write('%s %s\n' % (command, ' '.join(data[1:])))
         return True
     elif command == 'case_finished':
         self.transport.write('%s %s\n' % (command, ' '.join(data[1:])))
         return True
     else:
         self.prv_logger.error("invalid cmd:%s" % command)
         return False
コード例 #7
0
ファイル: client-modded.py プロジェクト: ananya1122/SharePy
    def lineReceived(self, line):
        if line == 'ENDMSG':
            self._display_response(self.buffer)
            self.buffer = []
            
                
        
        elif line.startswith('SEARCH'):
           
            data = clean_and_split_input(line)
            filename = data[1]
            files = []
            files = [ f for f in os.listdir(self.factory.files_path) if os.path.isfile(os.path.join(self.factory.files_path,f)) ]
            if filename in files :
                self.sendLine('sresponse true')
                
            else :
                self.sendLine('sresponse false')
                
            
                
            
        
        
        elif line.startswith('HASH'):
            # Received a file name and hash, server is sending us a file
            
            data = clean_and_split_input(line)

            filename = data[1]
            file_hash = data[2]
            
            self.file_data = (filename, file_hash)
            self.setRawMode()
        else:
            self.buffer.append(line)
コード例 #8
0
ファイル: client_protocol.py プロジェクト: adamxu0220/SCT
 def __download_file(self, line):
     """ Download a file from the server. """
     data = clean_and_split_input(line)
     if len(data) == 0 or data == '' or self.transport == None:
         return False
     command = data[0].lower()
     if command == 'download':
         try:
             src_filename = data[1]
             dst_filename = data[2]
         except IndexError:
             self._display_message('Missing filename')
             return False
         self.transport.write('%s %s %s\n' %
                              ("get", src_filename, dst_filename))
         return True
     else:
         self.prv_logger.error("invalid cmd:%s" % command)
         return False
コード例 #9
0
ファイル: client_protocol.py プロジェクト: adamxu0220/SCT
    def _process_response(self, line=None):
        """
		handle start/stop test case
		handle download test case
		handle upload test result
		handle update get-dut-sw-version method
		"""
        data = clean_and_split_input(line)
        if len(data) == 0 or data == '':
            return
        command = data[0].lower()
        if command == "stop_testcase":
            self.prv_logger.trace("try to stop running task")
            if self.stopcase_func != None:
                self.prv_logger.trace("call self.stopcase_func")
                self.stopcase_func()
        elif command == "start_testcase":
            self.prv_logger.trace("try to start new task")
            if self.startcase_func != None:
                self.prv_logger.trace("call self.startcase_func")
                if len(data) == 4:
                    th = threading.Thread(target=self.startcase_func,
                                          args=(data[1], data[2], data[3]))

                elif len(data) >= 5:
                    th = threading.Thread(target=self.startcase_func,
                                          args=(data[1], data[2], data[3],
                                                " ".join(data[4:])))

                else:
                    self.prv_logger.error(
                        "error, invalid len(data):%d; data:%s" %
                        (len(data), line))

                th.setDaemon(True)
                th.start()
        elif command == "cancel_testcase":
            self.prv_logger.trace("try to cancel new task")
            if self.cancelcase_func != None:
                self.prv_logger.trace("call self.cancelcase_func")
                self.cancelcase_func()
        else:
            self.prv_logger.trace("unhandle command:%s" % command)
コード例 #10
0
ファイル: client_protocol.py プロジェクト: adamxu0220/SCT
    def lineReceived(self, line):
        if not vars(self).has_key(
                "factory") or self.factory == None or not self.fg_ready:
            return
        if line == 'ENDMSG':
            self.prv_logger.trace(self.buffer)
            self.process_response(self.buffer)
            self.buffer = []
            self.CmdLineProtocol.set_idle()
        elif line.startswith('HASH'):
            # Received a file name and hash, server is sending us a file
            data = clean_and_split_input(line)

            filename = data[1]
            file_hash = data[2]

            self.file_data = (filename, file_hash)
            self.setRawMode()
        else:
            self.buffer.append(line)
コード例 #11
0
ファイル: client_protocol.py プロジェクト: adamxu0220/SCT
    def __upload_file(self, line):
        """ Download a file from the server. """
        data = clean_and_split_input(line)
        if len(data) == 0 or data == '' or self.transport == None:
            return False
        command = data[0].lower()
        if command == 'upload':
            try:
                file_path = data[1]
                filename = data[2]
                cmdid = data[3]
                result = data[4]
            except IndexError:
                self._display_message(
                    'Missing local file path or remote file name')
                return False

            if not os.path.isfile(file_path):
                self._display_message('This file does not exist')
                return False

            file_size = os.path.getsize(file_path) / 1024
            self.prv_logger.trace('Uploading file: %s (%d KB)' %
                                  (filename, file_size))
            self.transport.write(
                'upload %s %s %s %s\n' %
                (filename, get_file_md5_hash(self.prv_logger,
                                             file_path), cmdid, result))
            self.setRawMode()

            for bytes in read_bytes_from_file(file_path):
                self.transport.write(bytes)

            self.transport.write('\r\r\r\r\n')

            # When the transfer is finished, we go back to the line mode
            self.setLineMode()
            return True
        else:
            self.prv_logger.error("invalid cmd:%s" % command)
            return False
コード例 #12
0
    def _sendCommand(self, line):
	global setSynchronize, synchronized
        """ Sends a command to the server. """

        data = clean_and_split_input(line)
        if len(data) == 0 or data == '':
            return
	
	command = data[0].lower()

        if not command in COMMANDS:
            self._display_message('Invalid command')
            return

        '''TLast
        if command == 'list' or command == 'help' or command == 'quit':
            self.connection.transport.write('%s %s\n' % (command, self.username))
        '''

	if command == 'help':
	    if self.logged_in == False:
		self._display_message('Type login [username] [password] to login OR type register [username] [password] [user/admin] to register')
		return
            self.connection.transport.write('%s %s\n' % (command, self.username))

	elif command == 'list':
	    if self.logged_in == False:
		self._display_message('You must be logged in')
		return
            self.connection.transport.write('%s %s\n' % (command, self.username))
	
	elif command == 'registry':
	    if self.logged_in == False:
		self._display_message('You must be logged in')
		return
            self.connection.transport.write('%s %s\n' % (command, self.username))

	elif command == 'register':
	    if self.logged_in == True:
		self._display_message('You must log out to register a new user')
		return
	    try:
		username = data[1]
		password = data[2]
		role = data[3]
		
	    except IndexError:
                self._display_message('Missing username or password')
		return

            self.connection.transport.write('%s %s %s %s %s\n' % (command, username, password, role, self.username))
	
	elif command == 'change_password':
	    if self.logged_in == False:
		self._display_message('You must be logged in')
		return
	    try:
	        username = data[1]
  		password = data[2]

	    except IndexError:
                self._display_message('Missing username or password')
		return
            self.connection.transport.write('%s %s %s %s\n' % (command, username, password, self.username))

	elif command == 'remove_user':
	    if self.logged_in == False:
		self._display_message('You must be logged in')
		return
	    try:
	        username = data[1]
	    except IndexError:
                self._display_message('Missing username')
		return
            self.connection.transport.write('%s %s %s\n' % (command, username, self.username))

	elif command == 'login':
	    if self.logged_in != False:
		self._display_message('You are already logged in. Log out to change users.')
		return
	    try:
		username = data[1]
		password = data[2]
	    except IndexError:
                self._display_message('Missing username or password')
		return
            self.connection.transport.write('%s %s %s %s\n' % (command, username, password, self.username))

	elif command == 'logout':
	    if self.logged_in != True:
		self._display_message('You are not logged into any account.')
		return
            self.connection.transport.write('%s %s\n' % (command, self.username))

#############################
        elif command == 'get':
	    if self.logged_in == False:
		self._display_message('You must be logged in')
		return
            try:
                filename = data[1]
            except IndexError:
                self._display_message('Missing filename')
                return
            
            self.connection.transport.write('%s %s %s\n' % (command, filename, self.username))

#############################
        elif command == 'put':

	    if self.logged_in == False:
		self._display_message('You must be logged in')
		return
            try:
                file_path = data[1]
                filename = data[2]
            except IndexError:
                self._display_message('Missing local file path or remote file name')
                return
            
            if not os.path.isfile(file_path):
                self._display_message('This file does not exist')
                return

            file_size = os.path.getsize(file_path) / 1024
            
            print 'Uploading file: %s (%d KB)' % (filename, file_size)
            
            self.connection.transport.write('PUT %s %s %s\n' % (filename, get_file_md5_hash(file_path), self.username))
            self.setRawMode()
            
            for bytes in read_bytes_from_file(file_path):
                self.connection.transport.write(bytes)
            
            self.connection.transport.write('\r\n')   
            
            # When the transfer is finished, we go back to the line mode 
            self.setLineMode()

#####################################
        elif command == 'rename':
            """renames file or directory src to dst and returns True if successful"""
	    if self.logged_in == False:
		self._display_message('You must be logged in.')
	        self._prompt()
            else:
                src = '';
                dst = '';
                input = clean_and_split_input(line)
                if len(input) == 3:
                    src = input[1];
                    dst = input[2];
                if os.path.isfile(src) or os.path.isdir(src):
                    try:
                        os.renames(src, dst)
                        print '%s renamed to %s' % (src, dst)
                        self._prompt()
                    except OSError, e:
                        print e
                        self._prompt()
                else:
                    print "%s does not exist" % src
                    self._prompt()
コード例 #13
0
ファイル: client_protocol.py プロジェクト: adamxu0220/SCT
    def _sendCommand(self, line):
        """ Sends a command to the server. """

        data = clean_and_split_input(line)
        if len(data) == 0 or data == '' or self.transport == None:
            return

        command = data[0].lower()
        if not command in COMMANDS:
            self._display_message('Invalid command:%s' % command)
            return

        if command == 'list' or command == 'help' or command == 'quit':
            self.transport.write('%s\n' % (command))
        elif command == 'get':
            try:
                src_filename = data[1]
                dst_filename = data[2]
            except IndexError:
                self._display_message('Missing filename')
                return

            self.transport.write('%s %s %s\n' %
                                 (command, src_filename, dst_filename))
        elif command == 'put':
            try:
                file_path = data[1]
                filename = data[2]
            except IndexError:
                self._display_message(
                    'Missing local file path or remote file name')
                return

            if not os.path.isfile(file_path):
                self._display_message('This file does not exist')
                return

            file_size = os.path.getsize(file_path) / 1024

            self.prv_logger.trace('Uploading file: %s (%d KB)' %
                                  (filename, file_size))

            self.transport.write(
                'PUT %s %s\n' %
                (filename, get_file_md5_hash(self.prv_logger, file_path)))
            self.setRawMode()

            for bytes in read_bytes_from_file(file_path):
                self.transport.write(bytes)

            self.transport.write('\r\r\r\r\n')

            # When the transfer is finished, we go back to the line mode
            self.setLineMode()
        elif command == 'download':
            try:
                src_filename = data[1]
                dst_filename = data[2]
            except IndexError:
                self._display_message('Missing filename')
                return
            self.prv_logger.trace('%s %s %s\n' %
                                  ("get", src_filename, dst_filename))
            self.transport.write('%s %s %s\n' %
                                 ("get", src_filename, dst_filename))
            self.prv_logger.trace('%s %s %s done\n' %
                                  ("get", src_filename, dst_filename))
        elif command == 'hb':
            self.transport.write('%s %s\n' % (command, ' '.join(data[1:])))
        else:
            self.transport.write('%s %s\n' % (command, data[1]))
コード例 #14
0
                    except OSError, e:
                        print e
                        self._prompt()
                else:
                    print "%s does not exist" % src
                    self._prompt()

####################################
        elif command == 'delete':

	    if self.logged_in == False:
		self._display_message('You must be logged in.')
	        self._prompt()
            else:
                src = '';
                input = clean_and_split_input(line)
                if len(input) == 2:
                    src = input[1];
                    if os.path.isdir(src):
                        try:
                            shutil.rmtree(src)
                            print '%s removed' % src
                            self._prompt()
                        except OSError, e:
                            print e
                            self._prompt()
                        except shutil.Error, e:
                            print e
                            self._prompt()
                    elif os.path.isfile(src):
                        try:
コード例 #15
0
    def _sendCommand(self, line):
        """ Sends a command to the server. """

        data = clean_and_split_input(line)
        if len(data) == 0 or data == '':
            return

        command = data[0].lower()

        if not ((command in COMMANDS) or (command in RESPONSE)):
            self._display_message('Invalid command')
            return

        if command == 'list' or command == 'help' or command == "people" or command == 'quit':

            self.sender.transport.write('%s\n' % (command))

        if command == 'finger':
            try:
                nickname = data[1]
            except IndexError:
                self._display_message('Missing nickname')
                return

            self.sender.transport.write('%s %s\n' % (command, nickname))

        elif command == 'get':
            try:
                filename = data[1]
            except IndexError:
                self._display_message('Missing filename')
                return

            self.sender.transport.write('%s %s\n' % (command, filename))
        elif command == 'put':
            try:
                file_path = data[1]
                filename = data[2]
            except IndexError:
                self._display_message(
                    'Missing local file path or remote file name')
                return

            if not os.path.isfile(file_path):
                self._display_message('This file does not exist')
                return

            file_size = os.path.getsize(file_path) / 1024

            print('Uploading file: %s (%d KB)' % (filename, file_size))

            self.sender.transport.write(
                'PUT %s %s\n' % (filename, get_file_md5_hash(file_path)))
            self.sender.setRawMode()

            for bytes in read_bytes_from_file(file_path):
                self.sender.transport.write(bytes)

            self.sender.transport.write('\r\n')

            # When the transfer is finished, we go back to the line mode
            self.sender.setLineMode()

        elif command == 'sync':
            files = []
            files = [
                f for f in os.listdir(self.sender.factory.files_path)
                if os.path.isfile(
                    os.path.join(self.sender.factory.files_path, f))
            ]
            file_list = '#'.join(files)
            self.sender.transport.write('sync %s\n' % (file_list))

        elif command == 'search':
            try:
                filename = data[1]
            except IndexError:
                self._display_message('Missing filename')
                return

            if os.path.exists(
                    os.path.join(self.sender.factory.files_path, filename)):
                self._display_message(
                    'File already exists on your local folder')
                return

            self.sender.transport.write('search %s\n' % (filename))

        elif command == 'nick':
            try:
                subcommand = data[1]
                nick = data[2]
                passw = data[3]
            except IndexError:
                self._display_message(
                    'Missing subcommand {and\or} nick {and\or} password')
                return

            self.sender.transport.write('nick %s %s %s\n' %
                                        (subcommand, nick, passw))

        elif command == 'recv':
            self.sender.transport.write('%s %s\n' % (command, data[1]))
コード例 #16
0
ファイル: onedir3_client.py プロジェクト: dwd4bc/Team3_repo
    def _sendCommand(self, line):
        """ Sends a command to the server. """
        
        data = clean_and_split_input(line) 
        if len(data) == 0 or data == '':
            return 

        command = data[0].lower()
        if not command in COMMANDS:
            self._display_message('Invalid command')
            return
        
        if command == 'list' or command == 'help' or command == 'quit':
            self.connection.transport.write('%s\n' % (command))

	elif command == 'register':
	    try:
		username = data[1]
		password = data[2]
	    except IndexError:
                self._display_message('Missing username or password')
		return
            self.connection.transport.write('%s %s %s\n' % (command, username, password))

	elif command == 'login':
	    try:
		username = data[1]
		password = data[2]
	    except IndexError:
                self._display_message('Missing username or password')
		return
            self.connection.transport.write('%s %s %s\n' % (command, username, password))

        elif command == 'get':
            try:
                filename = data[1]
            except IndexError:
                self._display_message('Missing filename')
                return
            
            self.connection.transport.write('%s %s\n' % (command, filename))
        elif command == 'put':
            try:
                file_path = data[1]
                filename = data[2]
            except IndexError:
                self._display_message('Missing local file path or remote file name')
                return
            
            if not os.path.isfile(file_path):
                self._display_message('This file does not exist')
                return

            file_size = os.path.getsize(file_path) / 1024
            
            print 'Uploading file: %s (%d KB)' % (filename, file_size)
            
            self.connection.transport.write('PUT %s %s\n' % (filename, get_file_md5_hash(file_path)))
            self.setRawMode()
            
            for bytes in read_bytes_from_file(file_path):
                self.connection.transport.write(bytes)
            
            self.connection.transport.write('\r\n')   
            
            # When the transfer is finished, we go back to the line mode 
            self.setLineMode()
        elif command == 'rename':
            """renames file or directory src to dst and returns True if successful"""
            src = '';
            dst = '';
            input = clean_and_split_input(line)
            if len(input) == 3:
                src = input[1];
                dst = input[2];
            if os.path.isfile(src) or os.path.isdir(src):
                try:
                    os.renames(src,dst)
                    return True
		except OSError, e:
                    print e
                    return False
            else: 
		print "%s does not exist" % src
		return False
コード例 #17
0
ファイル: client.py プロジェクト: ananya1122/SharePy
    def _sendCommand(self, line):
        """ Sends a command to the server. """
        
       
        data = clean_and_split_input(line) 
        if len(data) == 0 or data == '':
            return 

        command = data[0].lower()
        
        
		
        if not ((command in COMMANDS ) or(command in RESPONSE ) ):
            self._display_message('Invalid command')
            return
        
        if command == 'list' or command == 'help' or command == "people" or command == 'quit':
            
            self.connection.transport.write('%s\n' % (command))
        
        elif command == 'get':
            try:
                filename = data[1]
            except IndexError:
                self._display_message('Missing filename')
                return
            
            self.connection.transport.write('%s %s\n' % (command, filename))
        elif command == 'put':
            try:
                file_path = data[1]
                filename = data[2]
            except IndexError:
                self._display_message('Missing local file path or remote file name')
                return
            
            if not os.path.isfile(file_path):
                self._display_message('This file does not exist')
                return

            file_size = os.path.getsize(file_path) / 1024
            
            print 'Uploading file: %s (%d KB)' % (filename, file_size)
            
            self.connection.transport.write('PUT %s %s\n' % (filename, get_file_md5_hash(file_path)))
            self.setRawMode()
            
            for bytes in read_bytes_from_file(file_path):
                self.connection.transport.write(bytes)
            
            self.connection.transport.write('\r\n')   
            
            # When the transfer is finished, we go back to the line mode 
            self.setLineMode()
        
		
        elif command == 'sync' :
            files = []
            files = [ f for f in os.listdir(self.files_path) if os.path.isfile(os.path.join(self.files_path,f)) ]
            file_list = '#'.join(files)
            self.connection.transport.write('sync %s\n' % (file_list))
        
        elif command == 'nick' :
            try:
                subcommand = data[1]
                nick = data[2]
                passw = data[3]
            except IndexError:
                self._display_message('Missing subcommand {and\or} nick {and\or} password')
                return
				
            self.connection.transport.write('nick %s %s %s\n' % (subcommand, nick,passw))
			
        elif command == 'recv' :
            self.connection.transport.write('%s %s\n' % (command , data[1]))
        
        else:
            self.connection.transport.write('%s %s\n' % (command, data[1]))

        self.factory.deferred.addCallback(self._display_response)
        self.factory.deferred1.addCallback(self._display_response)