kindle manager

This commit is contained in:
douboer
2020-06-23 14:39:29 +08:00
parent d7672d9380
commit 6aed9982f6

15
kman.py
View File

@@ -568,15 +568,24 @@ class kMan:
# not test for windows & linux # not test for windows & linux
with subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, \ with subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, \
stderr=subprocess.PIPE, bufsize=-1) as s: stderr=subprocess.PIPE, bufsize=-1) as s:
stream_stdout = io.TextIOWrapper(s.stdout, encoding='utf-8') #Windows:
stream_stderr = io.TextIOWrapper(s.stderr, encoding='utf-8') # UnicodeDecodeError: 'utf-8' codec can't decode byte 0xd0 in position 48:
# invalid continuation byte
#stream_stdout = io.TextIOWrapper(s.stdout, encoding='utf-8')
#stream_stderr = io.TextIOWrapper(s.stderr, encoding='utf-8')
stream_stdout = io.TextIOWrapper(s.stdout, encoding='GBK')
stream_stderr = io.TextIOWrapper(s.stderr, encoding='GBK')
sout = str(stream_stdout.read()) sout = str(stream_stdout.read())
#serr = str(stream_stderr.read()) #serr = str(stream_stderr.read())
#if sout: print('stdout {}'.format(sout)) #if sout: print('stdout {}'.format(sout))
#if serr: print('stderr {}'.format(serr)) #if serr: print('stderr {}'.format(serr))
print('os.name {} sout {}'.format(os.name,sout))
if os.name == 'nt': # windows if os.name == 'nt': # windows
for d in sout.split('\n'): for d in sout.split('\n'):
if 'Kindle' in d: return d.split('\s+')[0] if 'Kindle' in d:
p = re.split(r'\s+',d)[0]
print('path {}'.format(p))
return p
elif os.name == 'posix': # mac os elif os.name == 'posix': # mac os
if sout: return('/Volumes/Kindle/') if sout: return('/Volumes/Kindle/')
else: else: