Advertisement
Kimarite

/usr/share/screen-resolution-extra/nvidia-polkit (Ubuntu 24.04)

May 18th, 2024
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.23 KB | Software | 0 0
  1. #!/usr/bin/python3
  2. # -*- coding: utf-8 -*-
  3. ## Copyright (C) 2001-2008 Alberto Milone <[email protected]>
  4. ## Copyright (C) 2019 Canonical Ltd
  5.  
  6. ## This program is free software; you can redistribute it and/or modify
  7. ## it under the terms of the GNU General Public License as published by
  8. ## the Free Software Foundation; either version 2 of the License, or
  9. ## (at your option) any later version.
  10.  
  11. ## This program is distributed in the hope that it will be useful,
  12. ## but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. ## GNU General Public License for more details.
  15.  
  16. ## You should have received a copy of the GNU General Public License
  17. ## along with this program; if not, write to the Free Software
  18. ## Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19.  
  20.  
  21. import logging
  22. import argparse
  23. import os
  24. import shutil
  25.  
  26. from xkit import xutils, xorgparser
  27.  
  28.  
  29. # Usage:
  30. # /usr/share/screen-resolution-extra/nvidia-polkit --help
  31. #
  32.  
  33. if __name__ == '__main__':
  34. parser = argparse.ArgumentParser()
  35. parser.add_argument('destination', help='The destination path')
  36. parser.add_argument("-w", "--write-from", help='write xorg.conf from FILE', metavar='FILE')
  37. parser.add_argument("-b", "--backup-to", help='backup file to FILE', metavar='FILE')
  38.  
  39. args = parser.parse_args()
  40.  
  41. if args.backup_to and os.path.isfile(args.destination):
  42. try:
  43. shutil.copyfile(args.destination, args.backup_to)
  44. logging.debug('Making backup of %s to %s' % (args.destination, args.backup_to))
  45. except IOError as e:
  46. logging.error('%s' % e)
  47. exit(1)
  48.  
  49. try:
  50. xutils.XUtils(args.write_from)
  51. logging.debug('%s is a valid xorg.conf file.' % args.write_from)
  52. except(IOError, xorgparser.ParseException):#if xorg.conf is missing or broken
  53. logging.error('%s does not seem to be a valid xorg.conf file.' % args.write_from)
  54. exit(1)
  55.  
  56. try:
  57. shutil.copyfile(args.write_from, args.destination)
  58. logging.debug('%s was written successfully to %s.' % (args.write_from, args.destination))
  59. except IOError as e:
  60. logging.error('%s' % e)
  61. exit(1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement