Page 1 of 1

[RESOLVED] Package for Sourcetree

Published: November 12, 2024 - 1:44 PM
by bastien30
Good morning,

If it's of any use, here's the package code I use for the Sourcetree software (https://www.sourcetreeapp.com/) :

For Windows:

Code: Select all

# -*- coding: utf-8 -*-
from setuphelpers import *

uninstallkey = []

def install():
    appver = control.version.split('-',1)[0]
    bin_name = r'SourcetreeEnterpriseSetup_%s.msi' % appver
    parameters = {'ACCEPTEULA':'1'}
    install_msi_if_needed(bin_name, min_version=appver, killbefore=control.impacted_process, properties=parameters)

def update_package():
    appver = control.version.split('-',1)[0]
    url = r'https://www.sourcetreeapp.com/download-archives'

    print(r'Checking latest version...')
    for release in bs_find_all(url, "a"):
        if "Download free" in release:
            continue
        if release["href"].endswith(".msi"):
            url_dl = (release["href"])
            break
    latest_version = url_dl.split("/")[-1].split(".msi")[0].split("_")[-1]

    if Version(latest_version) > Version(appver):
        bin_name = url_dl.split("/")[-1]
        print(r'Latest version is: %s' % latest_version)
        print(r'Downloading latest binary...')
        wget(url_dl, bin_name)
        # Changing version of the package
        control.version = '%s-%s'%(latest_version,(control.version.split('-')[-1]))
        control.save_control_to_wapt()
        print('Changing version to: %s in WAPT\\control' % control.version)
    else:
        print(r'Already up to date !')

    # Deleting outdated binaries
    remove_outdated_binaries(latest_version)
For macOS:

Code: Select all

# -*- coding: utf-8 -*-
from setuphelpers import *

uninstallkey = []

zip_name_begin = r'Sourcetree'
app_name = r'Sourcetree.app'

def install():
    zip_name = glob.glob('%s*.zip' % zip_name_begin)[0]
    run(r'unzip -qq %s %s/*' % (zip_name, app_name))
    install_app(app_name)

def uninstall():
    uninstall_app(app_name)

def update_package():
    appver = control.version.split('-',1)[0]
    url = r'https://www.sourcetreeapp.com/download-archives'

    print(r'Checking latest version...')
    for release in bs_find_all(url, "a"):
        if "Download free" in release:
            continue
        if release["href"].endswith(".zip"):
            url_dl = (release["href"])
            break
    latest_version = url_dl.split("/")[-1].split(".zip")[0].split("_")[-2]

    if Version(latest_version) > Version(appver):
        bin_name = url_dl.split("/")[-1]
        # Remove older version ZIP file
        try:
            old_zip_name = glob.glob('%s*.zip' % zip_name_begin)[0]
            if isfile(old_zip_name):
                remove_file(old_zip_name)
        except:
            pass
        print(r'Latest version is: %s' % latest_version)
        print(r'Downloading latest binary...')
        wget(url_dl, bin_name)
        # Changing version of the package
        control.version = '%s-%s'%(latest_version,(control.version.split('-')[-1]))
        control.save_control_to_wapt()
        print('Changing version to: %s in WAPT\\control' % control.version)
    else:
        print(r'Already up to date !')
If it's possible for it to be adopted for the TIS store, that would be nice too :D
Thanks in advance.

Re: [SOLVED] Package for Sourcetree

Published: November 12, 2024 - 4:54 PM
by italbot
Hello,

thank you for sharing. I've just created the package; it will be on the store in 5 days.

Have a good day.

Best regards,

Ingrid

Re: [SOLVED] Package for Sourcetree

Published: November 12, 2024 - 4:56 PM
by bastien30
Thank you so much! :D