예제 #1
0
파일: client.py 프로젝트: RyanJenkins/YASA
    def do_push(self):
        logging.info('Starting push process')

        cursor = self._conn.cursor()
        since = (utils.read_settings(self._conn, 'last_update')
                      .get('last_update', 0))

        cursor.execute('SELECT * FROM files WHERE server_id IS NULL')
        add_files = cursor.fetchall()

        cursor.execute('SELECT * FROM deleted WHERE del_time>?', [since])
        rem_files = cursor.fetchall()

        logging.info('Notifying server %d new files and %d old ones' %
                     (len(add_files), len(rem_files)))

        for record in add_files:
            response = self.communicate({'ACTION': 'PUSH',
                                         'TYPE': 'NEW'})
            cursor.execute('UPDATE files SET server_id=? WHERE id=?',
                           [int(response['ID']), record['id']])

            utils.push_file(record['path'], self._socket, 
                            hash_code=record['hash'].decode('hex'))

            # Read off the server's reply, since this didn't go through the
            # communicate method we have to do it ourselves.
            next(self._responses)

        for record in rem_files:
            response = self.communicate({'ACTION': 'PUSH',
                                         'TYPE': 'DELETE',
                                         'ID': record['server_id']})

        logging.info('...finished push process')
예제 #2
0
파일: server.py 프로젝트: RyanJenkins/YASA
    def pull_file_command(self, command, session):
        """
        Serves the file with a specified server ID to the client.
        """
        cursor = self._conn.cursor()
        sid = int(command['ID'])
        cursor.execute('SELECT path, hash FROM files WHERE id=?', [sid])
        record = cursor.fetchone()

        utils.push_file(record['path'], self._socket,
                        hash_code=record['hash'].decode('hex'))

        return None, session