Beispiel #1
0
    def cancel(self, path):
        """
        Cancels the upload for the given file.
        The cancellation of an upload is very easy. 
        folders/{id}/file_references/delete (id = id of the folder that contains the file_refs) 
        This is is a batch delete method, so a dictionary of file_references can be passed.
        {
        "mid": user id,
        "t": token,
        "aid": project id,
        "file_references" :{"0":{"id":file_ref id},
                            "1":{"id":file_ref id},
                            }
        }        

        """
        if not path in self.FileReferenceID.keys():
            print "cancel returning False"
            return False
        else:
            file_references = {'0': {'id': self.FileReferenceID[path]}}
            values = {
                'mid': self.user_id,
                't': self.token,
                'aid': self.projectid,
                'file_references': file_references
            }
            request = FIOJsonRequest(
                'https://api.frame.io/folders/%s/file_references/delete' %
                self.folderid,
                data=values)
            response_body = urlopen(request).read()
            responsedata = json.loads(response_body)
            logging.info(responsedata.get('messages', [''])[0])
            return True
Beispiel #2
0
def check_email_type(email_address):
    """
    :param email_address:
    :return: auth_mode string: {'user-google', 'user-non-google' or 'user-eligible'}

    Frame.io supports login via Google OAuth2 (google-user), or via non-google (username/password)
    Responses are: 'user-google', 'user-non-google' or 'user-eligible' (sign-up required)

    POST: https://api.frame.io/users/check_elegible
    """

    print "Testing for email: " + str(email_address)
    values = {"email": str(email_address)}
    request = FIOJsonRequest('https://api.frame.io/users/check_elegible', data= values)
    response_body = urlopen(request).read()

    print "Response body: " + str(response_body)

    response_json = json.loads(response_body)

    # Responses looks like this:
    # Gmail/Googlemail domain
    # {"messages":["Success"],"action_key":"user-google"}
    # Non Gamil/Googlemail domain
    # {"messages":["Success"],"action_key":"user-non-google"}
    # Email is eligible but it's not a Google Account
    # {"messages":["Success"],"action_key":"user-eligible","google_account":"false"}

    if response_json.has_key('errors'):
        print 'Email check failed: %s' % (response_json['errors'])
        return None
    elif response_json.has_key('action_key'):
        user_type = response_json['action_key']
        return user_type
Beispiel #3
0
 def getFolderdata(self , folderid):
     """Returns the folderdata for the given folderid """
     values = { 'mid' : self.loginHandler.frameio_user_id , 't' :  self.loginHandler.frameio_token , 'aid' : self.projectid }
     request = FIOJsonRequest('https://api.frame.io/folders/%s' % folderid , data = values)
     response_body = urlopen(request).read()
     folderdata = json.loads(response_body)
     return folderdata['folder']
Beispiel #4
0
 def workerthread(self, path):
     """Starts the worker thread for the given file """
     if not path in self.FileReferenceID.keys():
         print "workerthread returning False"
         return False
     else:
         logging.info('Starting worker thread')
         values = {
             'mid': self.user_id,
             't': self.token,
             'aid': self.projectid,
             'process': 'new-upload',
             'file_reference_id': self.FileReferenceID[path]
         }
         request = FIOJsonRequest('https://api.frame.io/worker/create_job',
                                  data=values)
         response_body = urlopen(request).read()
         responsedata = json.loads(response_body)
         logging.info(responsedata.get('messages', [''])[0])
         return True
Beispiel #5
0
 def createSubfolders(self, namelist, folderid = ''):
     """Creates subfolders to a given folder.
     Args:
         namelist (list): names of the folders to create
         folderid (string): where the subfolders are created.
             Defaults to the current project's root folder 
     Returns:
         list: Dataobjects of the folders created
     """
     if folderid == '':
         folderid = self.get_root_folder_key()
     folders = {}
     i = 0
     for name in namelist:
         folders[str(i)] = {'name' : name}
         i+=1
     values = { 'mid' : self.loginHandler.frameio_user_id , 't' :  self.loginHandler.frameio_token , 'aid' : self.projectid , 'folders' : folders}
     request = FIOJsonRequest('https://api.frame.io/folders/%s/folders' % folderid , data = values)
     response_body = urlopen(request).read()
     folderdata = json.loads(response_body)
     return folderdata['folders']
Beispiel #6
0
 def mergeparts(self, path):
     """Merges all the parts for a given file. """
     if not path in self.FileReferenceID.keys():
         print "mergeparts returning False"
         return False
     else:
         logging.info('Merging parts')
         values = {
             'num_parts': 'dummy',
             'upload_id': 'dummy',
             'mid': self.user_id,
             't': self.token,
             'aid': self.projectid
         }
         request = FIOJsonRequest(
             'https://api.frame.io/file_references/%s/merge_parts' %
             self.FileReferenceID[path],
             data=values)
         response_body = urlopen(request).read()
         responsedata = json.loads(response_body)
         logging.info(responsedata.get('messages', [''])[0])
         return True
Beispiel #7
0
 def uploadpart(self, path, partindex):
     """Uploads the given part of the given file. """
     in_file = open(path, "rb")
     url = self.multipart_urls[path][partindex]
     offset = partindex * self.chunksize()
     in_file.seek(offset)
     datachunk = in_file.read(self.chunksize())
     in_file.close()
     values = {
         'part_num': partindex,
         'mid': self.user_id,
         't': self.token,
         'aid': self.projectid
     }
     try:
         put(urllib.unquote(url), datachunk,
             self.filedata[path]['filetype'])
         request = FIOJsonRequest(
             'https://api.frame.io/file_references/%s/part_complete' %
             self.FileReferenceID[path],
             data=values)
         response_body = urlopen(request).read()
         responsedata = json.loads(response_body)
         logging.info(responsedata.get('messages', [''])[0])
         print 'UPLOAD PART COMPLETED FOR: ' + path + ': ' + url
         return True
     except (URLError, KeyError) as c:
         logging.info('upload failed for ' + path + ': ' + url)
         logging.info(
             'https://api.frame.io/file_references/%s/part_complete' %
             self.FileReferenceID[path])
         logging.info(json.dumps(values, indent=4, separators=(',', ': ')))
         logging.info(self.filedata[path]['filetype'] + ' ' +
                      urllib.unquote(url))
         logging.info(c)
         self.FileReferenceID.pop(path)
         return False
Beispiel #8
0
    def createFileReference(self):
        """Creates the FileReferences on the server for all the files to upload.
        Returns a FileReference dictionary, e.g. {'/path/to/movie.mov': u'TiEXNSDx'}
        """
        file_references = {}
        index = {}
        i = 0
        for path in self.filedata.keys():
            file_references[str(i)] = self.filedata[path]
            index[path] = i
            i += 1
        values = {
            'mid': self.user_id,
            't': self.token,
            'aid': self.projectid,
            'file_references': file_references
        }

        print "Sending file_references request with Dict: ", str(values)

        request = FIOJsonRequest(
            'https://api.frame.io/folders/%s/file_references' % self.folderid,
            data=values)
        response_body = urlopen(request).read()

        print "File Reference Response:" + str(response_body)

        uploaddata = json.loads(response_body)
        logging.info(uploaddata.get('messages', [''])[0])
        for path in self.filedata.keys():
            self.multipart_urls[path] = uploaddata['file_references'][
                index[path]]['multipart_urls']
            self.FileReferenceID[path] = uploaddata['file_references'][
                index[path]]['id']

        return self.FileReferenceID
Beispiel #9
0
 def reloadUserdata(self):
     """Reloads the userdata from the server"""
     values = {'mid' : self.loginHandler.frameio_user_id, 't': self.loginHandler.frameio_token }
     request = FIOJsonRequest('https://api.frame.io/users/%s/data' % self.loginHandler.frameio_user_id, data = values)
     response_body = urlopen(request).read()
     self.userdata = json.loads(response_body)