#!/usr/bin/env python3
"""Push a local file to /var/mobile/Media on the RootHide device via AFC."""
import asyncio, sys, time, os

sys.stdout.reconfigure(encoding='utf-8')
from pymobiledevice3.lockdown import create_using_usbmux
from pymobiledevice3.services.afc import AfcService

UDID = '2f04999241eb80cae2d8a6176504af07002b86bd'


async def main():
    local, remote = sys.argv[1], sys.argv[2]
    size = os.path.getsize(local)
    print('pushing %s (%.1f MB) -> %s' % (local, size / 1e6, remote))
    ld = await create_using_usbmux(serial=UDID)
    async with AfcService(ld) as afc:
        t0 = time.time()
        await afc.push(local, remote, progress_bar=True)
        st = await afc.stat(remote)
        print('remote size:', st.get('st_size'), 'in %.1fs' % (time.time() - t0))
        if int(st.get('st_size', -1)) != size:
            print('SIZE MISMATCH')
        else:
            print('SIZE OK')


asyncio.run(main())
