Exemple #1
0
    def list_addons(server, translatable_only):
        """Get a list of addons on the server.

        server              The url of the addon server eg
                            add-ons.wesnoth.org:15005.
        translatable_only   If True only returns translatable addons.
        returns             A dictionary with the addon as key and the translatable
                            status as value.
        """

        logging.debug("list addons server = '%s' translatable_only = %s",
                      server, translatable_only)

        wml = libwml.CampaignClient(server, quiet_libwml)
        data = wml.list_campaigns()

        # Item [0] hardcoded seems to work
        campaigns = data.data[0]
        result = {}
        for c in campaigns.get_all("campaign"):
            translatable = c.get_text_val("translate")
            if (translatable == "yes" or translatable == "on"
                    or translatable == "true" or translatable == "1"):
                result[c.get_text_val("name")] = True
            else:
                # when the campaign isn't marked for translation skip it
                if (translatable_only):
                    continue
                else:
                    result[c.get_text_val("name")] = False

        return result
Exemple #2
0
    def get_timestamp(server, addon):
        """Get the timestamp of a campaign on the server.

        server              The url of the addon server eg
                            add-ons.wesnoth.org:15005.
        addon               The name of the addon.
        returns             The timestamp of the campaign, -1 if not on the server.
        """

        logging.debug("get_timestamp server = '%s' addon = %s",
            server, addon)

        wml = libwml.CampaignClient(server, quiet_libwml)
        data = wml.list_campaigns(addon)

        # Item [0] hardcoded seems to work
        campaigns = data.data[0]
        result = {}
        for c in campaigns.get_all("campaign"):
            if(c.get_text_val("name") != addon):
                continue

            return int(c.get_text_val("timestamp"))

        return -1
Exemple #3
0
    def download(server, addon, temp_dir, wescamp_dir, password, stamp=None):

        logging.debug(
            "download addon from wescamp server = '%s' addon = '%s' " +
            "temp_dir = '%s' wescamp_dir = '%s' password is not shown", server,
            addon, temp_dir, wescamp_dir)

        # update the wescamp checkout for the translation,
        addon_obj = libgithub.GitHub(wescamp,
                                     git_version,
                                     userpass=git_userpass).addon(addon)

        # The result of the update can be ignored, no changes when updating
        # doesn't mean no changes to the translations.
        addon_obj.update()

        # test whether the checkout has a translations dir, if not we can stop
        if (os.path.isdir(wescamp + "/" + addon + "/" + addon +
                          "/translations") == False):

            logging.info(
                "Wescamp has no translations directory so we can stop.")
            if (stamp == None):
                return
            else:
                return True

        # Export the entire addon data dir.
        source = os.path.join(wescamp, addon, addon)
        dest = os.path.join(temp_dir, addon)
        shutil.copytree(source, dest)

        # If it is the old format with the addon.cfg copy that as well.
        wescamp_cfg = wescamp + "/" + addon + "/" + addon + ".cfg"
        temp_cfg = temp_dir + "/" + addon + ".cfg"
        if (os.path.isfile(wescamp_cfg)):
            logging.debug("Found old format config file")
            shutil.copy(wescamp_cfg, temp_cfg)

        # We don't test for changes, just upload the stuff.
        # NOTE wml.put_campaign tests whether the addon.cfg exists so
        # send it unconditionally.
        wml = libwml.CampaignClient(server, quiet_libwml)
        ignore = {}
        stuff = {}
        stuff["passphrase"] = password
        if (stamp == None):
            wml.put_campaign(addon, temp_dir + "/" + addon + "/_main.cfg",
                             temp_dir + "/" + addon + "/", ignore, stuff)

            logging.info("New version of addon '%s' downloaded.", addon)
        else:
            if (stamp == get_timestamp(server, addon)):
                wml.put_campaign(addon, temp_dir + "/" + addon + "/_main.cfg",
                                 temp_dir + "/" + addon + "/", ignore, stuff)
                logging.info("New version of addon '%s' downloaded.", addon)
                return True
            else:
                return False
    def extract(server, addon, path):
        
        logging.debug("extract addon server = '%s' addon = '%s' path = '%s'",
            server, addon, path)

        wml = libwml.CampaignClient(server)
        data = wml.get_campaign(addon)
        wml.unpackdir(data, path)
    def download(server, addon, temp_dir, svn_dir, password, stamp = None):

        logging.debug("download addon from wescamp server = '%s' addon = '%s' "
            + "temp_dir = '%s' svn_dir = '%s' password is not shown", 
            server, addon, temp_dir, svn_dir)

        # update the wescamp checkout for the translation, 
        svn = libsvn.SVN(wescamp + "/" + addon)

        # The result of the update can be ignored, no changes when updating
        # doesn't mean no changes to the translations.
        svn.update()

        # test whether the svn has a translations dir, if not we can stop
        if(os.path.isdir(wescamp + "/" 
            + addon + "/" + addon + "/translations") == False):

            logging.info("Wescamp has no translations directory so we can stop.")
            if(stamp == None):
                return
            else:
                return True

        # Export the entire addon data dir.
        svn_addon = libsvn.SVN(wescamp + "/" + addon + "/" + addon)
        svn_addon.export(temp_dir + "/" + addon)

        # If it is the old format with the addon.cfg copy that as well.
        svn_cfg = wescamp + "/" + addon + "/" + addon + ".cfg"
        temp_cfg = temp_dir + "/" + addon + ".cfg"
        if(os.path.isfile(svn_cfg)):
            logging.debug("Found old format config file")
            shutil.copy(svn_cfg, temp_cfg)

        # We don't test for changes, just upload the stuff.
        # NOTE wml.put_campaign tests whether the addon.cfg exists so
        # send it unconditionally.
        wml = libwml.CampaignClient(server)
        if(stamp == None):
            wml.put_campaign("", addon, "", password, "", "", "",  
                temp_dir + "/" + addon + ".cfg", temp_dir + "/" + addon + "/")
            logging.info("New version of addon '%s' downloaded.", addon)
        else:
            if(stamp == get_timestamp(server, addon)):
                wml.put_campaign("", addon, "", password, "", "", "",  
                    temp_dir + "/" + addon + ".cfg", temp_dir + "/" + addon + "/")
                logging.info("New version of addon '%s' downloaded.", addon)
                return True
            else:
                return False
Exemple #6
0
    def extract(server, addon, path):
        """Download an addon from the server.

        server              The url of the addon server eg
                            add-ons.wesnoth.org:15005.
        addon               The name of the addon.
        path                Directory to unpack the campaign in.
        returns             Nothing.
        """

        logging.debug("extract addon server = '%s' addon = '%s' path = '%s'",
                      server, addon, path)

        wml = libwml.CampaignClient(server, quiet_libwml)
        data = wml.get_campaign(addon)
        wml.unpackdir(data, path)
Exemple #7
0
    def get_timestamp(server, addon):

        logging.debug("get_timestamp server = '%s' addon = %s", server, addon)

        wml = libwml.CampaignClient(server)
        data = wml.list_campaigns()

        # Item [0] hardcoded seems to work
        campaigns = data.data[0]
        result = {}
        for c in campaigns.get_all("campaign"):
            if (c.get_text_val("name") != addon):
                continue

            return int(c.get_text_val("timestamp"))

        return -1
    def list(server, translatable_only):
        
        logging.debug("list addons server = '%s' translatable_only = %s",
            server, translatable_only)

        wml = libwml.CampaignClient(server)
        data = wml.list_campaigns()

        # Item [0] hardcoded seems to work
        campaigns = data.data[0]
        result = {}
        for c in campaigns.get_all("campaign"):
            translatable = c.get_text_val("translate")
            if(translatable == "yes" or translatable == "on" or translatable == "true" or translatable == "1"):
                result[c.get_text_val("name")] = True
            else:
                # when the campaign isn't marked for translation skip it
                if(translatable_only):
                    continue
                else:
                    result[c.get_text_val("name")] = False

        return result