Exemple #1
0
def test_internal_representation():
    v1 = Version("1.2.3")
    v2 = Version("1.2.3b4")
    v3 = Version("1.2.3a4")

    assert v1.raw_version == ["1", "2", "3"]
    assert v2.raw_version == ["1", "2", "3", "4"]
    assert v3.raw_version == ["1", "2", "3", "0", "4"]
Exemple #2
0
def test_human_readability():
    v1 = Version("1.2.3")
    v2 = Version("1.2.3b4")
    v3 = Version("1.2.3a4")

    assert v1.to_human_readable() == "1.2.3"
    assert v2.to_human_readable() == "1.2.3 beta 4"
    assert v3.to_human_readable() == "1.2.3 alpha 4"
Exemple #3
0
 def _get_newest_stable(self):
     v1 = Version("0.0.0")  # the lowest version you can go.
     for version_key in self._metadata.keys():
         v2 = Version(version_key)
         if v2.is_stable == False:  # This version is not a stable build.
             continue
         if v2 > v1:
             v1 = v2
     if v1 == Version(
             "0.0.0"
     ):  # If the version is still the same (no builds on this channel yet).
         return None
     return v1
def test_metadata_getting_newest():
    md = MetaData()
    assert len(md._metadata) == 0
    md.add_metadata("test_app-1.0.0.exe", "DUMMY_CHECKSUM", "1.0.0")
    assert len(md._metadata) == 1
    assert md.get_newest(MetaDataChannel.STABLE) == Version("1.0.0")

    md.add_metadata("test_app-1.0.0a1.exe", "DUMMY_CHECKSUM_FOR_ALPHA",
                    "1.0.0a1")
    assert len(md._metadata) == 2
    assert md.get_newest(MetaDataChannel.ALPHA) == Version("1.0.0a1")

    md.add_metadata("test_app-1.0.0b1.exe", "DUMMY_CHECKSUM_FOR_BETA",
                    "1.0.0b1")
    assert len(md._metadata) == 3
    assert md.get_newest(MetaDataChannel.BETA) == Version("1.0.0b1")
async def check_for_updates(show_result=False):
    if variables.update_in_progress:
        err = wx.MessageDialog(wx.GetTopLevelWindows()[0],
                               caption="UtopiaForReddit Updater",
                               message="Updater already in progress.")
        err.ShowModal()
        err.Destroy()
        return
    logging.info("Initializing updater.")
    updater_client = JustUpdateClient(ClientConfig(), variables.version,
                                      variables.config.get("update_channel"))
    if updater_client.is_post_update():
        logging.info("Running post update actions")
        updater_client.cleanup()
        updater_client.post_update_cleanup()
        return
    if variables.config.get("auto_check_for_updates") == False:
        return
    try:
        bypass_cache = False
        if variables.release_channel == "alpha":
            logging.debug(
                "Disabling cache when checking for updates on the alpha channel."
            )
            bypass_cache = True
        if updater_client.update_available(bypass_cache):
            variables.update_in_progress = True
            logging.debug("Update found.")
            logging.debug("Asking user to update.")
            q = wx.MessageDialog(
                wx.GetTopLevelWindows()[0],
                "You are running version {} however version {} is available. Do you want to update UtopiaForReddit now?"
                .format(
                    Version(variables.version).to_human_readable(),
                    updater_client._update_version.to_human_readable()),
                "UtopiaForReddit Updater",
                wx.YES_NO | wx.YES_DEFAULT | wx.STAY_ON_TOP)
            q.ShowModal()
            q.Destroy()
            if result == wx.ID_NO:
                variables.update_in_progress = False
                return
            # user wants to update.
            await _do_update(updater_client)
            return
        else:
            raise ValueError("No update available.")
    except (requests.exceptions.ConnectionError, ValueError, zlib.error) as e:
        logging.warn("Status when checking for updates: " + str(e))
        if show_result:
            result = wx.MessageDialog(wx.GetTopLevelWindows()[0],
                                      caption="UtopiaForReddit",
                                      message="No update found.")
            result.ShowModal()
            result.Destroy()
Exemple #6
0
    def update_available(self, bypass_metadata_cache=False):
        """Checks for updates to the application
		
		args:
			bypass_metadata_cache (bool) : Bypass the available cache for the metadata, True to force redownload of metadata, False to use cache. (Default False).
		"""
        if self.channel not in ("stable", "beta", "alpha"):
            raise InvalidUpdateChannelException(
                "\"{} is an invalid update channel. Available channels are alpha, beta and stable."
                .format(channel))
        current_version = Version(self.current_version)
        try:
            self._metadata = self._load_metadata(bypass_metadata_cache)
        except requests.exceptions.HTTPError as e:
            raise e
            return False
        if self.channel == "alpha":
            newest_version = self._metadata.get_newest(MetaDataChannel.ALPHA)
            if newest_version is None:
                return False
            if newest_version > current_version:
                self._update_version = newest_version
                return True
            else:
                return False
        if self.channel == "beta":
            newest_version = self._metadata.get_newest(MetaDataChannel.BETA)
            if newest_version == None:
                return False
            if newest_version > current_version:
                self._update_version = newest_version
                return True
            else:
                return False
        if self.channel == "stable":
            newest_version = self._metadata.get_newest(MetaDataChannel.STABLE)
            if newest_version is None:
                return False
            if newest_version > current_version:
                self._update_version = newest_version
                return True
            else:
                return False
Exemple #7
0
 def update_available(self):
     if self.channel not in ("stable", "beta", "alpha"):
         raise InvalidUpdateChannelException(
             "\"{} is an invalid update channel. Available channels are alpha, beta and stable."
             .format(channel))
     current_version = Version(self.current_version)
     try:
         self._metadata = self._load_metadata()
     except requests.exceptions.HTTPError as e:
         raise e
         return False
     if self.channel == "alpha":
         newest_version = self._metadata.get_newest(MetaDataChannel.ALPHA)
         if newest_version is None:
             return False
         if newest_version > current_version:
             self._update_version = newest_version
             return True
         else:
             return False
     if self.channel == "beta":
         newest_version = self._metadata.get_newest(MetaDataChannel.BETA)
         if newest_version == None:
             return False
         if newest_version > current_version:
             self._update_version = newest_version
             return True
         else:
             return False
     if self.channel == "stable":
         newest_version = self._metadata.get_newest(MetaDataChannel.STABLE)
         if newest_version is None:
             return False
         if newest_version > current_version:
             self._update_version = newest_version
             return True
         else:
             return False
Exemple #8
0
import sys

from justupdate.repo.version import Version

if len(sys.argv) == 1:
    print("Usage: version_writer.py version")
    sys.exit(1)

print("Starting version writer for UtopiaForReddit.")
print("Version: {}.".format(sys.argv[1]))
version = Version(sys.argv[1])
channel = ""
if version.is_stable:
    channel = "stable"
if version.is_beta:
    channel = "beta"
if version.is_alpha:
    channel = "alpha"

if channel == "":
    raise ValueError("Unable to determine release channel.")
    sys.exit(2)

print("Release channel: {}.".format(channel))

print("Writing version_helper.py in \"src/core/version_helper.py\".")
f = open("src/core/version_helper.py", "w")
f.write('git_tag_version = "{0}"\ngit_tag_release_channel = "{1}"'.format(
    sys.argv[1], channel))
f.close()
print("Done writing version_helper.py")
Exemple #9
0
def test_version_equality():
    assert Version("1.0.0") == Version("1.0.0")
    assert Version("1.0.0b1") == Version("1.0.0b1")
    assert Version("1.0.0a1") == Version("1.0.0a1")
Exemple #10
0
def test_less_than():
    assert Version("1.0.1") < Version("1.0.2")
    assert Version("1.1.0") < Version("1.2.0")
    assert Version("1.0.0") < Version("2.0.0")
Exemple #11
0
def test_version_greater_than():
    assert Version("1.0.2") > Version("1.0.1")
    assert Version("1.2.0") > Version("1.1.0")
    assert Version("2.0.0") > Version("1.0.0")
Exemple #12
0
 def __init__(self, version):
     self.config = Config()
     self.config.load(
         os.path.join(JustUpdateConstants.REPO_FOLDER, "config.ju"))
     self.version = Version(version)
     self.executor = CommandExecutor()
Exemple #13
0
class Committer():
    def __init__(self, version):
        self.config = Config()
        self.config.load(
            os.path.join(JustUpdateConstants.REPO_FOLDER, "config.ju"))
        self.version = Version(version)
        self.executor = CommandExecutor()

    def setup(self):
        if os.path.isdir(os.path.join(JustUpdateConstants.REPO_FOLDER,
                                      "new")) == False:
            os.makedirs(os.path.join(JustUpdateConstants.REPO_FOLDER, "new"))
        if os.path.isdir(
                os.path.join(JustUpdateConstants.REPO_FOLDER,
                             "deploy")) == False:
            os.makedirs(os.path.join(JustUpdateConstants.REPO_FOLDER,
                                     "deploy"))

    def insure_build_availability(self):
        cmd = getattr(
            self,
            "_insure_build_availability_{}".format(get_platform_name_short()))
        return cmd()

    def produce_executable(self):
        cmd = getattr(
            self, "_produce_executable_{}".format(get_platform_name_short()))
        return cmd()

    def create_metadata(self):
        cmd = getattr(self,
                      "_create_metadata_{}".format(get_platform_name_short()))
        return cmd()

    def finalize(self):
        cmd = getattr(self, "_finalize_{}".format(get_platform_name_short()))
        return cmd()

    def _insure_build_availability_win(self):
        if os.path.isdir(
                os.path.join(JustUpdateConstants.REPO_FOLDER, "dist",
                             "win")) == False:
            return False
        if not os.listdir(
                os.path.join(JustUpdateConstants.REPO_FOLDER, "dist", "win")):
            return False
        return True

    def _insure_build_availability_mac(self):
        if not os.path.isdir(
                os.path.join(JustUpdateConstants.REPO_FOLDER, "dist",
                             "{}.app".format(self.config.get("app_name")))):
            return False
        return True

    def _produce_executable_win(self):
        tmp = template.prepare_template(self.version)
        cmd = ["makensis", "/V1", "-"]
        result, stdout = self.executor.execute(cmd, CommandType.RAW, stdin=tmp)
        if result != 0:
            print(stdout)
            logging.error("Please correct the errors above and try again.")
            return False
        return True

    def _produce_executable_mac(self):
        logging.debug("Updating Info.plist and installation scripts.")
        tmp = template.prepare_template(self.version)
        logging.debug("Assembling pkg installer.")
        cmd = [
            "productbuild", "--scripts",
            os.path.join(JustUpdateConstants.REPO_FOLDER, "templates", "mac",
                         "scripts"), "--component",
            os.path.join(JustUpdateConstants.REPO_FOLDER, "dist",
                         "{}.app".format(self.config.get("app_name"))),
            "/Applications",
            os.path.join(
                JustUpdateConstants.REPO_FOLDER, "new",
                "{0}-{1}.pkg".format(self.config.get("app_name"),
                                     self.version.to_string()))
        ]
        result, stdout = self.executor.execute(cmd, CommandType.RAW)
        if result != 0:
            print(stdout)
            logging.error("Please correct the errors above and try again.")
            return False
        return True

    def _create_metadata_win(self):
        logging.info("Calculating checksum.")
        checksum = data_manager.calculate_checksum(
            os.path.join(
                JustUpdateConstants.REPO_FOLDER, "new",
                "{0}-{1}.exe".format(self.config.get("app_name"),
                                     self.version.to_string())))
        logging.info("Looking for existing metadata.")
        md = MetaData()
        md.apply_metadata(md.load())
        md.add_metadata(
            "{0}-{1}.exe".format(self.config.get("app_name"),
                                 self.version.to_string()), checksum,
            self.version.to_string())
        logging.info("Saving updated metadata.")
        md.save(
        )  # The updated metadata is saved to "ju-repo/deploy/metadata.ju".
        return True

    def _create_metadata_mac(self):
        logging.info("Calculating checksum.")
        checksum = data_manager.calculate_checksum(
            os.path.join(
                JustUpdateConstants.REPO_FOLDER, "new",
                "{0}-{1}.pkg".format(self.config.get("app_name"),
                                     self.version.to_string())))
        logging.info("Looking for existing metadata.")
        md = MetaData()
        md.apply_metadata(md.load())
        md.add_metadata(
            "{0}-{1}.pkg".format(self.config.get("app_name"),
                                 self.version.to_string()), checksum,
            self.version.to_string())
        logging.info("Saving updated metadata.")
        md.save(
        )  # The updated metadata is saved to "ju-repo/deploy/metadata.ju".
        return True

    def _finalize_win(self):
        logging.info("Moving executable.")
        shutil.move(
            os.path.join(
                JustUpdateConstants.REPO_FOLDER, "new",
                "{0}-{1}.exe".format(self.config.get("app_name"),
                                     self.version.to_string())),
            os.path.join(JustUpdateConstants.REPO_FOLDER, "deploy"))
        #cleanup ju-repo/dist/win
        shutil.rmtree(
            os.path.join(JustUpdateConstants.REPO_FOLDER, "dist", "win"))

    def _finalize_mac(self):
        logging.info("Moving executable.")
        shutil.move(
            os.path.join(
                JustUpdateConstants.REPO_FOLDER, "new",
                "{0}-{1}.pkg".format(self.config.get("app_name"),
                                     self.version.to_string())),
            os.path.join(JustUpdateConstants.REPO_FOLDER, "deploy"))
        #cleanup ju-repo/dist/mac
        try:
            shutil.rmtree(
                os.path.join(JustUpdateConstants.REPO_FOLDER, "dist", "mac"))
        except:
            pass
        try:
            shutil.rmtree(
                os.path.join(JustUpdateConstants.REPO_FOLDER, "dist",
                             "{}.app".format(self.config.get("app_name"))))
        except:
            pass
Exemple #14
0
def test_less_than():
    # stable ones
    assert Version("1.0.1") < Version("1.0.2")
    assert Version("1.1.0") < Version("1.2.0")
    assert Version("1.0.0") < Version("2.0.0")
    # beta versions
    assert Version("1.0.0b1") < Version("1.0.0b2")
    assert Version("1.0.0b1") < Version("1.0.1b1")
    assert Version("1.0.0b1") < Version("1.1.0b1")
    assert Version("1.0.0b1") < Version("2.0.0b1")
    # alpha versions
    assert Version("1.0.0a1") < Version("1.0.0a2")
    assert Version("1.0.0a1") < Version("1.0.1a1")
    assert Version("1.0.0a1") < Version("1.1.0a1")
    assert Version("1.0.0a1") < Version("2.0.0a1")
    # Mixed channel versions (version priority)
    assert Version("1.0.0a1") < Version("1.0.0b1")
    assert Version("1.0.0b1") < Version("1.0.0")
    assert Version("1.0.0a1") < Version("1.0.0")
Exemple #15
0
import os
import sys

from justupdate.repo.version import Version
from justupdate.repo.metadata import MetaData

if len(sys.argv) == 1:
    print("Usage: travis_build_cleaner.py version")
    sys.exit(1)

print("Starting travis build cleaner for UtopiaForReddit.")
print("Version: {}.".format(sys.argv[1]))
new_version = Version(sys.argv[1])
channel = ""
if new_version.is_stable:
    channel = "stable"
if new_version.is_beta:
    channel = "beta"
if new_version.is_alpha:
    channel = "alpha"

if channel == "":
    raise ValueError("Unable to determine release channel.")
    sys.exit(2)

print("Release channel: {}.".format(channel))

print("Removing older versions from ju-repo/archive")

metadata = MetaData().load()