Exemplo n.º 1
0
def downloadCompleteAction(parent, path, download_path, file_name, file_size):

    # remove query from name, If file_name contains query components. 
    # check if query existed.
    # query form is 1.mp3?foo=bar 2.mp3?blatz=pow 3.mp3?fizz=buzz
    file_name_split = file_name.split('.')
    file_extension = file_name_split[-1]
    file_name_without_extension = file_name_split[0]

    # if '?' in file_extension, then file_name contains query components.
    if '?' in file_extension:
        file_extension = file_extension.split('?')[0]
        file_name = '.'.join([file_name_without_extension, file_extension]) 


    # rename file if file already existed
    i = 1
    file_path = os.path.join(download_path, file_name)

    while os.path.isfile(file_path):
        file_name_split = file_name.split('.')
        extension_length = len(file_name_split[-1]) + 1

        new_name = file_name[0:-extension_length] + \
            '_' + str(i) + file_name[-extension_length:]
        file_path = os.path.join(download_path, new_name)
        i = i + 1

    free_space = freeSpace(download_path)

    if free_space != None and file_size != None:
        # compare free disk space and file_size
        if free_space >= file_size:
            # move the file to the download folder
            try:
                # use shutil.copy instead of the default copy2
                shutil.move(str(path) ,str(file_path) ,shutil.copy )

            except:
                logger.sendToLog('Persepolis can not move file', "ERROR")
                file_path = path
        else:
            # notify user if we have insufficient disk space
            # and do not move file from temp download folder to download folder
            file_path = path
            logger.sendToLog('Insufficient disk space in download folder', "ERROR")
            # show notification
            notifySend("Insufficient disk space!", 'Please change download folder',
                    10000, 'fail', parent=parent)

    else:
        # move the file to the download folder
        try:
            shutil.move(str(path) ,str(file_path) ,shutil.copy )

        except:
            logger.sendToLog('Persepolis can not move file', "ERROR")
            file_path = path
 
    return str(file_path)
Exemplo n.º 2
0
def downloadCompleteAction(parent, path, download_path, file_name, file_size):
    i = 1
    file_path = os.path.join(download_path, file_name)

    # rename file if file already existed
    while os.path.isfile(file_path):
        file_name_split = file_name.split('.')
        extension_length = len(file_name_split[-1]) + 1

        new_name = file_name[0:-extension_length] + \
            '_' + str(i) + file_name[-extension_length:]
        file_path = os.path.join(download_path, new_name)
        i = i + 1

    free_space = freeSpace(download_path)

    if free_space != None and file_size != None:
        # compare free disk space and file_size
        if free_space >= file_size:
            # move the file to the download folder
            try:
                # use shutil.copy instead of the default copy2
                shutil.move(str(path), str(file_path), shutil.copy)

            except:
                logger.sendToLog('Persepolis can not move file', "ERROR")
                file_path = path
        else:
            # notify user if we have insufficient disk space
            # and do not move file from temp download folder to download folder
            file_path = path
            logger.sendToLog('Insufficient disk space in download folder',
                             "ERROR")
            # show notification
            notifySend("Insufficient disk space!",
                       'Please change download folder',
                       10000,
                       'fail',
                       parent=parent)

    else:
        # move the file to the download folder
        try:
            shutil.move(str(path), str(file_path), shutil.copy)

        except:
            logger.sendToLog('Persepolis can not move file', "ERROR")
            file_path = path

    return str(file_path)