From 03e75c2d5aba9f8675b7ddf6fb859e1e5add1c0a Mon Sep 17 00:00:00 2001 From: Benjamin Drung Date: Sat, 10 May 2014 00:25:38 +0200 Subject: install-xpi: Catch RDF.RedlandError exception and print error message. --- install-xpi | 47 ++++++++++++++++++++++++++++------------------- 1 file changed, 28 insertions(+), 19 deletions(-) (limited to 'install-xpi') diff --git a/install-xpi b/install-xpi index d658735..e740454 100755 --- a/install-xpi +++ b/install-xpi @@ -14,6 +14,8 @@ # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +from __future__ import print_function + import csv import optparse import os @@ -36,6 +38,7 @@ LICENSE_PATTERN_LIST = ( # error codes COMMAND_LINE_SYNTAX_ERROR = 1 XPI_FILE_DOES_NOT_EXISTS = 2 +RDF_ERROR = 3 def get_debian_directory(script_name): @@ -124,8 +127,8 @@ def install_xpi(script_name, package, xpi_file, exclude, install_dir, links, debian_directory, verbose=False): # get xpi file content list if not os.path.isfile(xpi_file): - print >> sys.stderr, "%s: Error: xpi file %s does not exist." % \ - (script_name, xpi_file) + print("%s: Error: xpi file %s does not exist." % + (script_name, xpi_file), file=sys.stderr) sys.exit(XPI_FILE_DOES_NOT_EXISTS) zfobj = zipfile.ZipFile(xpi_file) xpi_content = zfobj.namelist() @@ -140,7 +143,7 @@ def install_xpi(script_name, package, xpi_file, exclude, install_dir, links, package.replace("xul-ext-", "")) copy_dir = os.path.join(debian_directory, package, install_dir.strip("/")) if verbose: - print "%s: install directory: %s" % (script_name, install_dir) + print("%s: install directory: %s" % (script_name, install_dir)) # remove documented license files if remove_licenses: @@ -148,7 +151,7 @@ def install_xpi(script_name, package, xpi_file, exclude, install_dir, links, basename = os.path.basename(name).lower() if basename in LICENSE_PATTERN_LIST: exclude.append(name) - print "%s: exclude license file %s" % (script_name, name) + print("%s: exclude license file %s" % (script_name, name)) # create directory and extract xpi file if not os.path.isdir(copy_dir): @@ -157,7 +160,7 @@ def install_xpi(script_name, package, xpi_file, exclude, install_dir, links, if len(exclude) > 0: command.append("-x") command.extend(exclude) - print " ".join(command) + print(" ".join(command)) subprocess.call(command) # correct permissons of files to 644 and directories to 755 @@ -167,20 +170,20 @@ def install_xpi(script_name, package, xpi_file, exclude, install_dir, links, if os.path.exists(filename): mode = get_mode(filename) if os.path.isdir(filename) and mode != 0755: - print "%s: correct permission from %s to %s of %s" % \ - (script_name, oct(mode), oct(0755), name) + print("%s: correct permission from %s to %s of %s" % + (script_name, oct(mode), oct(0755), name)) os.chmod(filename, 0755) elif os.path.isfile(filename): header = open(filename, "r").read(2) if header != "#!" and mode != 0644: # file without shebang - print "%s: correct permission from %s to %s of %s" % \ - (script_name, oct(mode), oct(0644), name) + print("%s: correct permission from %s to %s of %s" % + (script_name, oct(mode), oct(0644), name)) os.chmod(filename, 0644) elif header == "#!" and mode != 0755: # file with shebang - print "%s: correct permission from %s to %s of %s" % \ - (script_name, oct(mode), oct(0755), name) + print("%s: correct permission from %s to %s of %s" % + (script_name, oct(mode), oct(0755), name)) os.chmod(filename, 0755) # create a system preference file in /etc @@ -219,13 +222,18 @@ def install_xpi(script_name, package, xpi_file, exclude, install_dir, links, "000system.js") command = ["dh_link", "-p" + package, link_source, link_target] if verbose: - print " ".join(command) + print(" ".join(command)) subprocess.call(command) # get symlinks list - extension_id = get_extension_id(os.path.join(copy_dir, "install.rdf")) - filename = os.path.join(copy_dir, "install.rdf") - target_applications = get_target_applications(filename) + try: + extension_id = get_extension_id(os.path.join(copy_dir, "install.rdf")) + filename = os.path.join(copy_dir, "install.rdf") + target_applications = get_target_applications(filename) + except RDF.RedlandError as error: + print(script_name + ": Error while parsing install.rdf: " + str(error), + file=sys.stderr) + sys.exit(RDF_ERROR) for target_application in target_applications: destination = os.path.join("/usr", lib_share_dir, "mozilla/extensions", target_application, extension_id) @@ -234,7 +242,7 @@ def install_xpi(script_name, package, xpi_file, exclude, install_dir, links, # create symlinks for link in links: command = ["dh_link", "-p" + package, install_dir, link] - print " ".join(command) + print(" ".join(command)) subprocess.call(command) @@ -278,11 +286,12 @@ def main(): (options, args) = parser.parse_args() if len(args) == 0: - print >> sys.stderr, "%s: Error: No xpi file specified." % (script_name) + print("%s: Error: No xpi file specified." % (script_name), + file=sys.stderr) sys.exit(COMMAND_LINE_SYNTAX_ERROR) elif len(args) > 1: - print >> sys.stderr, "%s: Error: Multiple xpi files specified: %s" % \ - (script_name, ", ".join(args)) + print("%s: Error: Multiple xpi files specified: %s" % + (script_name, ", ".join(args)), file=sys.stderr) sys.exit(COMMAND_LINE_SYNTAX_ERROR) debian_directory = get_debian_directory(script_name) -- cgit v1.2.3