This commit is contained in:
Kovid Goyal 2012-08-12 22:29:51 +05:30
parent 7214c96fd3
commit 3c8450f620
3 changed files with 47 additions and 10 deletions

View File

@ -7,9 +7,9 @@ __license__ = 'GPL v3'
__copyright__ = '2012, Kovid Goyal <kovid at kovidgoyal.net>' __copyright__ = '2012, Kovid Goyal <kovid at kovidgoyal.net>'
__docformat__ = 'restructuredtext en' __docformat__ = 'restructuredtext en'
import subprocess, sys, os import subprocess, sys, os, pprint
def build(): def build(mod='wpd'):
builder = subprocess.Popen('ssh xp_build ~/build-wpd'.split()) builder = subprocess.Popen('ssh xp_build ~/build-wpd'.split())
syncer = subprocess.Popen('ssh getafix ~/test-wpd'.split()) syncer = subprocess.Popen('ssh getafix ~/test-wpd'.split())
if builder.wait() != 0: if builder.wait() != 0:
@ -17,9 +17,9 @@ def build():
if syncer.wait() != 0: if syncer.wait() != 0:
raise Exception('Failed to rsync to getafix') raise Exception('Failed to rsync to getafix')
subprocess.check_call( subprocess.check_call(
'scp xp_build:build/calibre/src/calibre/plugins/wpd.pyd /tmp'.split()) ('scp xp_build:build/calibre/src/calibre/plugins/%s.pyd /tmp'%mod).split())
subprocess.check_call( subprocess.check_call(
'scp /tmp/wpd.pyd getafix:calibre/src/calibre/devices/mtp/windows'.split()) ('scp /tmp/%s.pyd getafix:calibre/src/calibre/devices/mtp/windows'%mod).split())
p = subprocess.Popen( p = subprocess.Popen(
'ssh getafix calibre-debug -e calibre/src/calibre/devices/mtp/windows/remote.py'.split()) 'ssh getafix calibre-debug -e calibre/src/calibre/devices/mtp/windows/remote.py'.split())
p.wait() p.wait()
@ -27,7 +27,6 @@ def build():
def main(): def main():
import pprint
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
import wpd import wpd
from calibre.constants import plugins from calibre.constants import plugins
@ -41,6 +40,44 @@ def main():
finally: finally:
wpd.uninit() wpd.uninit()
if __name__ == '__main__': def winutil():
main() sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
del sys.modules['winutil']
import winutil
from calibre.constants import plugins
plugins._plugins['winutil'] = (winutil, '')
sys.path.pop(0)
print (winutil.serial_number_from_drive('F'))
def get_subkeys(key):
import _winreg
index = -1
while True:
index += 1
try:
yield _winreg.EnumKey(key, index)
except OSError:
break
def get_values(key):
import _winreg
index = -1
while True:
index +=1
try:
yield _winreg.EnumValue(key, index)
except OSError:
break
def test():
vid, pid = 0x1949, 0x4
import _winreg as r
usb = r.OpenKey(r.HKEY_LOCAL_MACHINE, 'SYSTEM\\CurrentControlSet\\Enum\\USB')
q = ('vid_%4.4x&pid_%4.4x'%(vid, pid))
dev = r.OpenKey(usb, q)
print (list(get_subkeys(dev)))
if __name__ == '__main__':
# main()
winutil()

View File

@ -33,13 +33,12 @@ PyObject *wpd::hresult_set_exc(const char *msg, HRESULT hr) {
wchar_t *wpd::unicode_to_wchar(PyObject *o) { wchar_t *wpd::unicode_to_wchar(PyObject *o) {
wchar_t *buf; wchar_t *buf;
Py_ssize_t len; Py_ssize_t len;
if (!PyUnicode_Check(o)) {PyErr_Format(PyExc_TypeError, "The pnp id must be a unicode object"); return NULL;} if (!PyUnicode_Check(o)) {PyErr_Format(PyExc_TypeError, "The python object must be a unicode object"); return NULL;}
len = PyUnicode_GET_SIZE(o); len = PyUnicode_GET_SIZE(o);
if (len < 1) {PyErr_Format(PyExc_TypeError, "The pnp id must not be empty."); return NULL;}
buf = (wchar_t *)calloc(len+2, sizeof(wchar_t)); buf = (wchar_t *)calloc(len+2, sizeof(wchar_t));
if (buf == NULL) { PyErr_NoMemory(); return NULL; } if (buf == NULL) { PyErr_NoMemory(); return NULL; }
len = PyUnicode_AsWideChar((PyUnicodeObject*)o, buf, len); len = PyUnicode_AsWideChar((PyUnicodeObject*)o, buf, len);
if (len == -1) { free(buf); PyErr_Format(PyExc_TypeError, "Invalid pnp id."); return NULL; } if (len == -1) { free(buf); PyErr_Format(PyExc_TypeError, "Invalid python unicode object."); return NULL; }
return buf; return buf;
} }

View File

@ -148,6 +148,7 @@ wpd_device_info(PyObject *self, PyObject *args) {
if (!PyArg_ParseTuple(args, "O", &py_pnp_id)) return NULL; if (!PyArg_ParseTuple(args, "O", &py_pnp_id)) return NULL;
pnp_id = unicode_to_wchar(py_pnp_id); pnp_id = unicode_to_wchar(py_pnp_id);
if (wcslen(pnp_id) < 1) { PyErr_SetString(WPDError, "The PNP id must not be empty."); return NULL; }
if (pnp_id == NULL) return NULL; if (pnp_id == NULL) return NULL;
client_information = get_client_information(); client_information = get_client_information();