diff options
| -rwxr-xr-x | tools/generate-plugin.py | 30 | ||||
| -rw-r--r-- | tools/preprocessor.py | 5 | 
2 files changed, 18 insertions, 17 deletions
| diff --git a/tools/generate-plugin.py b/tools/generate-plugin.py index 151a8f31..073f5104 100755 --- a/tools/generate-plugin.py +++ b/tools/generate-plugin.py @@ -1,11 +1,11 @@ -#!/usr/bin/env python +#!/usr/bin/env python3  # -*- coding: utf-8 -*-  # generate-plugin.py - pluma plugin skeletton generator  # This file is part of pluma  #  # Copyright (C) 2006 - Steve Frécinaux -# Copyright (C) 2012-2021 MATE Developers +# Copyright (C) 2012-2022 MATE Developers  #  # pluma is free software; you can redistribute it and/or modify  # it under the terms of the GNU General Public License as published by @@ -82,14 +82,14 @@ try:                                  'with-bottom-pane'  , 'without-bottom-pane',                                  'with-config-dlg'   , 'without-config-dlg',                                  'help']) -except getopt.error, exc: -    print >>sys.stderr, '%s: %s' % (sys.argv[0], str(exc)) -    print >>sys.stderr, USAGE +except getopt.error as exc: +    print('%s: %s' % (sys.argv[0], str(exc)), file=sys.stderr) +    print(USAGE, file=sys.stderr)      sys.exit(1)  for opt, arg in opts:      if opt in ('-h', '--help'): -        print >>sys.stderr, HELP +        print(HELP, file=sys.stderr)          sys.exit(0)      elif opt in ('--description', '--author', '--email'): @@ -109,7 +109,7 @@ for opt, arg in opts:  # What's the new plugin name ?  if len(args) < 1: -    print >>sys.stderr, USAGE +    print(USAGE, file=sys.stderr)      sys.exit(1)  plugin_name = args[0] @@ -129,15 +129,15 @@ directives = {  # Files to be generated by the preprocessor, in the form "template : outfile"  output_files = {      'Makefile.am': '%s/Makefile.am' % plugin_module, -    'pluma-plugin.desktop.in': '%s/%s.pluma-plugin.desktop.in' % (plugin_module, plugin_module) +    'pluma-plugin.desktop.in': '%s/%s.plugin.desktop.in.in' % (plugin_module, plugin_module)  }  if options['language'] == 'c':      output_files['pluma-plugin.c'] = '%s/%s-plugin.c' % (plugin_module, plugin_module)      output_files['pluma-plugin.h'] = '%s/%s-plugin.h' % (plugin_module, plugin_module)  else: -    print >>sys.stderr, 'Value of --language should be C' -    print >>sys.stderr, USAGE +    print('Value of --language should be C', file=sys.stderr) +    print(USAGE, file=sys.stderr)      sys.exit(1)  if options['standalone']: @@ -157,15 +157,15 @@ if options['with-config-dlg']:  # Generate the plugin base -for infile, outfile in output_files.iteritems(): -    print 'Processing %s\n' \ -          '      into %s...' % (infile, outfile) +for infile, outfile in output_files.items(): +    print('Processing %s\n' \ +          '      into %s...' % (infile, outfile))      infile = os.path.join(TEMPLATE_DIR, infile)      outfile = os.path.join(os.getcwd(), outfile)      if not os.path.isfile(infile): -        print >>sys.stderr, 'Input file does not exist : %s.' % os.path.basename(infile) +        print('Input file does not exist : %s.' % os.path.basename(infile), file=sys.stderr)          continue      # Make sure the destination directory exists @@ -178,6 +178,6 @@ for infile, outfile in output_files.iteritems():      # Generate the file      preprocessor.process(infile, outfile, directives.copy()) -print 'Done.' +print('Done.')  # ex:ts=4:et: diff --git a/tools/preprocessor.py b/tools/preprocessor.py index f78647bf..4292af02 100644 --- a/tools/preprocessor.py +++ b/tools/preprocessor.py @@ -23,6 +23,7 @@  import sys  import re +import io  class DeepnessException(Exception):      def __init__(self): @@ -64,13 +65,13 @@ def _subvar(match, macros):      return val  def process(infile = sys.stdin, outfile = sys.stdout, macros = {}): -    if not isinstance(infile, file): +    if not isinstance(infile, io.IOBase):          infile = open(infile, mode = 'r')          close_infile = True      else:          close_infile = False -    if not isinstance(outfile, file): +    if not isinstance(outfile, io.IOBase):          outfile = open(outfile, mode = 'w')          close_outfile = True      else: | 
