Пример #1
0
def processHelper(cmd, cwd=None, msg='Error'):
    """
    Used to run subprocess calls with an easy error window throw
    :param cmd:
    :param cwd:
    :param msg:
    :return:
    """
    process = subprocess.Popen(cmd,
                               cwd=cwd,
                               stdout=subprocess.PIPE,
                               stderr=subprocess.PIPE)
    p_status = process.wait()
    out, err = process.communicate()
    if process.returncode != 0:
        if 'File exists' in str(err):
            fileExists = True
        else:
            print(err)
            error_window(err)
        if 'Resource temporarily unavailable' in str(err):
            time.sleep(5)
            processHelper(cmd, cwd, msg)

    time.sleep(2)
Пример #2
0
def finishWrapper(blank):
    """
    Detatches volume,
    converts sparseimage to dmg
    segements the new dmg
    moves dmg files to wrapper
    changes the wrapper name
    copies the icon file
    changes the plist and then cleans up the tmp folder
    :return:
    """
    global VARS
    name = VARS.setname.replace(' ','')

    copyWrapper()

    detachVolumeCMD = ['/usr/bin/hdiutil', 'detach', name]
    processHelper(detachVolumeCMD, cwd='/Volumes', msg='Volume Detach Failure: ')

    convertToDmgCMD = ['/usr/bin/hdiutil', 'convert', f"{name}.sparseimage", '-format', 'UDRO', '-o', f"{name}-original.dmg"]
    processHelper(convertToDmgCMD, cwd='/tmp', msg='Conversion to DMG failed: ')

    segmentCMD = ['/usr/bin/hdiutil', 'segment', '-o', name, '-segmentSize', '1g', f'{name}-original.dmg']
    processHelper(segmentCMD, cwd='/tmp', msg='Segment Failed: ')

    try:
        moveFiles()
    except Exception as err:
        error_window(err)

    changeWrapperName = ['/bin/mv', 'Template.app', f"{VARS.setname}.app"]

    dir_path = os.path.dirname(os.path.realpath(__file__))
    dir_path = pathlib.Path(dir_path).parent.parent

    processHelper(changeWrapperName, cwd=dir_path, msg='Wrapper Name Change Failed: ')

    # copies icon over to the package
    if blank == False:
        copyIcon(VARS)
    else:
        copyIconBlank(VARS)

    # Changes the Plist in the template with the proper information
    changePlist(VARS)

    #copies over pre, post and exit scripts
    copyScripts(VARS)

    #cleans up tmp dir and moves finished app to Desktop
    postcleanup(blank)

    #Shows Finished Indicator
    finished_window()
Пример #3
0
def copyIconBlank(VARS):
    """
    Copies icon from source application to the wrapper app
    :param VARS:
    :return:
    """
    name = VARS.setname
    dir_path = os.path.dirname(os.path.realpath(__file__))
    dir_path = pathlib.Path(dir_path).parent.parent
    dst = f"{dir_path}/{name}.app/Contents/Resources/icon.icns"
    src = f"{dir_path}/temp/icon.icns"
    try:
        shutil.copy(src, dst)
    except Exception as err:
        error_window(err)
Пример #4
0
def postcleanup():
    """
    used to clean up the tmp folder and moves finished wrapper to desktop
    :return:
    """
    global VARS
    setname = str(VARS.setname).replace(' ', '')
    os.remove(f"/tmp/{setname}.sparseimage")
    os.remove(f"/tmp/{setname}-original.dmg")

    name = VARS.setname
    dir_path = pathlib.Path(os.path.dirname(
        os.path.realpath(__file__))).parent.parent

    try:
        dir_path = dir_path / f"{VARS.setname}.app"
        shutil.move(str(dir_path), str(pathlib.Path.home() / 'Desktop'))
    except Exception as err:
        print(f"{err} : Post Cleanup Failed.")
        error_window()
Пример #5
0
def changePlist(data):
    """
    Edits the Plist in the wrapper app with the collected information from the original app
    :param data:
    :return:
    """
    name = data.setname
    dir_path = os.path.dirname(os.path.realpath(__file__))
    dir_path = pathlib.Path(dir_path).parent.parent
    try:
        plistPath = f"{dir_path}/{name}.app/Contents/Info.plist"
        p = plistlib.readPlist(plistPath)
        p['CFBundleIconFile'] = 'icon'
        p['CFBundleName'] = data.name
        p['CFBundleShortVersionString'] = data.version
        p['CFBundleIdentifier'] = data.identifier
        plistlib.writePlist(p, plistPath)

    except Exception as err:
        error_window(err)