mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
add function to winutil to check for an active internet connection
This commit is contained in:
parent
833c54c5d2
commit
9d61fbe0d9
@ -143,7 +143,7 @@ extensions = [
|
|||||||
if iswindows:
|
if iswindows:
|
||||||
extensions.append(Extension('winutil',
|
extensions.append(Extension('winutil',
|
||||||
['calibre/utils/windows/winutil.c'],
|
['calibre/utils/windows/winutil.c'],
|
||||||
libraries=['shell32', 'setupapi'],
|
libraries=['shell32', 'setupapi', 'wininet'],
|
||||||
cflags=['/X']
|
cflags=['/X']
|
||||||
))
|
))
|
||||||
|
|
||||||
|
@ -51,11 +51,15 @@ wherever possible in this module.
|
|||||||
script being run. So to replace sys.argv, you should use
|
script being run. So to replace sys.argv, you should use
|
||||||
`if len(sys.argv) > 1: sys.argv[1:] = winutil.argv()[1-len(sys.argv):]`
|
`if len(sys.argv) > 1: sys.argv[1:] = winutil.argv()[1-len(sys.argv):]`
|
||||||
|
|
||||||
|
.. function:: internet_connected() -> Return True if there is an active
|
||||||
|
internet connection.
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#define UNICODE
|
#define UNICODE
|
||||||
#include <Windows.h>
|
#include <Windows.h>
|
||||||
|
#include <Wininet.h>
|
||||||
#include <Python.h>
|
#include <Python.h>
|
||||||
#include <structseq.h>
|
#include <structseq.h>
|
||||||
#include <timefuncs.h>
|
#include <timefuncs.h>
|
||||||
@ -771,6 +775,15 @@ gettmarg(PyObject *args, struct tm *p)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static PyObject *
|
||||||
|
winutil_internet_connected(PyObject *self, PyObject *args) {
|
||||||
|
DWORD flags;
|
||||||
|
BOOL ans = InternetGetConnectedState(&flags, 0);
|
||||||
|
if (ans) Py_RETURN_TRUE;
|
||||||
|
Py_RETURN_FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
winutil_strftime(PyObject *self, PyObject *args)
|
winutil_strftime(PyObject *self, PyObject *args)
|
||||||
{
|
{
|
||||||
@ -919,6 +932,10 @@ be a unicode string. Returns unicode strings."
|
|||||||
"eject_drive(drive_letter)\n\nEject a drive. Raises an exception on failure."
|
"eject_drive(drive_letter)\n\nEject a drive. Raises an exception on failure."
|
||||||
},
|
},
|
||||||
|
|
||||||
|
{"internet_connected", winutil_internet_connected, METH_VARARGS,
|
||||||
|
"internet_connected()\n\nReturn True if there is an active internet connection"
|
||||||
|
},
|
||||||
|
|
||||||
{NULL, NULL, 0, NULL}
|
{NULL, NULL, 0, NULL}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user