Robot-Will / Stino

A Sublime Text Plugin for Arduino
Other
1.58k stars 250 forks source link

Proxy Support ? #508

Open bousqi opened 5 years ago

bousqi commented 5 years ago

I'm facing issue to use Stino Package as my computer must pass through a proxy. When I pick a board after the installation, the package tries to fetch all missing dependencies but without any success :

[http://downloads.arduino.cc/tools/avr-gcc-4.9.2-atmel3.5.4-arduino2-i686-mingw32.zip] Waiting for download...
[http://downloads.arduino.cc/tools/avrdude-6.3.0-arduino9-i686-w64-mingw32.zip] Waiting for download...
[http://downloads.arduino.cc/tools/arduinoOTA-1.1.1-windows_386.zip] Waiting for download...

In fact, it internally fails. Is there any simple solution to add proxy support ?

I've been looking into package sources, and I feel (not sure at all) that downloader.py must be modified to fix it.

bousqi commented 5 years ago

I managed to make a quick and DIRTY, MEGA DIRTY workaround. If someone is inspired to make something better :

def download(url, target_dir,
             message_consumer=sys.stdout.write, mode='resume'):
    """."""
    is_done = False
    trunk_size = 1024
    done_size = 0
    is_msg_quiet = True

    file_name = os.path.basename(url)
    target_file_path = os.path.join(target_dir, file_name)
    tmp_file_path = target_file_path + '.stino-down'

    proxies = {'http': 'http://IP.IP.IP.IP:PORT',
               'https': 'https://IP.IP.IP.IP:PORT'}

    proxy_handler = urllib.request.ProxyHandler(proxies)
    opener = urllib.request.build_opener(proxy_handler)
    urllib.request.install_opener(opener)

    remote_info = get_remote_file_info(url)
    remote_size = int(remote_info.get('Content-Length', '0'))

Main issue with that solution is that it can't work with HTTPS urls as a install_opener will replace the proxy handler.