<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def download_log(currentfile=None):
 """downloads log of given .py file from EV3."""


    if currentfile == None:
        return
    
    # add ".err.log" if file doesn't end with it!
    if not currentfile.endswith(".err.log"):
        currentfile=currentfile + ".err.log"
    
    list = get_base_ev3dev_cmd() + ['download','--force']
    list.append(currentfile)

    env = os.environ.copy()
    env["PYTHONUSERBASE"] = THONNY_USER_BASE
    proc = subprocess.Popen(list, stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
                            universal_newlines=True, env=env)
    dlg = MySubprocessDialog(get_workbench(), proc, "Downloading log of program from EV3", autoclose=True)
    dlg.wait_window()
    if dlg.returncode == 0:
        from pathlib import Path
        home = str(Path.home())
        open_file(currentfile,home,True)