def link(self): print(" > Authorizing...") request_token = self.obtain_request_token() url = self.build_authorize_url(request_token) # some code to make this fancy window with URL show up in Haiku OS # it's temporary btw. if sys.platform[:5] == "haiku": common.putIn( url, os.path.normpath(configurationDirectory + '/authorize-url'), 'rewrite') os.system("orphilia_haiku-authorize") os.system('rm ' + os.path.normpath(configurationDirectory + '/authorize-url')) else: print("url:" + url), raw_input() self.obtain_access_token(request_token) self.write_creds(self.token) save_state({ 'access_token': (request_token.key, request_token.secret), 'tree': {} })
def config(): if os.path.isdir(configurationDirectory): shutil.rmtree(configurationDirectory) os.makedirs(configurationDirectory) common.putIn('0',os.path.normpath(configurationDirectory+'/net-status'),'rewrite') print("Welcome to Orphilia, an open-source crossplatform Dropbox client.\nIn few steps, you will configure your Dropbox account to be used with Orphilia.") if sys.platform[:5] == "haiku": common.putIn('orphilia_haiku-notify',os.path.normpath(configurationDirectory+'/notify-settings'),'rewrite') else: notifier = raw_input("Enter notify method: ") common.putIn(notifier,os.path.normpath(configurationDirectory+'/notify-settings'),'rewrite') dropboxPath = raw_input("Dropbox folder location (optional):") if dropboxPath == "": dropboxPath = os.path.normpath(home + '/Dropbox') else: pass common.putIn(dropboxPath,os.path.normpath(configurationDirectory+'/dropbox-path'),'rewrite') if not os.path.exists(dropboxPath): os.makedirs(dropboxPath) print("Please wait. Orphilia is making configuration files.") import orphiliaclient tmp = [ 'uid', os.path.normpath(configurationDirectory+'/dropbox-id')] orphiliaclient.client.client(tmp) print("Configuration files has been created.")
def link(self): print(" > Authorizing...") request_token = self.obtain_request_token() url = self.build_authorize_url(request_token) # some code to make this fancy window with URL show up in Haiku OS if sys.platform[:5] == "haiku": common.putIn(url,os.path.normpath(configurationDirectory+'/authorize-url'),'rewrite') os.system("orphilia_haiku-authorize") os.system('rm ' + os.path.normpath(configurationDirectory+'/authorize-url')) else: print("url:"+ url), raw_input() self.obtain_access_token(request_token) self.write_creds(self.token) save_state({ 'access_token': (request_token.key, request_token.secret), 'tree': {} })
def config_gui(parameters): if os.path.isdir(configurationDirectory): shutil.rmtree(configurationDirectory) os.makedirs(configurationDirectory) common.putIn('0',os.path.normpath(configurationDirectory+'/net-status'),'rewrite') common.putIn('orphilia_haiku-notify',os.path.normpath(configurationDirectory+'/notify-settings'),'rewrite') dropboxPath = parameters[0] if dropboxPath == "default": dropboxPath = os.path.normpath(home + '/Dropbox') else: pass common.putIn(dropboxPath,os.path.normpath(configurationDirectory+'/dropbox-path'),'rewrite') if not os.path.exists(dropboxPath): os.makedirs(dropboxPath) os.system('orphilia --client \"uid \''+os.path.normpath(configurationDirectory+'/dropbox-id') + '\'\"')
def client(parameters): cmd = parameters[0] if cmd == "ls": path = parameters[1] to_file = parameters[2] resp = api_client.metadata(path) file = open(to_file,"w") if 'contents' in resp: for f in resp['contents']: name = os.path.basename(f['path']) encoding = locale.getdefaultlocale()[1] file.write(('%s\n' % name).encode(encoding)) file.close() if cmd == "share": param = parameters[1] f = api_client.share(param) url = str(f['url']) print(" > Generated link: " + url) elif cmd == "delta": state = load_state() cursor = state.get('cursor') tree = state['tree'] page = 0 changed = False page_limit = 15 try: delta_switch = parameter[1] except: delta_switch = 0 while (page_limit is None) or (page < page_limit): # Make an int for progress/total progress = 0 total = 0 # Get /delta results from Dropbox result = api_client.delta(cursor) page += 1 if result['reset'] == True: sys.stdout.write('reset\n') changed = True tree = {} cursor = result['cursor'] # Apply the entries one by one to our cached tree. for delta_entry in result['entries']: total = total+1 for delta_entry in result['entries']: changed = True progress = progress +1 print("Current entry: "+str(progress)+"/"+str(total)) apply_delta(tree, delta_entry) cursor = result['cursor'] if not result['has_more']: break if not changed: sys.stdout.write('No updates.\n') else: # Save state state['cursor'] = cursor state['tree'] = tree save_state(state) elif cmd == "put": from_path = parameters[1] to_path = parameters[2] notify = parameters[3] # it can be 'add' or 'upd' from_file = open(os.path.expanduser(from_path), 'rb') #try: api_client.put_file("/" + to_path, from_file) #except: # print(" x Unable to upload file. ") common.orphiliaNotify(notify,from_path) elif cmd == "unlink": sess.unlink() print(" > Unlinked :C") elif cmd == "cat": f = api_client.get_file("/" + path) stdout.write(f.read()) stdout.write("\n") elif cmd == "mkdir": path = parameters[1] try: api_client.file_create_folder("/" + path) except: print(" x Unable to make directory " + path) print(" > Directory \'" + path + "\' created") elif cmd == "rm": path = path_rewrite.rewritepath('posix',parameters[1]) try: api_client.file_delete("/" + path) common.orphiliaNotify('rm',path) except: print(" x Unable to remove file " + path) elif cmd == "mv": from_path = parameters[1] to_path = parameters[2] try: api_client.file_move("/" + from_path, "/" + to_path) except: print(" x Unable to move file " + from_path + " to " + to_path) elif cmd == "account_info": f = api_client.account_info() pprint.PrettyPrinter(indent=2).pprint(f) elif cmd == "uid": param = parameters[1] f = api_client.account_info() uid = str(f['uid']) try: common.putIn(uid,param,'rewrite') except: print(" x Unable to save file.") print(" > UID updated") elif cmd == "get": from_path = parameters[1] to_path = parameters[2] resp = api_client.metadata(from_path) modified = resp['modified'] try: open(os.path.expanduser(to_path), 'rb') except: pass 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,"w+") try: file.write(f.read()) except: print(" x Unable to save file.") file.close() os.utime(os.path.normpath(to_path),(date1,date1)) elif cmd == "sync": path = parameters[1] localPath = os.path.normpath(dropboxPath + '/' + path) change = 'upd' try: resp = api_client.metadata(path) modified = resp['client_mtime'] except: change = 'add' 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) print(" > Command '" + parameters[0] + "' executed")
def client(parameters): cmd = parameters[0] if cmd == "ls": path = parameters[1] to_file = parameters[2] resp = api_client.metadata(path) file = open(to_file, "w") if 'contents' in resp: for f in resp['contents']: name = os.path.basename(f['path']) encoding = locale.getdefaultlocale()[1] file.write(('%s\n' % name).encode(encoding)) file.close() elif cmd == "delta": state = load_state() cursor = state.get('cursor') tree = state['tree'] page = 0 changed = False page_limit = 5 try: delta_switch = parameter[1] except: delta_switch = 0 while (page_limit is None) or (page < page_limit): # Get /delta results from Dropbox result = api_client.delta(cursor) page += 1 if result['reset'] == True: sys.stdout.write('reset\n') changed = True tree = {} cursor = result['cursor'] # Apply the entries one by one to our cached tree. for delta_entry in result['entries']: changed = True apply_delta(tree, delta_entry) cursor = result['cursor'] if not result['has_more']: break if not changed: sys.stdout.write('No updates.\n') else: # Save state state['cursor'] = cursor state['tree'] = tree save_state(state) elif cmd == "put": from_path = parameters[1] to_path = parameters[2] notify = parameters[3] # it can be 'add' or 'upd' from_file = open(os.path.expanduser(from_path), 'rb') #try: api_client.put_file("/" + to_path, from_file) #except: # print(" x Unable to upload file. ") common.orphiliaNotify(notify, from_path) elif cmd == "unlink": sess.unlink() print(" > Unlinked :C") elif cmd == "cat": f = api_client.get_file("/" + path) stdout.write(f.read()) stdout.write("\n") elif cmd == "mkdir": path = parameters[1] try: api_client.file_create_folder("/" + path) except: print(" x Unable to make directory " + path) print(" > Directory \'" + path + "\' created") elif cmd == "rm": path = path_rewrite.rewritepath('posix', parameters[1]) try: api_client.file_delete("/" + path) common.orphiliaNotify('rm', path) except: print(" x Unable to remove file " + path) elif cmd == "mv": from_path = parameters[1] to_path = parameters[2] try: api_client.file_move("/" + from_path, "/" + to_path) except: print(" x Unable to move file " + from_path + " to " + to_path) elif cmd == "account_info": f = api_client.account_info() pprint.PrettyPrinter(indent=2).pprint(f) elif cmd == "uid": param = parameters[1] f = api_client.account_info() uid = str(f['uid']) try: common.putIn(uid, param, 'rewrite') except: print(" x Unable to save file.") print(" > UID updated") elif cmd == "get": from_path = parameters[1] to_path = parameters[2] try: open(os.path.expanduser(to_path), 'rb') except: resp = api_client.metadata(from_path) modified = resp['modified'] date1 = modified[5:] date1 = date_rewrite.generate_modifytime(date1) f = api_client.get_file("/" + from_path) file = open(to_path, "wb") try: file.write(f.read()) except: print(" x Unable to save file.") file.close() if sys.platform[:5] != "win32": os.system("touch -d \"" + date1 + "\" \"" + to_path + "\"") # this solution won't work on Windows elif cmd == "sync_folder": path = parameters[1] resp = api_client.metadata( path) # gets list of files in directory on Dropbox dirlist = os.listdir( dropboxPath + "/" + path) # gets list of files in directory on local computer rand1 = random.random() # generates random integer queue = Queue.Queue(0) if 'contents' in resp: # begin comparing both lists for f in resp['contents']: name = os.path.basename(f['path']) encoding = locale.getdefaultlocale()[1] if ('%s' % name).encode( encoding ) not in dirlist: # found Dropbox file, which isn't present on local computer print('%s' % name).encode(encoding) + " not found." if not os.path.isfile(('%s' % name).encode(encoding)): dir = f['is_dir'] if not dir: tmp = [ 'get', path + "/" + name, dropboxPath + "/" + path + name ] queue.put(client_new(tmp)) if dir: os.mkdir(dropboxPath + "/" + path + ('%s' % name).encode(encoding)) else: # found Dropbox file which is present on local computer, check this out, bro! name = os.path.basename(f['path']) encoding = locale.getdefaultlocale()[1] print(('%s' % name).encode(encoding) + " found. Checking...") print(" > Command '" + parameters[0] + "' executed")
def client(parameters): cmd = parameters[0] if cmd == "ls": path = parameters[1] to_file = parameters[2] resp = api_client.metadata(path) file = open(to_file,"w") if 'contents' in resp: for f in resp['contents']: name = os.path.basename(f['path']) encoding = locale.getdefaultlocale()[1] file.write(('%s\n' % name).encode(encoding)) file.close() elif cmd == "delta": state = load_state() cursor = state.get('cursor') tree = state['tree'] page = 0 changed = False page_limit = 5 try: delta_switch = parameter[1] except: delta_switch = 0 while (page_limit is None) or (page < page_limit): # Get /delta results from Dropbox result = api_client.delta(cursor) page += 1 if result['reset'] == True: sys.stdout.write('reset\n') changed = True tree = {} cursor = result['cursor'] # Apply the entries one by one to our cached tree. for delta_entry in result['entries']: changed = True apply_delta(tree, delta_entry) cursor = result['cursor'] if not result['has_more']: break if not changed: sys.stdout.write('No updates.\n') else: # Save state state['cursor'] = cursor state['tree'] = tree save_state(state) elif cmd == "put": from_path = parameters[1] to_path = parameters[2] notify = parameters[3] # it can be 'add' or 'upd' from_file = open(os.path.expanduser(from_path), 'rb') #try: api_client.put_file("/" + to_path, from_file) #except: # print(" x Unable to upload file. ") common.orphiliaNotify(notify,from_path) elif cmd == "unlink": sess.unlink() print(" > Unlinked :C") elif cmd == "cat": f = api_client.get_file("/" + path) stdout.write(f.read()) stdout.write("\n") elif cmd == "mkdir": path = parameters[1] try: api_client.file_create_folder("/" + path) except: print(" x Unable to make directory " + path) print(" > Directory \'" + path + "\' created") elif cmd == "rm": path = path_rewrite.rewritepath('posix',parameters[1]) try: api_client.file_delete("/" + path) common.orphiliaNotify('rm',path) except: print(" x Unable to remove file " + path) elif cmd == "mv": from_path = parameters[1] to_path = parameters[2] try: api_client.file_move("/" + from_path, "/" + to_path) except: print(" x Unable to move file " + from_path + " to " + to_path) elif cmd == "account_info": f = api_client.account_info() pprint.PrettyPrinter(indent=2).pprint(f) elif cmd == "uid": param = parameters[1] f = api_client.account_info() uid = str(f['uid']) try: common.putIn(uid,param,'rewrite') except: print(" x Unable to save file.") print(" > UID updated") elif cmd == "get": from_path = parameters[1] to_path = parameters[2] try: open(os.path.expanduser(to_path), 'rb') except: resp = api_client.metadata(from_path) modified = resp['modified'] date1 = modified[5:] date1 = date_rewrite.generate_modifytime(date1) f = api_client.get_file("/" + from_path) file = open(to_path,"wb") try: file.write(f.read()) except: print(" x Unable to save file.") file.close() if sys.platform[:5] != "win32": os.system("touch -d \"" + date1 + "\" \"" + to_path + "\"") # this solution won't work on Windows elif cmd == "sync_folder": path = parameters[1] resp = api_client.metadata(path) # gets list of files in directory on Dropbox dirlist = os.listdir(dropboxPath + "/" + path) # gets list of files in directory on local computer rand1 = random.random() # generates random integer queue = Queue.Queue(0) if 'contents' in resp: # begin comparing both lists for f in resp['contents']: name = os.path.basename(f['path']) encoding = locale.getdefaultlocale()[1] if ('%s' % name).encode(encoding) not in dirlist: # found Dropbox file, which isn't present on local computer print ('%s' % name).encode(encoding) + " not found." if not os.path.isfile(('%s' % name).encode(encoding)): dir = f['is_dir'] if not dir: tmp = [ 'get', path + "/" + name, dropboxPath + "/" + path + name] queue.put(client_new(tmp)) if dir: os.mkdir(dropboxPath + "/" + path + ('%s' % name).encode(encoding)) else: # found Dropbox file which is present on local computer, check this out, bro! name = os.path.basename(f['path']) encoding = locale.getdefaultlocale()[1] print(('%s' % name).encode(encoding) + " found. Checking...") print(" > Command '" + parameters[0] + "' executed")