#!/usr/bin/env python

# A simple script for copying bencode.hpp to mettle's include directory. This
# eliminates the need for users to manually download bencode.hpp if they don't
# want to.

import os
import shutil
import tarfile
from io import BytesIO

try:
    from urllib.request import urlopen
except ImportError:
    from urllib import urlopen

srcdir = os.path.normpath(os.path.join(__file__, '..',  '..'))

commit = '3164da8db451b434837f9be1e5ad773e6f3e6a20'
bencode_name = 'bencode.hpp-{}'.format(commit)
bencode_url = ('https://github.com/jimporter/bencode.hpp/archive/{}.tar.gz'
               .format(commit))

if __name__ == '__main__':
    print('Fetching {}'.format(bencode_url))
    f = urlopen(bencode_url)

    with tarfile.open(mode='r:gz', fileobj=BytesIO(f.read())) as tar:
        src_name = '{}/include/bencode.hpp'.format(bencode_name)
        print('Extracting {}'.format(src_name))
        src = tar.extractfile(src_name)

        dst_name = os.path.join(srcdir, 'include', 'bencode.hpp')
        with open(dst_name, 'wb') as dst:
            print('Copying to {}'.format(dst_name))
            shutil.copyfileobj(src, dst)

#!/usr/bin/env python

# A simple script for copying bencode.hpp to mettle's include directory. This
# eliminates the need for users to manually download bencode.hpp if they don't
# want to.

import os
import shutil
import tarfile
from io import BytesIO

try:
    from urllib.request import urlopen
except ImportError:
    from urllib import urlopen

srcdir = os.path.normpath(os.path.join(__file__, '..',  '..'))

commit = 'fd1b6d1e76affd02dcc89b1bbcf2feef95e969da'
bencode_name = 'bencode.hpp-{}'.format(commit)
bencode_url = ('https://github.com/jimporter/bencode.hpp/archive/{}.tar.gz'
               .format(commit))

if __name__ == '__main__':
    print('Fetching {}'.format(bencode_url))
    f = urlopen(bencode_url)

    with tarfile.open(mode='r:gz', fileobj=BytesIO(f.read())) as tar:
        src_name = '{}/include/bencode.hpp'.format(bencode_name)
        print('Extracting {}'.format(src_name))
        src = tar.extractfile(src_name)

        dst_name = os.path.join(srcdir, 'include', 'bencode.hpp')
        with open(dst_name, 'wb') as dst:
            print('Copying to {}'.format(dst_name))
            shutil.copyfileobj(src, dst)

Update bencode