def browse(server, folderid, user, pword, parent=1): userinfo = filr.userinfo(server, user, pword, s) wx.Yield() fname = userinfo["title"] start_time = time.time() global nf data = filr.filrapi(server, "folders/" + folderid, "", "", "", 0, 1, s) wx.Yield() path = data["path"].replace("/Home Workspace/Net Folders", "") path = data["path"].replace( "/Home Workspace/Personal Workspaces/" + fname + " (" + user + ")", "") data = filr.filrapi(server, "folders/" + folderid + "/folders", "", "", "", 0, 1, s) #data=filr.filrapi(server,"folders/"+folderid+"/folders","","","",debug=1) wx.Yield() if parent == 1: nf.update({ int(folderid): { "parent": parent, "child": [], "path": path, "content": [] } }) for temp in data["items"]: tempath = temp["path"].replace("/Home/Workspace/Net Folders", "") tempath = tempath.replace( "/Home Workspace/Personal Workspaces/" + fname + " (" + user + ")", "") nf.update({ temp["id"]: { "parent": int(folderid), "child": [], "path": tempath, "content": [] } }) print temp["id"] print "folderid is " + folderid print nf if temp["id"] not in nf[int(folderid)]["child"]: nf[int(folderid)]["child"].append(temp["id"]) data = filr.filrapi(server, "folders/" + folderid + "/files", "", "", "", 0, 1, s) wx.Yield() for temp in data["items"]: #print temp["name"] if temp["name"] not in nf[int(folderid)]["content"]: nf[int(folderid)]["content"].append(temp["name"]) taken = time.time() - start_time print print "Time taken to run command is %5.3f seconds" % taken print return (nf)
def browse(server, folderid, user, pword, parent=1, up=0, s=""): start_time = time.time() global nf data = filr.filrapi(server, "folders/" + folderid, "", "", "", 0, up, s) path = data["path"].replace("/Home Workspace/Net Folders", "") path = data["path"].replace( "/Home Workspace/Personal Workspaces/" + fname + " (" + user + ")", "") data = filr.filrapi(server, "folders/" + folderid + "/folders", "", "", "", 0, up, s) if parent == 1: nf.update({ int(folderid): { "parent": parent, "child": [], "path": path, "content": [] } }) for temp in data["items"]: tempath = temp["path"].replace("/Home/Workspace/Net Folders", "") tempath = tempath.replace( "/Home Workspace/Personal Workspaces/" + fname + " (" + user + ")", "") nf.update({ temp["id"]: { "parent": int(folderid), "child": [], "path": tempath, "content": [] } }) if temp["id"] not in nf[int(folderid)]["child"]: nf[int(folderid)]["child"].append(temp["id"]) if up == 1: #print "Prior Change Detected" data = filr.filrapi(server, "folders/" + folderid + "/files", "", "", "", 0, 1, s) up = 0 else: data = filr.filrapi(server, "folders/" + folderid + "/files", "", "", "", 0, 0, s) for temp in data["items"]: #print temp["name"] if temp["name"] not in nf[int(folderid)]["content"]: nf[int(folderid)]["content"].append(temp["name"]) taken = time.time() - start_time print print "Time taken to run command is %5.3f seconds" % taken print return (nf)
def shared(server, userid, user, pword, s="", parent=1): #print s """(REST) Routine to look at shared with Me Folder""" start_time = time.time() global nf data = filr.filrapi(server, "shares/with_user/" + str(userid), "", "", "", 0, 0, s) path = "/Shared With Me" if parent == 1: nf.update({ int(userid): { "parent": parent, "child": [], "path": path, "content": [] } }) for temp in data["items"]: type = temp["shared_entity"]["type"] url = temp["shared_entity"]["href"][1:] #print url data1 = filr.filrapi(server, url, "", user, pword) #print data1 if type == "folderEntry": #print data1["title"] if data1["title"] not in nf[int(userid)]["content"]: nf[int(userid)]["content"].append(data1["title"]) if type == "folder": try: path = data1["path"] path = data["path"].replace( "/Home Workspace/Personal Workspaces/" + fname + " (" + user + ")", "") #print path nf.update({ data1["id"]: { "parent": int(userid), "child": [], "path": path, "content": [] } }) if data1["id"] not in nf[int(userid)]["child"]: nf[int(userid)]["child"].append(data1["id"]) except: error = 1 taken = time.time() - start_time print print "Time taken to run command is %5.3f seconds" % taken print return (nf)
def rights(filename, folderid, srvname, user, pw): """(REST) List Filr Shares for a file""" filename = filename.replace("(file) ", "") id = filr.filetoidr(filename, folderid, srvname, user, pw, s) reply = [] if id <> 0: rights = filr.filrapi(srvname, "folder_entries/" + str(id) + "/shares", "", "", "", 0, 0, s) #recipient=rights["items"][0]["recipient"] #print shareing count = 1 count = 0 reply.append("Access Rights for File " + filename + ":") for temp in rights["items"]: #print temp["recipient"] reply.append("\n") reply.append( "File Granted to User " + filr.idtoname(str(temp["recipient"]["id"]), srvname, user, pw)) reply.append("Access Granted is :" + str(temp["access"]["role"])) reply.append("Reshare right granted " + str(temp["access"]["sharing"]["grant_reshare"])) if len(reply) == 1: reply.append("File is shared with Nobody") else: print "ERROR file not found" return (reply)
import filr import os os.system("cls") pw=None srv="filrutp.utopia.novell.com" user="******" user,pw=filr.pw(srv,user,pw) s=filr.auth(user,pw) userinfo=filr.filrapi(srv,"self","","","",0,0,s) os.system("cls") print userinfo["title"]
def view(self, event): global file1 print "File View Selected" print filename file1 = filename.replace("(file) ", "") print file1 tempdir = os.getenv("TEMP") dest = tempdir.replace("\\", "/") + "/" + file1 print "Destination path is " + dest print folderid name = posixpath.basename(dest) dirname = posixpath.dirname(dest) wx.Yield() id = filr.filetoidr(name, folderid, srv, user, pw, s) data = filr.filrapi(srv, "folders/" + folderid + "/files", "", "", "", 0, 1, s) wx.Yield() filr_url = "" for temp in data["items"]: if name == temp["name"]: filr_url = temp["permalinks"][-1]["href"] length = temp["length"] if filr_url == "": status = 1 print "Error" return (status) max = length #status=filr.download(posixpath.basename(dest),str(folderid),srv,posixpath.dirname(dest),user,pw) dlg = wx.ProgressDialog( "File Download", "File being downloaded " + posixpath.basename(dest), maximum=max, parent=self, style=0 | wx.PD_APP_MODAL #| wx.PD_CAN_ABORT #| wx.PD_CAN_SKIP | wx.PD_ELAPSED_TIME | wx.PD_ESTIMATED_TIME | wx.PD_REMAINING_TIME #| wx.PD_AUTO_HIDE ) keepGoing = True count = 0 status = 0 start_time = time.time() wx.Yield() #wx.Yield() local_filename = urllib2.unquote(filr_url.split('/')[-1]) local_filename = dirname + "/" + local_filename print local_filename + " of size " + str(length) + "k" print "Being Downloaded ..." header1 = {'Content-type': 'application/json'} max = length chunk = 3072 count = 0 r = requests.get(filr_url, data="", headers=header1, auth=(user, pw), stream=True, verify=False) with open(local_filename, 'wb') as f: for chunk in r.iter_content(chunk_size=chunk): if chunk: # filter out keep-alive new chunks f.write(chunk) f.flush() count = count + 3072 #wx.MilliSleep(250) wx.Yield() if count < max: skip = dlg.Update(count) dlg.Destroy() print taken = time.time() - start_time os.system("\"" + dest + "\"")
def download(self, event): global file1 print self print "File Download Selected" print filename wildcard = "All files (*.*)|*.*" file1 = filename.replace("(file) ", "") print file1 dlg = wx.FileDialog(self, message="Save file as ...", defaultDir=os.getcwd(), defaultFile=file1, wildcard=wildcard, style=wx.SAVE) dlg.SetFilterIndex(2) if dlg.ShowModal() == wx.ID_OK: path = dlg.GetPath() dest = path.replace("\\", "/") print "Destination path is " + dest print folderid name = posixpath.basename(dest) dirname = posixpath.dirname(dest) id = filr.filetoidr(name, folderid, srv, user, pw, s) data = filr.filrapi(srv, "folders/" + folderid + "/files", "", "", "", 0, 1, s) wx.Yield() filr_url = "" for temp in data["items"]: if name == temp["name"]: filr_url = temp["permalinks"][-1]["href"] length = temp["length"] if filr_url == "": status = 1 print "Error" return (status) max = length dlg = wx.ProgressDialog( "File Download", "File being downloaded " + posixpath.basename(dest), maximum=max, parent=self, style=0 | wx.PD_APP_MODAL | wx.PD_CAN_ABORT #| wx.PD_CAN_SKIP #| wx.PD_ELAPSED_TIME | wx.PD_ESTIMATED_TIME | wx.PD_REMAINING_TIME #| wx.PD_AUTO_HIDE ) keepGoing = True count = 0 status = 0 start_time = time.time() wx.Yield() wx.Yield() local_filename = urllib2.unquote(filr_url.split('/')[-1]) local_filename = dirname + "/" + local_filename print local_filename + " of size " + str(length) + "k" print "Being Downloaded ..." header1 = {'Content-type': 'application/json'} max = length chunk = 3072 count = 0 r = requests.get(filr_url, data="", headers=header1, auth=(user, pw), stream=True, verify=False) with open(local_filename, 'wb') as f: for chunk in r.iter_content(chunk_size=chunk): if chunk: # filter out keep-alive new chunks f.write(chunk) f.flush() count = count + 3072 #wx.MilliSleep(250) wx.Yield() if count < max: skip = dlg.Update(count) dlg.Destroy() print taken = time.time() - start_time print "File Downloaded in %5.3f Seconds" % taken dlg = wx.MessageDialog( self, 'File ' + posixpath.basename(local_filename) + " " + str(length) + "k downloaded in %5.3f seconds" % taken, 'Download Completed', wx.OK | wx.ICON_INFORMATION #wx.YES_NO | wx.NO_DEFAULT | wx.CANCEL | wx.ICON_INFORMATION ) dlg.ShowModal() dlg.Destroy() # Normally, at this point you would save your data using the file and path # data that the user provided to you, but since we didn't actually start # with any data to work with, that would be difficult. # # The code to do so would be similar to this, assuming 'data' contains # the data you want to save: # # fp = file(path, 'w') # Create file anew # fp.write(data) # fp.close() # # You might want to add some error checking :-) # print "Download Done"
def edit(self, event): #global s global filename print filename global folderid print "Folderid is " + str(folderid) obj = event.GetEventObject() if filename == "": item = event.GetItem() filename = self.GetItemText(item) print "File Edit Selected" file1 = filename.replace("(file) ", "") print file1 tempdir = os.getenv("TEMP") dest = tempdir.replace("\\", "/") + "/" + file1 print "Destination path is " + dest print folderid name = posixpath.basename(dest) dirname = posixpath.dirname(dest) wx.Yield() id = filr.filetoidr(name, folderid, srv, user, pw, s) data = filr.filrapi(srv, "folders/" + folderid + "/files", "", "", "", 0, 1, s) wx.Yield() filr_url = "" for temp in data["items"]: if name == temp["name"]: filr_url = temp["permalinks"][-1]["href"] length = temp["length"] if filr_url == "": status = 1 print "Error" return (status) max = length #status=filr.download(posixpath.basename(dest),str(folderid),srv,posixpath.dirname(dest),user,pw) dlg = wx.ProgressDialog( "File Download", "File being downloaded " + posixpath.basename(dest), maximum=max, parent=self, style=0 | wx.PD_APP_MODAL #| wx.PD_CAN_ABORT #| wx.PD_CAN_SKIP | wx.PD_ELAPSED_TIME | wx.PD_ESTIMATED_TIME | wx.PD_REMAINING_TIME #| wx.PD_AUTO_HIDE ) keepGoing = True count = 0 status = 0 start_time = time.time() wx.Yield() local_filename = urllib2.unquote(filr_url.split('/')[-1]) local_filename = dirname + "/" + local_filename print local_filename + " of size " + str(length) + "k" print "Being Downloaded ..." header1 = {'Content-type': 'application/json'} max = length chunk = 2048 count = 0 r = requests.get(filr_url, data="", headers=header1, auth=(user, pw), stream=True, verify=False) with open(local_filename, 'wb') as f: for chunk in r.iter_content(chunk_size=chunk): if chunk: # filter out keep-alive new chunks f.write(chunk) f.flush() count = count + 3072 #wx.MilliSleep(250) wx.Yield() if count < max: skip = dlg.Update(count) dlg.Destroy() print taken = time.time() - start_time os.system("\"" + dest + "\"") fname = dest size = os.path.getsize(fname) size = size / 1024 print "File Download Finished" taken = time.time() - start_time print "File Downloaded in %5.3f Seconds" % taken dlg = wx.ProgressDialog( "File Uploaded", "File being Uploaded " + os.path.basename(fname), maximum=size, parent=self, style=0 | wx.PD_APP_MODAL #| wx.PD_CAN_ABORT #| wx.PD_CAN_SKIP | wx.PD_ELAPSED_TIME | wx.PD_ESTIMATED_TIME | wx.PD_REMAINING_TIME #| wx.PD_AUTO_HIDE ) keepGoing = True count = 0 status = 0 start_time = time.time() identity = folderid #filr_url = "https://"+srv+"/rest/folders/"+identity+"/library_files?file_name="+os.path.basename(fname)+"&force_overwrite=true" filr_url = "https://" + srv + "/rest/folders/" + identity + "/library_files?file_name=" + os.path.basename( fname) + "&overwrite_existing=true" data = json.dumps({'file_name': fname}) if os.path.isfile(fname): files = open(fname, 'rb') else: print "ERROR: Source File Not Found" return print "Please Wait ...." skip = dlg.Update(size) wx.Yield() r = requests.post(filr_url, files, auth=(user, pw), verify=False) data = json.loads(r.text) wx.Yield() l = len(data) print data if l <= 2: print "ERROR: " + str(data["message"]) else: #print d print str(data["name"]) + " size " + str( data["length"] / 1024) + "k Uploaded Successfully...." taken = time.time() - start_time print "File Uploaded in %5.3f Seconds" % taken # Compare this with the debug above; did we change working dirs? # Destroy the dialog. Don't do this until you are done with it! # BAD things can happen otherwise! dlg.Destroy()