I appreciate your help PyTom!!! I implemented both systems in my game (using "wget" for Windows version and "requests" for Android.
For those who dare to use
"wget" on Android, I have found the solution to prevent the module from throwing the exception
no module named 'termios'.
I started looking closely at the wget code (wget.py) until I found the exact point that asks to import
"termios". You can definitely use wget without the need to have "termios".
All of this leads me to this function:
Code: Select all
def get_console_width():
"""Return width of available window area. Autodetection works for
Windows and POSIX platforms. Returns 80 for others
Code from http://bitbucket.org/techtonik/python-pager
"""
if os.name == 'nt':
STD_INPUT_HANDLE = -10
STD_OUTPUT_HANDLE = -11
STD_ERROR_HANDLE = -12
# get console handle
from ctypes import windll, Structure, byref
try:
from ctypes.wintypes import SHORT, WORD, DWORD
except ImportError:
# workaround for missing types in Python 2.5
from ctypes import (
c_short as SHORT, c_ushort as WORD, c_ulong as DWORD)
console_handle = windll.kernel32.GetStdHandle(STD_OUTPUT_HANDLE)
# CONSOLE_SCREEN_BUFFER_INFO Structure
class COORD(Structure):
_fields_ = [("X", SHORT), ("Y", SHORT)]
class SMALL_RECT(Structure):
_fields_ = [("Left", SHORT), ("Top", SHORT),
("Right", SHORT), ("Bottom", SHORT)]
class CONSOLE_SCREEN_BUFFER_INFO(Structure):
_fields_ = [("dwSize", COORD),
("dwCursorPosition", COORD),
("wAttributes", WORD),
("srWindow", SMALL_RECT),
("dwMaximumWindowSize", DWORD)]
sbi = CONSOLE_SCREEN_BUFFER_INFO()
ret = windll.kernel32.GetConsoleScreenBufferInfo(
console_handle, byref(sbi))
if ret == 0:
return 0
return sbi.srWindow.Right+1
elif os.name == 'posix':
from fcntl import ioctl
from termios import TIOCGWINSZ
from array import array
winsize = array("H", [0] * 4)
try:
ioctl(sys.stdout.fileno(), TIOCGWINSZ, winsize)
except IOError:
pass
return (winsize[1], winsize[0])[0]
return 80
This function returns a value to define the width of the window, in order to show a progress bar in the console / terminal / interpreter.
This is somewhat irrelevant to the Ren'Py code that I am using at the moment.
Just pay attention to what the text at the beginning of the function tells us:
Code: Select all
"""Return width of available window area. Autodetection works for
Windows and POSIX platforms. Returns 80 for others
Code from http://bitbucket.org/techtonik/python-pager
"""
When using "wget" in Android, it detects Android as a
POSIX platform, which is completely natural if you understand the architecture of Android.
This function returns
80 when neither platform (NT or POSIX) is detected.
A simple change that will make "wget" work, would be to eliminate much of the code in this function, making it always return the value 80 when it is called. The function that I showed previously, should simply look like this:
Code: Select all
def get_console_width():
"""Return width of available window area. Autodetection works for
Windows and POSIX platforms. Returns 80 for others
Code from http://bitbucket.org/techtonik/python-pager
"""
return 80
This does not affect the main operation of the module or the code that I implemented in Ren'Py (with the help of more people). Downloads are successful and the progress bar in Ren'Py continues to work as expected.
Hope this helps other folks experimenting with Android downloads using "wget". My main intention to implement the downloads on Android was so that the player, at the end of the game, can obtain DLCs and "patch" the game through the Android public path.