'Trigger a sync, wait for completion'

def _update_device(self, msg='', wait=True):

    if self.verbose:
        logger().info(('    %s:_update_device():\n    %s' % (self.__class__.__name__, msg)))
    if isosx:
        self.iTunes.update()
        if wait:
            if self.verbose:
                sys.stdout.write('        waiting    for    iPad    sync    to    complete    ...')
                sys.stdout.flush()
            while (len(self._get_device_books()) != (len(self._get_library_books()) + len(self._get_purchased_book_ids()))):
                if self.verbose:
                    sys.stdout.write('.')
                    sys.stdout.flush()
                time.sleep(2)
            print
    elif iswindows:
        import pythoncom, win32com.client
        try:
            pythoncom.CoInitialize()
            self.iTunes = win32com.client.Dispatch('iTunes.Application')
            self.iTunes.UpdateIPod()
            if wait:
                if self.verbose:
                    sys.stdout.write('        waiting    for    iPad    sync    to    complete    ...')
                    sys.stdout.flush()
                while True:
                    db_count = len(self._get_device_books())
                    lb_count = len(self._get_library_books())
                    pb_count = len(self._get_purchased_book_ids())
                    if (db_count != (lb_count + pb_count)):
                        if self.verbose:
                            sys.stdout.write('.')
                            sys.stdout.flush()
                        time.sleep(2)
                    else:
                        sys.stdout.write('\n')
                        sys.stdout.flush()
                        break
        finally:
            pythoncom.CoUninitialize()
