Skip to content

Commit a1648a6

Browse files
committed
Fix uploading files under a different name
1 parent bccdb84 commit a1648a6

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

chdkptp/device.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
from chdkptp.lua import LuaContext, PTPError, global_lua, parse_table
99
import chdkptp.util as util
1010

11+
from lupa import LuaError
12+
1113

1214
DISTANCE_RE = re.compile('(\d+(?:.\d+)?)(mm|cm|m|ft|in)')
1315
DISTANCE_FACTORS = {
@@ -219,12 +221,13 @@ def upload_file(self, local_path, remote_path='A/', skip_checks=False):
219221
if os.path.isdir(local_path):
220222
raise ValueError("`local_path` must be a file, not a directory.")
221223
if not skip_checks:
222-
status, error = self._lua.call("con:stat", remote_path)
223-
if not status:
224-
raise Exception("Stat on remote path '{0}' failed: {1}"
225-
.format(remote_path, error))
226224
if remote_path.endswith("/"):
227-
if not status.is_dir:
225+
try:
226+
status = parse_table(
227+
self._lua.call("con:stat", remote_path))
228+
except LuaError:
229+
status = {'is_dir': False}
230+
if not status['is_dir']:
228231
raise ValueError("Remote path '{0}' is not a directory. "
229232
"Please leave out the trailing slash if "
230233
"you are refering to a file")

test.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,13 @@
4242
imgdata = dev.shoot(stream=False, download_after=True, remove_after=True)
4343
with open(fpath, 'wb') as fp:
4444
fp.write(imgdata)
45+
46+
print "Checking file upload"
47+
with open('/tmp/test.txt', 'w') as fp:
48+
fp.write('test')
49+
dev.upload_file('/tmp/test.txt', 'A/')
50+
assert 'a/test.txt' in [x.lower() for x in dev.list_files()]
51+
52+
print "Checking file removal"
53+
dev.delete_files('A/test.txt')
54+
assert 'a/test.txt' not in [x.lower() for x in dev.list_files()]

0 commit comments

Comments
 (0)