Exemplo n.º 1
0
def check_for_updates(request):
    """Check if a new version of Modoboa is available."""
    local_config = models.LocalConfig.objects.first()
    client = ModoAPIClient()
    extensions = exts_pool.list_all()
    extensions = [{
        "label": "Modoboa",
        "name": "modoboa",
        "description": _("The core part of Modoboa"),
        "version": client.local_core_version
    }] + extensions
    update_avail = False
    for extension in extensions:
        pkgname = extension["name"].replace("_", "-")
        for api_extension in local_config.api_versions:
            if api_extension["name"] != pkgname:
                continue
            extension["last_version"] = api_extension["version"]
            if (parse_version(api_extension["version"]) > parse_version(
                    extension["version"])):
                extension["update"] = True
                extension["changelog_url"] = api_extension["url"]
                update_avail = True
                break
    return update_avail, extensions
Exemplo n.º 2
0
    def list_all(self, check_new_versions=False):
        """List all defined extensions."""
        result = []
        new_extensions = {}
        if check_new_versions:
            new_extensions = ModoAPIClient().list_extensions()
            if new_extensions:
                new_extensions = dict(
                    (ext["name"], ext["version"]) for ext in new_extensions)
            else:
                new_extensions = {}

        for extname, extdef in self.extensions.iteritems():
            if not extdef["show"]:
                continue
            infos = self.get_extension_infos(extname)
            infos["id"] = extname
            local_version = Version(infos["version"], DEFAULT_NUMBER_BITS)
            pkgname = infos["name"].replace("_", "-")
            if pkgname in new_extensions:
                infos["last_version"] = new_extensions[pkgname]
                last_version = Version(new_extensions[pkgname],
                                       DEFAULT_NUMBER_BITS)
                if last_version > local_version:
                    infos["update"] = True
            result += [infos]
        return sorted(result, key=lambda i: i["name"])
Exemplo n.º 3
0
    def _get_extension_list(self):
        """Ask the API to get the list of all extensions.

        We hardcode the API url here to avoid a loading of
        django's settings since they are not available yet...
        """
        url = "http://api.modoboa.org/"
        official_exts = ModoAPIClient(url).list_extensions()
        return [extension["name"] for extension in official_exts]
Exemplo n.º 4
0
def check_for_updates(request):
    """Check if a new version of Modoboa is available."""
    if parameters.get_admin("CHECK_NEW_VERSIONS") == "no":
        return False, []
    client = ModoAPIClient()
    extensions = exts_pool.list_all(True)
    extensions = [{
        "label": "Modoboa",
        "description": _("The core part of Modoboa"),
        "update": client.new_core_version(get_current_site(request)),
        "last_version": client.latest_core_version,
        "changelog_url": client.changelog_url,
        "version": client.local_core_version
    }] + extensions
    update_avail = False
    for extension in extensions:
        if extension.get("update"):
            update_avail = True
            break
    return update_avail, extensions
Exemplo n.º 5
0
    def __load_extensions(self, extensions):
        """Load specified extensions."""
        if "all" in extensions:
            from modoboa.lib.api_client import ModoAPIClient

            # Retrieve extension list from the API
            url = "http://api.modoboa.org/"
            official_exts = ModoAPIClient(url).list_extensions()
            extensions = [extension["name"] for extension in official_exts]

        for extension in extensions:
            extension = extension.replace("-", "_")
            try:
                __import__(extension, locals(), globals(), ["postfix_maps"])
            except ImportError:
                sys.stderr.write("Unknown extension {0}".format(extension))
Exemplo n.º 6
0
    def render(self, args):
        """Render all map files.

        :param args: arguments received from the command line
        """
        try:
            os.mkdir(args.destdir)
        except OSError:
            pass
        applications = ["modoboa.admin", "modoboa.relaydomains"]
        if args.extensions:
            if "all" in applications:
                from modoboa.lib.api_client import ModoAPIClient

                # Retrieve extension list from the API
                url = "http://api.modoboa.org/"
                official_exts = ModoAPIClient(url).list_extensions()
                extensions = [extension["name"] for extension in official_exts]
            else:
                extensions = args.extensions
            applications += extensions
        self.__load_applications(applications)
        for mapfile in registry.files:
            self.__render_map(args, mapfile)