예제 #1
0
def delete_from_drive(filepath=None, url=None, lkID=None, TD=None):
    try:
        if filepath == None and url == None and lkID == None:
            return False
        if TD == None:
            remote = location(route=filepath)
        else:
            remote = location(route=filepath, TD_Name=TD)
        if lkID != None:
            file_id = lkID
        elif url != None:
            file_id, is_download_link = Public.parse_url(url)
        elif filepath != None:
            file_id = remote.ID

        file = remote.drive_service.files().get(fileId=file_id,
                                                fields='parents').execute()
        # print(file.get('parents'))
        previous_parents = ",".join(file.get('parents'))
        file = remote.drive_service.files().update(
            fileId=file_id,
            removeParents=previous_parents,
            fields='name,id,parents').execute()
        print("{} was removed from drive".format(file['name']))
    except IOError as e:
        print(e, file=sys.stderr)
예제 #2
0
def add_to_drive(url=None, ID=None, filepath=None, makecopy=False, TD=None):
    # print(url);print(ID);print(filepath);print(makecopy);print(TD);
    try:
        if ID == None and url == None:
            return False
        if filepath == None:
            return False
        if ID != None:
            file_id = ID
        else:
            file_id, is_download_link = Public.parse_url(url)
        if TD == None:
            remote = location(route=filepath)
        else:
            remote = location(route=filepath, TD_Name=TD)
        # remote=location(route=filepath)
        drive = remote.drivename
        FolderID = remote.ID
        if makecopy != True:
            file = remote.drive_service.files().update(
                fileId=file_id, addParents=FolderID,
                fields='id,parents,name').execute()
            name = file.get('name')
        else:
            result = remote.drive_service.files().get(
                fileId=file_id, fields="name,mimeType").execute()
            name = result['name']
            newfile = {'name': name, 'parents': [FolderID]}

            file = remote.drive_service.files().copy(
                fileId=file_id, body=newfile, fields='id, parents').execute()
        print("{} was added to drive".format(name))
    except IOError as e:
        print(e, file=sys.stderr)
    return name
예제 #3
0
def get_parents(path, ID=None, url=None):
    file_id = ID
    remote = location(route=path)
    if ID != None:
        file = remote.drive_service.files().get(fileId=file_id,
                                                fields='parents').execute()
        return file.get('parents')
    elif url != None:
        file_id, is_download_link = Public.parse_url(url)
        file = remote.drive_service.files().get(fileId=file_id,
                                                fields='parents').execute()
        return file.get('parents')
    else:
        return False
def addtodrive(filename,truecopy=True):
	if os.path.exists(cache_lib_file):
		lib,TD,libpath=get_cache_lib()
		if lib!=None:
			file_id, is_download_link=DrivePublic.parse_url(filename)		
			if is_download_link:
				remote=DrivePrivate.location(route=libpath,TD_Name=TD)		
				result=remote.drive_service.files().get(fileId=file_id, fields="name,mimeType").execute()		
				name=result['name']	
				testpath=('{}/{}').format(libpath,name)
				remote=DrivePrivate.location(route=testpath,TD_Name=TD)	
				if remote.name==None:			
					name=DrivePrivate.add_to_drive(url=filename,filepath=libpath,makecopy=truecopy,TD=TD)
					filename=('{}/{}').format(libpath,name)
					ID,name,type,size,md5,remote=DrivePrivate.get_Data(filename,TD=TD,Print=False)
				else:
					filename=testpath
				globalremote=remote
		return filename