Example #1
0
def file_exists(fileId):
    """
    Checks whether a file exists on the Drive or not.
    :param fileId: The ID of the file to check.
    :type fileId: str
    :returns: bool
    """
    if not fileId:
        return False
    try:
        file_service.get(fileId=fileId, fields="").execute()
        return True
    except:
        return False
def file_exists(fileId):
    """
    Checks whether a file exists on the Drive and is not trashed.
    :param fileId: The ID of the file to check.
    :type fileId: str
    :returns: bool
    """
    if not fileId:
        return False
    try:
        results = file_service.get(fileId=fileId, fields="trashed").execute()
        # Return False if the file is either trashed or does not exist
        return not results["trashed"]
    except Exception:
        return False
Example #3
0
def file_exists(fileId):
    """
    Checks whether a file exists on the Drive and is not trashed.
    :param fileId: The ID of the file to check.
    :type fileId: str
    :returns: bool
    """
    if not fileId:
        return False
    try:
        results = file_service.get(fileId=fileId, fields="trashed").execute()
        # Return False if the file is either trashed or does not exist
        return not results['trashed']
    except Exception:
        return False
Example #4
0
def file_exists(fileId):
    """
    Checks whether a file exists on the Drive or not.
    :param fileId: The ID of the file to check.
    :type fileId: str
    :returns: bool
    """
    if not fileId:
        return False
    try:
        # Get the file metadata for trashed field 
        # if true, then it doesn't exist in drive
        file_metadata = file_service.get(fileId=fileId, fields="trashed").execute()
        if (file_metadata['trashed']) == True:
            return False
        else:
            return True
    except Exception:
        return False
Example #5
0
def is_file_modified(input_file):
    """
    Checks whether a file on the Drive is different from its local counterpart.
    It does this by comparing their hash values.
    :param input_file: A dictionary containing the details about the file.
    The required details are 'path', 'fileId' and 'parentId'.
    :type input_file: dict
    :returns: bool
    """
    file_path = input_file['path']
    fileId = input_file['fileId']

    if not file_exists(fileId):
        return True

    local_file_hash = hashlib.md5(open(file_path, 'rb').read()).hexdigest()

    remote_file_hash = file_service.get(
        fileId=fileId, fields="md5Checksum").execute()['md5Checksum']

    return local_file_hash != remote_file_hash
def is_file_modified(file_dict):
    """
    Checks whether a file on the Drive is different from its local counterpart.
    It does this by comparing their hash values.
    :param file_dict: A dictionary containing the details about the file.
     The required keys are 'path' and 'fileId'.
    :type file_dict: dict
    :returns: bool
    """
    file_path = file_dict["path"]
    fileId = file_dict["fileId"]

    # If the file does not exist on the Drive,
    # then return true.
    if not file_exists(fileId):
        return True

    remote_file_hash = file_service.get(fileId=fileId, fields="md5Checksum").execute()["md5Checksum"]

    local_file_hash = hashlib.md5(open(file_path, "rb").read()).hexdigest()

    return local_file_hash != remote_file_hash