pylupdate.py 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. # Copyright (c) 2026 Riverbank Computing Limited <info@riverbankcomputing.com>
  2. #
  3. # This file is part of PyQt6.
  4. #
  5. # This file may be used under the terms of the GNU General Public License
  6. # version 3.0 as published by the Free Software Foundation and appearing in
  7. # the file LICENSE included in the packaging of this file. Please review the
  8. # following information to ensure the GNU General Public License version 3.0
  9. # requirements will be met: http://www.gnu.org/copyleft/gpl.html.
  10. #
  11. # If you do not wish to use this file under the terms of the GPL version 3.0
  12. # then you may purchase a commercial license. For more information contact
  13. # info@riverbankcomputing.com.
  14. #
  15. # This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
  16. # WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  17. import sys
  18. from .lupdate import lupdate
  19. def main():
  20. """ Update a .ts file from a .py file. """
  21. import argparse
  22. from PyQt6.QtCore import PYQT_VERSION_STR
  23. from .user import UserException
  24. # The program name.
  25. PROGRAM_NAME = 'pylupdate6'
  26. # Parse the command line.
  27. parser = argparse.ArgumentParser(prog=PROGRAM_NAME,
  28. description="Python Language Update Tool")
  29. parser.add_argument('-V', '--version', action='version',
  30. version=PYQT_VERSION_STR)
  31. parser.add_argument('--exclude', action='append', metavar="PATTERN",
  32. help="exclude matching files when reading a directory")
  33. parser.add_argument('--no-obsolete', '-no-obsolete', action='store_true',
  34. help="remove any obsolete translated messages")
  35. parser.add_argument('--no-summary', action='store_true',
  36. help="suppress the summary")
  37. parser.add_argument('--ts', '-ts', action='append', metavar="FILE",
  38. required=True,
  39. help="a .ts file to update or create")
  40. parser.add_argument('--verbose', action='store_true',
  41. help="show progress messages")
  42. parser.add_argument('file', nargs='+',
  43. help="the .py or .ui file, or directory to be read")
  44. args = parser.parse_args()
  45. # Update the translation files.
  46. try:
  47. lupdate(args.file, args.ts, args.no_obsolete, args.no_summary,
  48. args.verbose, args.exclude)
  49. except UserException as e:
  50. print("{0}: {1}".format(PROGRAM_NAME, e), file=sys.stderr)
  51. return 1
  52. except:
  53. if args.verbose:
  54. import traceback
  55. traceback.print_exception(*sys.exc_info())
  56. else:
  57. print("""An unexpected error occurred.
  58. Check that you are using the latest version of {name} and send an error
  59. report to the PyQt mailing list and include the following information:
  60. - the version of {name} ({version})
  61. - the .py or .ui file that caused the error (as an attachment)
  62. - the verbose output of {name} (use the --verbose flag when calling
  63. {name})""".format(name=PROGRAM_NAME, version=PYQT_VERSION_STR),
  64. file=sys.stderr)
  65. return 2
  66. return 0
  67. if __name__ == '__main__':
  68. sys.exit(main())