1. #!/usr/bin/env python
  2. # -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
  3. ### BEGIN LICENSE
  4. # Copyright (C) 2011 Joe Simpson [email protected]
  5. # This program is free software: you can redistribute it and/or modify it
  6. # under the terms of the GNU General Public License version 3, as published
  7. # by the Free Software Foundation.
  8. #
  9. # This program is distributed in the hope that it will be useful, but
  10. # WITHOUT ANY WARRANTY; without even the implied warranties of
  11. # MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
  12. # PURPOSE. See the GNU General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU General Public License along
  15. # with this program. If not, see <http://www.gnu.org/licenses/>.
  16. ### END LICENSE
  17. ###################### DO NOT TOUCH THIS (HEAD TO THE SECOND PART) ######################
  18. import os
  19. import sys
  20. try:
  21. import DistUtilsExtra.auto
  22. except ImportError:
  23. print >> sys.stderr, 'To build project_name you need https://launchpad.net/python-distutils-extra'
  24. sys.exit(1)
  25. assert DistUtilsExtra.auto.__version__ >= '2.18', 'needs DistUtilsExtra.auto >= 2.18'
  26. def update_config(values = {}):
  27. oldvalues = {}
  28. try:
  29. fin = file('one_click_installer_lib/one_click_installerconfig.py', 'r')
  30. fout = file(fin.name + '.new', 'w')
  31. for line in fin:
  32. fields = line.split(' = ') # Separate variable from value
  33. if fields[0] in values:
  34. oldvalues[fields[0]] = fields[1].strip()
  35. line = "%s = %s\n" % (fields[0], values[fields[0]])
  36. fout.write(line)
  37. fout.flush()
  38. fout.close()
  39. fin.close()
  40. os.rename(fout.name, fin.name)
  41. except (OSError, IOError), e:
  42. print ("ERROR: Can't find one_click_installer_lib/one_click_installerconfig.py")
  43. sys.exit(1)
  44. return oldvalues
  45. def update_desktop_file(datadir):
  46. try:
  47. fin = file('one-click-installer.desktop.in', 'r')
  48. fout = file(fin.name + '.new', 'w')
  49. for line in fin:
  50. fout.write(line)
  51. fout.flush()
  52. fout.close()
  53. fin.close()
  54. os.rename(fout.name, fin.name)
  55. except (OSError, IOError), e:
  56. print ("ERROR: Can't find one-click-installer.desktop.in")
  57. sys.exit(1)
  58. class InstallAndUpdateDataDirectory(DistUtilsExtra.auto.install_auto):
  59. def run(self):
  60. values = {'__one-click-installer_data_directory__': "'%s'" % (self.prefix + '/share/one-click-installer/'),
  61. '__version__': "'%s'" % self.distribution.get_version()}
  62. previous_values = update_config(values)
  63. update_desktop_file(self.prefix + '/share/project_name/')
  64. DistUtilsExtra.auto.install_auto.run(self)
  65. update_config(previous_values)
  66. ##################################################################################
  67. ###################### YOU SHOULD MODIFY ONLY WHAT IS BELOW ######################
  68. ##################################################################################
  69. DistUtilsExtra.auto.setup(
  70. name='one-click-installer',
  71. version='0.1',
  72. license='GPL-3',
  73. author='Joe Simpson',
  74. author_email='[email protected]',
  75. url='https://launchpad.net/one-click-installer',
  76. data_files=[('/usr/share/mime/packages', ['one-click-installer.xml'])],
  77. description='Easy PPA installation!',
  78. long_description='Easy PPA installation!',
  79. cmdclass={'install': InstallAndUpdateDataDirectory}
  80. )