Esempio n. 1
0
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)
Esempio n. 2
0
        else:
            print "No Netfolder Currently Selected"

        print

    if cmd[0:6] == "fileid":
        print
        print "Fileid Selected"
        print "================"
        print
        print "current is " + str(current)
        cmds = shlex.split(cmd)
        out("\n")
        if len(cmds) == 2:
            if cmds[1] in nf[current]["content"]:
                id = filr.filetoidr(cmds[1], str(current), srv, "", "", s)
                out("File ID is " + str(id))
            else:
                out("ERROR: File Name Not Found")
        out("\n")

    if cmd[0:4] == "zone":

        #cmds=cmd.split(" ")
        cmds = shlex.split(cmd)
        #print len(cmds)
        if len(cmds) > 1:
            if cmds[1].lower() == "list":
                temp = filr.zone(srv, "list", user, pw, s)
                print "list ..."
Esempio n. 3
0
    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 + "\"")
Esempio n. 4
0
    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"
Esempio n. 5
0
    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()