orphilia-dropbox
orphilia-dropbox copied to clipboard
Some hacks
I had various problems which I worked around in a probably ugly and incorrect way.
- "delta" mode wants to delete files from the remote on first download. I commented that out, probably a "readonly" mode would be nice to have (only fetch from remote, do not upload)?
- I had problems with strptime trying to parse month names in french (my locale) and not handling english dates returned by dropbox API. Setting the locale fixes that
- I changed the exception handling a bit so it continues if a file fails to download.
- I removed the "has_more" check from the main delta loop, so all files are checked. I think this makes shared folders work, as their items come after the rest in the list (possibly fixes #2).
- I have some issues with some files failing to create here, but I didn't find why. Also some folders got converted to all-caps, which was unexpected.
diff --git a/modules/orphiliaclient/client.py b/modules/orphiliaclient/client.py
index 6bc1715..1abd103 100644
--- a/modules/orphiliaclient/client.py
+++ b/modules/orphiliaclient/client.py
@@ -112,7 +112,7 @@ class Node(object):
def apply_delta(root, e):
queue = Queue.Queue(0)
path, metadata = e
- branch, leaf = split_path(path)
+ branch, leaf = split_path(path.encode("utf-8"))
if metadata is not None:
print(' + ' + path.encode("utf-8"))
@@ -142,10 +142,7 @@ def apply_delta(root, e):
node.content = metadata['size'], metadata['modified']
tmp = [ 'sync', node.path]
if delta_switch == 0:
- try:
- queue.put(client(tmp))
- except:
- print(" x Something went wrong. Unable to get file.")
+ queue.put(client(tmp))
else:
print(' - ' + path.encode("utf-8"))
if delta_switch == 0:
@@ -226,6 +223,8 @@ sess = StoredSession(APP_KEY, APP_SECRET, access_type=ACCESS_TYPE)
api_client = client.DropboxClient(sess)
sess.load_creds()
+locale.setlocale(locale.LC_ALL, locale.normalize('C'))
+
def client(parameters):
cmd = parameters[0]
@@ -283,7 +282,7 @@ def client(parameters):
print("Current entry: "+str(progress)+"/"+str(total))
apply_delta(tree, delta_entry)
cursor = result['cursor']
- if not result['has_more']: break
+ #if not result['has_more']: break
if not changed:
sys.stdout.write('No updates.\n')
@@ -359,16 +358,15 @@ def client(parameters):
resp = api_client.metadata(from_path)
modified = resp['modified']
- open(os.path.expanduser(to_path), 'rb')
date1 = time.mktime(datetime.datetime.strptime(modified, "%a, %d %b %Y %H:%M:%S +0000").timetuple())
f = api_client.get_file("/" + from_path)
- file = open(to_path,"wb")
try:
+ file = open(to_path,"wb")
file.write(f.read())
+ file.close()
+ os.utime(os.path.normpath(to_path),(date1,date1))
except:
print(" x Unable to save file.")
- file.close()
- os.utime(os.path.normpath(to_path),(date1,date1))
elif cmd == "sync":
path = parameters[1]
@@ -381,22 +379,25 @@ def client(parameters):
except:
change = 'add'
- localTime = os.path.getmtime(localPath)
+ try:
+ localTime = os.path.getmtime(localPath)
+ except:
+ localTime = 0
if (change != 'add'):
dropboxTime = time.mktime(datetime.datetime.strptime(modified, "%a, %d %b %Y %H:%M:%S +0000").timetuple())
-
+
if ((change != 'add') and (localTime < dropboxTime)):
tmp = ['get',path,localPath]
client(tmp)
elif ((change != 'add') and (localTime == dropboxTime)):
print(" > No need to update. localTime: " + str(localTime) + " = dropboxTime: " + str(dropboxTime))
- else:
- if (change != 'add'):
- tmp = ['rm', path]
- client(tmp)
- tmp = ['put',localPath,path,change]
- client(tmp)
+ #else:
+ # if (change != 'add'):
+ # tmp = ['rm', path]
+ # client(tmp)
+ # tmp = ['put',localPath,path,change]
+ # client(tmp)
print(" > Command '" + parameters[0] + "' executed")
@pulkomandy thank you! could you fork this repo, commit these changes to it and then make a pull request back into this repo? i'm sure @ksiazkowicz will accept :)
I'm looking into your issues/changes right now.
""delta" mode wants to delete files from the remote on first download. I commented that out, probably a "readonly" mode would be nice to have (only fetch from remote, do not upload)?" Oh well... It actually thinks that you're UPDATING that file, for reasons that are hard for me to understand because that part is so poorly written. I probably just copy-pasted it from the first version of client I wrote years ago when my understanding of python was... uhm, wasn't.