diff -Nru ubuntu-l10n-tools-0.1+bzr40~oneiric1/bin/translations-lp-disable ubuntu-l10n-tools-0.1+bzr41~oneiric1/bin/translations-lp-disable --- ubuntu-l10n-tools-0.1+bzr40~oneiric1/bin/translations-lp-disable 1970-01-01 00:00:00.000000000 +0000 +++ ubuntu-l10n-tools-0.1+bzr41~oneiric1/bin/translations-lp-disable 2012-08-03 13:35:36.000000000 +0000 @@ -0,0 +1,23 @@ +#!/usr/bin/python +# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*- +### BEGIN LICENSE +# This file is in the public domain +### END LICENSE + +import os +import sys + +# Add project root directory (enable symlink, and trunk execution). +PROJECT_ROOT_DIRECTORY = os.path.abspath( + os.path.dirname(os.path.dirname(os.path.realpath(sys.argv[0])))) + +if (os.path.exists(os.path.join(PROJECT_ROOT_DIRECTORY, 'ubuntu_l10n_tools')) + and PROJECT_ROOT_DIRECTORY not in sys.path): + sys.path.insert(0, PROJECT_ROOT_DIRECTORY) + os.putenv('PYTHONPATH', PROJECT_ROOT_DIRECTORY) # for subprocesses + +import ubuntu_l10n_tools.translations_lp_disable as \ + translations_lp_disable + +translations_lp_disable.main() + diff -Nru ubuntu-l10n-tools-0.1+bzr40~oneiric1/bin/translations-lp-setpriority ubuntu-l10n-tools-0.1+bzr41~oneiric1/bin/translations-lp-setpriority --- ubuntu-l10n-tools-0.1+bzr40~oneiric1/bin/translations-lp-setpriority 2012-04-16 13:49:54.000000000 +0000 +++ ubuntu-l10n-tools-0.1+bzr41~oneiric1/bin/translations-lp-setpriority 2012-08-03 13:35:36.000000000 +0000 @@ -16,8 +16,8 @@ sys.path.insert(0, PROJECT_ROOT_DIRECTORY) os.putenv('PYTHONPATH', PROJECT_ROOT_DIRECTORY) # for subprocesses -import ubuntu_l10n_tools.translations_set_pot_priority as \ - translations_set_pot_priority +import ubuntu_l10n_tools.translations_lp_setpriority as \ + translations_lp_setpriority -translations_set_pot_priority.main() +translations_lp_setpriority.main() diff -Nru ubuntu-l10n-tools-0.1+bzr40~oneiric1/debian/bzr-builder.manifest ubuntu-l10n-tools-0.1+bzr41~oneiric1/debian/bzr-builder.manifest --- ubuntu-l10n-tools-0.1+bzr40~oneiric1/debian/bzr-builder.manifest 2012-04-16 13:49:54.000000000 +0000 +++ ubuntu-l10n-tools-0.1+bzr41~oneiric1/debian/bzr-builder.manifest 2012-08-03 13:35:36.000000000 +0000 @@ -1,2 +1,2 @@ -# bzr-builder format 0.3 deb-version {debupstream}+bzr40 -lp:ubuntu-l10n-tools revid:david.planella@ubuntu.com-20120416133138-i6ml3c5kd4dxxbf0 +# bzr-builder format 0.3 deb-version {debupstream}+bzr41 +lp:ubuntu-l10n-tools revid:david.planella@ubuntu.com-20120803132513-dg37evdhf7vw109y diff -Nru ubuntu-l10n-tools-0.1+bzr40~oneiric1/debian/changelog ubuntu-l10n-tools-0.1+bzr41~oneiric1/debian/changelog --- ubuntu-l10n-tools-0.1+bzr40~oneiric1/debian/changelog 2012-04-16 13:49:54.000000000 +0000 +++ ubuntu-l10n-tools-0.1+bzr41~oneiric1/debian/changelog 2012-08-03 13:35:36.000000000 +0000 @@ -1,8 +1,8 @@ -ubuntu-l10n-tools (0.1+bzr40~oneiric1) oneiric; urgency=low +ubuntu-l10n-tools (0.1+bzr41~oneiric1) oneiric; urgency=low * Auto build. - -- David Planella Mon, 16 Apr 2012 13:49:54 +0000 + -- David Planella Fri, 03 Aug 2012 13:35:36 +0000 ubuntu-l10n-tools (0.1) oneiric; urgency=low diff -Nru ubuntu-l10n-tools-0.1+bzr40~oneiric1/ubuntu_l10n_tools/translations_lp_disable/__init__.py ubuntu-l10n-tools-0.1+bzr41~oneiric1/ubuntu_l10n_tools/translations_lp_disable/__init__.py --- ubuntu-l10n-tools-0.1+bzr40~oneiric1/ubuntu_l10n_tools/translations_lp_disable/__init__.py 1970-01-01 00:00:00.000000000 +0000 +++ ubuntu-l10n-tools-0.1+bzr41~oneiric1/ubuntu_l10n_tools/translations_lp_disable/__init__.py 2012-08-03 13:35:36.000000000 +0000 @@ -0,0 +1,147 @@ +#!/usr/bin/env python +# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*- +# +# Copyright (c) 2011 Canonical Services Ltd. +# +# Original author: David Planella +# +# Inspired by the ubuntu-translators-tools search-translation +# script, by Sebastian Heinlein +# +# This program is free software: you can redistribute it and/or modify it +# under the terms of the GNU General Public License version 3, as published +# by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranties of +# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR +# PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program. If not, see . +# +# Sets the priorities of translatable templates in Launchpad according to the +# given CSV file. +# +# The list of templates and their priorities can be seen at: +# +# https://translations.launchpad.net/ubuntu/natty/+templates +# +# Note that we cannot fully use the LP API in a nice way, but the current +# script uses a workaround that works pretty well. +# The missing bits from the API are the traversal bits where you'd be able to +# walk the templates from within already exposed objects, instead of using +# "launchpad.load()" directly + +# TODO: Generalize the script to be able to: +# - Change template names (name property) +# - Disable templates (active, exported_in_languagepacks properties) + +import sys +import logging +import optparse +import platform +from ubuntu_l10n_tools.utils.launchpadmanager import (get_launchpad, + get_distro_codenames, + ) +from ubuntu_l10n_tools.utils import PotUtil + +LEVELS = (logging.ERROR, + logging.WARNING, + logging.INFO, + logging.DEBUG, + ) +DEFAULT_DISTRO_CODENAME = platform.dist()[2] # Codename of current system. + + +def main(): + # Support for command line options. + USAGE = """%prog [OPTIONS] FILE + + Disable translatable templates in Launchpad. + + Templates can be disabled either by specifying a single template and the + relevant options (e.g. + '%prog --source evolution --template evolution') or + by specifying a list of templates in a CSV file with the following format + e.g.: + + Source package,Template name + sessioninstaller,sessioninstaller + gnome-user-share,gnome-user-share + gsettings-desktop-schemas,gsettings-desktop-schemas + + Note that when specifying a single template an additional option can be + passed: 'active'. This option defines whether the template is still + visible and translatable in Launchpad despite it being disabled from + the language packs. If you use the CSV option, there is no possibility + to specify this parameter and templates will be hidden from Launchpad + and not be exported in language packs""" + + parser = optparse.OptionParser(usage = USAGE) + parser.add_option("-c", "--distro-codenames", dest="distro_codenames", + help = ("Specify one or more distro's codenames. " + + "Default is the version of your system. " + + "Comma-separated when specifying more than one.")) + parser.add_option('-d', '--debug', dest='debug_mode', action='store_true', + help = 'Print the maximum debugging info (implies -vvv)') + parser.add_option('-f', '--csv-file', dest='csv_file', + help = 'Specify a CSV file with templates to disable') + parser.add_option('-l', '--use-staging', dest='use_staging', + action='store_true', + help = 'Whether to use the launchpad "staging" server. The ' + \ + 'default is "production"') + parser.add_option('-a', '--active', dest='active', + help = 'Set the template as active in Launchpad. Use this in ' + \ + 'conjunction with -t and -s') + parser.add_option('-s', '--source', dest='source', + help = 'Source package. Use this in conjunction with -t') + parser.add_option('-t', '--template', dest='template', + help = 'Template name. Use this in conjunction with -s') + parser.add_option('-v', '--verbose', dest='logging_level', action='count', + help = 'Set error_level output to warning, info, and then debug') + + parser.set_defaults(logging_level = 0, + use_staging = False, + active = False, + distro_codenames = DEFAULT_DISTRO_CODENAME) + (options, args) = parser.parse_args() + + # Set the verbosity + if options.debug_mode: + options.logging_level = 3 + logging.basicConfig(level = LEVELS[options.logging_level], + format = '%(asctime)s %(levelname)s %(message)s') + + # Log into Launchpad + launchpad = get_launchpad(options.use_staging) + + releases = options.distro_codenames.strip().split(',') + logging.debug("Use staging: {0}".format(options.use_staging)) + logging.debug("Specified releases: {0}".format(', '.join(releases))) + + # Validate specified distro's codenames + for rel in releases: + if not rel in get_distro_codenames(launchpad): + msg = "ERROR: {0} is not a valid Ubuntu " + \ + "release name.".format(rel) + error_and_exit(msg, parser.print_help()) + + pot_util = PotUtil.PotUtil(launchpad, releases) + + if options.source and options.template: + pot_util.disable_in_langpacks(options.source, options.template, + options.active) + elif options.csv_file: + pot_util.disable_in_langpacks_csv(options.csv_file) + else: + msg = 'ERROR: Not enough arguments. Either ' + \ + 'specify a CSV file with -f or the parameters -s, -t ' + \ + 'must be specified.' + error_and_exit(msg, parser.print_help()) + + +def error_and_exit(message, help_message_func): + print >> sys.stderr, '\n' + message + '\n' + help_message_func + sys.exit(1) diff -Nru ubuntu-l10n-tools-0.1+bzr40~oneiric1/ubuntu_l10n_tools/translations_lp_gettarballs/__init__.py ubuntu-l10n-tools-0.1+bzr41~oneiric1/ubuntu_l10n_tools/translations_lp_gettarballs/__init__.py --- ubuntu-l10n-tools-0.1+bzr40~oneiric1/ubuntu_l10n_tools/translations_lp_gettarballs/__init__.py 2012-04-16 13:49:54.000000000 +0000 +++ ubuntu-l10n-tools-0.1+bzr41~oneiric1/ubuntu_l10n_tools/translations_lp_gettarballs/__init__.py 2012-08-03 13:35:36.000000000 +0000 @@ -79,6 +79,7 @@ for url in upload.custom_file_urls: url = url.replace('lplibrarian.internal', 'launchpadlibrarian.net') + print json.dumps({ 'name': upload.display_name, 'version': upload.display_version, @@ -86,5 +87,6 @@ 'translations': upload.custom_file_urls}, default=dthandler, sort_keys=True, indent=4) + ',' print ']' + if __name__ == "__main__": main() diff -Nru ubuntu-l10n-tools-0.1+bzr40~oneiric1/ubuntu_l10n_tools/translations_lp_setpriority/__init__.py ubuntu-l10n-tools-0.1+bzr41~oneiric1/ubuntu_l10n_tools/translations_lp_setpriority/__init__.py --- ubuntu-l10n-tools-0.1+bzr40~oneiric1/ubuntu_l10n_tools/translations_lp_setpriority/__init__.py 1970-01-01 00:00:00.000000000 +0000 +++ ubuntu-l10n-tools-0.1+bzr41~oneiric1/ubuntu_l10n_tools/translations_lp_setpriority/__init__.py 2012-08-03 13:35:36.000000000 +0000 @@ -0,0 +1,148 @@ +#!/usr/bin/env python +# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*- +# +# Copyright (c) 2011 Canonical Services Ltd. +# +# Original author: David Planella +# +# Inspired by the ubuntu-translators-tools search-translation +# script, by Sebastian Heinlein +# +# This program is free software: you can redistribute it and/or modify it +# under the terms of the GNU General Public License version 3, as published +# by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranties of +# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR +# PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program. If not, see . +# +# Sets the priorities of translatable templates in Launchpad according to the +# given CSV file. +# +# The list of templates and their priorities can be seen at: +# +# https://translations.launchpad.net/ubuntu/natty/+templates +# +# Note that we cannot fully use the LP API in a nice way, but the current +# script uses a workaround that works pretty well. +# The missing bits from the API are the traversal bits where you'd be able to +# walk the templates from within already exposed objects, instead of using +# "launchpad.load()" directly + +# TODO: Generalize the script to be able to: +# - Change template names (name property) +# - Disable templates (active, exported_in_languagepacks properties) + +import sys +import logging +import optparse +import platform +from ubuntu_l10n_tools.utils.launchpadmanager import (get_launchpad, + get_distro_codenames, + ) +from ubuntu_l10n_tools.utils.PotUtil import PotUtil + +LEVELS = (logging.ERROR, + logging.WARNING, + logging.INFO, + logging.DEBUG, + ) +DEFAULT_DISTRO_CODENAME = platform.dist()[2] # Codename of current system. + + +def main(): + # Support for command line options. + USAGE = """%prog [OPTIONS] FILE + + Sets the priorities of translatable templates in Launchpad. + Priorities can be set either by specifying a single template and the + relevant options (e.g. + '%prog --priority 1500 --source evolution --template evolution') or + by specifying a list of templates in a CSV file with the following format + e.g.: + + Priority,Source package,Template name + 9010,sessioninstaller,sessioninstaller + 7200,gnome-user-share,gnome-user-share + 72a00,gsettings-desktop-schemas,gsettings-desktop-schemas + + Only priority values in the 0-9999 range are accepted. For more info on + how to assign priorities see: + + https://wiki.ubuntu.com/Translations/TemplatesPriority""" + + parser = optparse.OptionParser(usage = USAGE) + parser.add_option("-c", "--distro-codenames", dest="distro_codenames", + help = ("Specify one or more distro's codenames. " + + "Default is the version of your system. " + + "Comma-separated when specifying more than one.")) + parser.add_option('-d', '--debug', dest='debug_mode', action='store_true', + help = 'Print the maximum debugging info (implies -vvv)') + parser.add_option('-f', '--csv-file', dest='csv_file', + help = 'Specify a CSV file with templates and their desired ' + + 'priorities') + parser.add_option('-l', '--use-staging', dest='use_staging', + action='store_true', + help = 'Whether to use the launchpad "staging" server. The ' + \ + 'default is "production"') + parser.add_option('-p', '--priority', dest='priority', + help = 'Set priority. Use this in conjunction with -t and -s') + parser.add_option('-s', '--source', dest='source', + help = 'Source package. Use this in conjunction with -t') + parser.add_option('-t', '--template', dest='template', + help = 'Template name. Use this in conjunction with -s') + parser.add_option('-v', '--verbose', dest='logging_level', action='count', + help = 'Set error_level output to warning, info, and then debug') + + parser.set_defaults(logging_level = 0, + use_staging = False, + distro_codenames = DEFAULT_DISTRO_CODENAME) + (options, args) = parser.parse_args() + + # Set the verbosity + if options.debug_mode: + options.logging_level = 3 + logging.basicConfig(level = LEVELS[options.logging_level], + format = '%(asctime)s %(levelname)s %(message)s') + + # Log into Launchpad + launchpad = get_launchpad(options.use_staging) + + releases = options.distro_codenames.strip().split(',') + logging.debug("Use staging: {0}".format(options.use_staging)) + logging.debug("Specified releases: {0}".format(', '.join(releases))) + + # Validate specified distro's codenames + for rel in releases: + if not rel in get_distro_codenames(launchpad): + msg = "ERROR: {0} is not a valid Ubuntu " + \ + "release name.".format(rel) + error_and_exit(msg, parser.print_help()) + + if options.priority and int(options.priority) not in range(9999): + msg = "ERROR: priority must be within the 0-9999 range. " + \ + "You specified {0}".format(options.priority) + error_and_exit(msg, parser.print_help()) + + pot_util = PotUtil.PotUtil(launchpad, releases) + + if options.source and options.template and options.priority: + pot_util.set_priority(options.source, options.template, + options.priority) + elif options.csv_file: + pot_util.set_priorities_csv(options.csv_file) + else: + msg = 'ERROR: Not enough arguments. Either ' + \ + 'specify a CSV file with -f or the parameters -s, -t ' + \ + 'and -p must be specified.' + error_and_exit(msg, parser.print_help()) + + +def error_and_exit(message, help_message_func): + print >> sys.stderr, '\n' + message + '\n' + help_message_func + sys.exit(1) diff -Nru ubuntu-l10n-tools-0.1+bzr40~oneiric1/ubuntu_l10n_tools/translations_set_pot_priority/__init__.py ubuntu-l10n-tools-0.1+bzr41~oneiric1/ubuntu_l10n_tools/translations_set_pot_priority/__init__.py --- ubuntu-l10n-tools-0.1+bzr40~oneiric1/ubuntu_l10n_tools/translations_set_pot_priority/__init__.py 2012-04-16 13:49:54.000000000 +0000 +++ ubuntu-l10n-tools-0.1+bzr41~oneiric1/ubuntu_l10n_tools/translations_set_pot_priority/__init__.py 1970-01-01 00:00:00.000000000 +0000 @@ -1,148 +0,0 @@ -#!/usr/bin/env python -# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*- -# -# Copyright (c) 2011 Canonical Services Ltd. -# -# Original author: David Planella -# -# Inspired by the ubuntu-translators-tools search-translation -# script, by Sebastian Heinlein -# -# This program is free software: you can redistribute it and/or modify it -# under the terms of the GNU General Public License version 3, as published -# by the Free Software Foundation. -# -# This program is distributed in the hope that it will be useful, but -# WITHOUT ANY WARRANTY; without even the implied warranties of -# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR -# PURPOSE. See the GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License along -# with this program. If not, see . -# -# Sets the priorities of translatable templates in Launchpad according to the -# given CSV file. -# -# The list of templates and their priorities can be seen at: -# -# https://translations.launchpad.net/ubuntu/natty/+templates -# -# Note that we cannot fully use the LP API in a nice way, but the current -# script uses a workaround that works pretty well. -# The missing bits from the API are the traversal bits where you'd be able to -# walk the templates from within already exposed objects, instead of using -# "launchpad.load()" directly - -# TODO: Generalize the script to be able to: -# - Change template names (name property) -# - Disable templates (active, exported_in_languagepacks properties) - -import sys -import logging -import optparse -import platform -from ubuntu_l10n_tools.utils.launchpadmanager import (get_launchpad, - get_distro_codenames, - ) -from ubuntu_l10n_tools.translations_set_pot_priority.PotUtil import PotUtil - -LEVELS = (logging.ERROR, - logging.WARNING, - logging.INFO, - logging.DEBUG, - ) -DEFAULT_DISTRO_CODENAME = platform.dist()[2] # Codename of current system. - - -def main(): - # Support for command line options. - USAGE = """%prog [OPTIONS] FILE - - Sets the priorities of translatable templates in Launchpad. - Priorities can be set either by specifying a single template and the - relevant options (e.g. - '%prog --priority 1500 --source evolution --template evolution') or - by specifying a list of templates in a CSV file with the following format - e.g.: - - Priority,Source package,Template name - 9010,sessioninstaller,sessioninstaller - 7200,gnome-user-share,gnome-user-share - 72a00,gsettings-desktop-schemas,gsettings-desktop-schemas - - Only priority values in the 0-9999 range are accepted. For more info on - how to assign priorities see: - - https://wiki.ubuntu.com/Translations/TemplatesPriority""" - - parser = optparse.OptionParser(usage = USAGE) - parser.add_option("-c", "--distro-codenames", dest="distro_codenames", - help = ("Specify one or more distro's codenames. " + - "Default is the version of your system. " + - "Comma-separated when specifying more than one.")) - parser.add_option('-d', '--debug', dest='debug_mode', action='store_true', - help = 'Print the maximum debugging info (implies -vvv)') - parser.add_option('-f', '--csv-file', dest='csv_file', - help = 'Specify a CSV file with templates and their desired ' + - 'priorities') - parser.add_option('-l', '--use-staging', dest='use_staging', - action='store_true', - help = 'Whether to use the launchpad "staging" server. The ' + \ - 'default is "production"') - parser.add_option('-p', '--priority', dest='priority', - help = 'Set priority. Use this in conjunction with -t and -s') - parser.add_option('-s', '--source', dest='source', - help = 'Source package. Use this in conjunction with -t') - parser.add_option('-t', '--template', dest='template', - help = 'Template name. Use this in conjunction with -s') - parser.add_option('-v', '--verbose', dest='logging_level', action='count', - help = 'Set error_level output to warning, info, and then debug') - - parser.set_defaults(logging_level = 0, - use_staging = False, - distro_codenames = DEFAULT_DISTRO_CODENAME) - (options, args) = parser.parse_args() - - # Set the verbosity - if options.debug_mode: - options.logging_level = 3 - logging.basicConfig(level = LEVELS[options.logging_level], - format = '%(asctime)s %(levelname)s %(message)s') - - # Log into Launchpad - launchpad = get_launchpad(options.use_staging) - - releases = options.distro_codenames.strip().split(',') - logging.debug("Use staging: {0}".format(options.use_staging)) - logging.debug("Specified releases: {0}".format(', '.join(releases))) - - # Validate specified distro's codenames - for rel in releases: - if not rel in get_distro_codenames(launchpad): - msg = "ERROR: {0} is not a valid Ubuntu " + \ - "release name.".format(rel) - error_and_exit(msg, parser.print_help()) - - if options.priority and int(options.priority) not in range(9999): - msg = "ERROR: priority must be within the 0-9999 range. " + \ - "You specified {0}".format(options.priority) - error_and_exit(msg, parser.print_help()) - - pot_util = PotUtil(launchpad, releases) - - if options.source and options.template and options.priority: - pot_util.set_priority(options.source, options.template, - options.priority) - elif options.csv_file: - pot_util.set_priorities_csv(options.csv_file) - else: - msg = 'ERROR: Not enough arguments. Either ' + \ - 'specify a CSV file with -f or the parameters -s, -t ' + \ - 'and -p must be specified.' - error_and_exit(msg, parser.print_help()) - - -def error_and_exit(message, help_message_func): - print >> sys.stderr, '\n' + message + '\n' - help_message_func - sys.exit(1) diff -Nru ubuntu-l10n-tools-0.1+bzr40~oneiric1/ubuntu_l10n_tools/translations_set_pot_priority/PotUtil.py ubuntu-l10n-tools-0.1+bzr41~oneiric1/ubuntu_l10n_tools/translations_set_pot_priority/PotUtil.py --- ubuntu-l10n-tools-0.1+bzr40~oneiric1/ubuntu_l10n_tools/translations_set_pot_priority/PotUtil.py 2012-04-16 13:49:54.000000000 +0000 +++ ubuntu-l10n-tools-0.1+bzr41~oneiric1/ubuntu_l10n_tools/translations_set_pot_priority/PotUtil.py 1970-01-01 00:00:00.000000000 +0000 @@ -1,87 +0,0 @@ -#!/usr/bin/env python -# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*- -# -# Original author: Rachid BM -# -# This program is free software: you can redistribute it and/or modify it -# under the terms of the GNU General Public License version 3, as published -# by the Free Software Foundation. -# -# This program is distributed in the hope that it will be useful, but -# WITHOUT ANY WARRANTY; without even the implied warranties of -# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR -# PURPOSE. See the GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License along -# with this program. If not, see . - -import logging -import sys -import csv - - -class PotUtil(object): - """ - Utility class for changing properties of po templates - """ - - def __init__(self, launchpad, releases): - self.launchpad = launchpad - self.releases = releases - self.api_url = self.launchpad.distributions['ubuntu'] - logging.debug("API URL: {0}".format(self.api_url)) - - def set_priority(self, source, template, priority): - """ - Sets the priority of a template - - Keyword arguments: - source -- the source package - template -- the name of the template - priority -- the new priority - """ - print "Setting {0}/{1}'s priority to {2}...".format(source, template, - priority) - - for release in self.releases: - URL = '{0}/{1}/+source/{2}/+pots/{3}'.format(self.api_url, - release, source, template) - logging.debug("API URL: {0}".format(URL)) - pot = self.launchpad.load(URL) - pot.priority = self.__validate_priority(priority) - pot.lp_save() - - def set_priorities_csv(self, csv_filename): - """ - Read templates/priorities from the CSV file - and set the priority of each template - - Keyword arguments: - csv_filename -- the filename of the CSV file to read - """ - # Read the CSV file - with open(csv_filename, 'rb') as f: - reader = csv.DictReader(f) - prio_key, srcpkg_key, pot_key = reader.fieldnames - for row in reader: - priority = row[prio_key] - source = row[srcpkg_key].strip() - template = row[pot_key].strip() - self.set_priority(source, template, priority) - - def __validate_priority(self, priority): - try: - priority = int(priority) - except: - print >> sys.stderr, 'ERROR: {0} is not a valid integer as ' \ - 'priority.'.format(priority) - sys.exit(1) - if priority not in range(9999): - print >> sys.stderr, 'ERROR: {0} is outside of the range of ' \ - 'valid priorities (0-9999).'.format(priority) - sys.exit(1) - return priority - - def set_name(self, source, template, new_name): - # TODO - pass diff -Nru ubuntu-l10n-tools-0.1+bzr40~oneiric1/ubuntu_l10n_tools/utils/PotUtil.py ubuntu-l10n-tools-0.1+bzr41~oneiric1/ubuntu_l10n_tools/utils/PotUtil.py --- ubuntu-l10n-tools-0.1+bzr40~oneiric1/ubuntu_l10n_tools/utils/PotUtil.py 1970-01-01 00:00:00.000000000 +0000 +++ ubuntu-l10n-tools-0.1+bzr41~oneiric1/ubuntu_l10n_tools/utils/PotUtil.py 2012-08-03 13:35:36.000000000 +0000 @@ -0,0 +1,128 @@ +#!/usr/bin/env python +# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*- +# +# Original author: Rachid BM +# +# This program is free software: you can redistribute it and/or modify it +# under the terms of the GNU General Public License version 3, as published +# by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranties of +# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR +# PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program. If not, see . + +import logging +import sys +import csv + + +class PotUtil(object): + """ + Utility class for changing properties of po templates + """ + + def __init__(self, launchpad, releases): + self.launchpad = launchpad + self.releases = releases + self.api_url = self.launchpad.distributions['ubuntu'] + logging.debug("API URL: {0}".format(self.api_url)) + + def set_priority(self, source, template, priority): + """ + Sets the priority of a template + + Keyword arguments: + source -- the source package + template -- the name of the template + priority -- the new priority + """ + print "Setting {0}/{1}'s priority to {2}...".format(source, template, + priority) + + for release in self.releases: + URL = '{0}/{1}/+source/{2}/+pots/{3}'.format(self.api_url, + release, source, template) + logging.debug("API URL: {0}".format(URL)) + pot = self.launchpad.load(URL) + pot.priority = self.__validate_priority(priority) + pot.lp_save() + + def set_priorities_csv(self, csv_filename): + """ + Read templates/priorities from the CSV file + and set the priority of each template + + Keyword arguments: + csv_filename -- the filename of the CSV file to read + """ + # Read the CSV file + with open(csv_filename, 'rb') as f: + reader = csv.DictReader(f) + prio_key, srcpkg_key, pot_key = reader.fieldnames + for row in reader: + priority = row[prio_key] + source = row[srcpkg_key].strip() + print "Source:", source + template = row[pot_key].strip() + print "Template:", template + self.set_priority(source, template, priority) + + def __validate_priority(self, priority): + try: + priority = int(priority) + except: + print >> sys.stderr, 'ERROR: {0} is not a valid integer as ' \ + 'priority.'.format(priority) + sys.exit(1) + if priority not in range(9999): + print >> sys.stderr, 'ERROR: {0} is outside of the range of ' \ + 'valid priorities (0-9999).'.format(priority) + sys.exit(1) + return priority + + def set_name(self, source, template, new_name): + # TODO + pass + + def disable_in_langpacks(self, source, template, set_active=False): + """ + Sets the priority of a template + + Keyword arguments: + source -- the source package + template -- the name of the template + set_active -- whether the template must be set as active in LP + """ + print "Disabling {0}/{1}...".format(source, template) + + for release in self.releases: + URL = '{0}/{1}/+source/{2}/+pots/{3}'.format(self.api_url, + release, source, template) + logging.debug("API URL: {0}".format(URL)) + pot = self.launchpad.load(URL) + pot.exported_in_languagepacks = False + pot.active = set_active + pot.lp_save() + + def disable_in_langpacks_csv(self, csv_filename): + """ + Read templates/priorities from the CSV file + and set the priority of each template + + Keyword arguments: + csv_filename -- the filename of the CSV file to read + """ + # Read the CSV file + with open(csv_filename, 'rb') as f: + reader = csv.DictReader(f) + srcpkg_key, pot_key = reader.fieldnames + for row in reader: + source = row[srcpkg_key].strip() + print "Source:", source + template = row[pot_key].strip() + print "Template:", template + self.disable_in_langpacks(source, template)