No Description

setup.py 5.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. #!/usr/bin/env python
  2. # -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
  3. ### BEGIN LICENSE
  4. # Copyright (C) 2013 Bryan M. Allred <bryan.allred@gmail.com>
  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 organiccode 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(libdir, values={}):
  27. filename = os.path.join(libdir, 'organiccode_lib/organiccodeconfig.py')
  28. oldvalues = {}
  29. try:
  30. fin = file(filename, 'r')
  31. fout = file(filename + '.new', 'w')
  32. for line in fin:
  33. fields = line.split(' = ') # Separate variable from value
  34. if fields[0] in values:
  35. oldvalues[fields[0]] = fields[1].strip()
  36. line = "%s = %s\n" % (fields[0], values[fields[0]])
  37. fout.write(line)
  38. fout.flush()
  39. fout.close()
  40. fin.close()
  41. os.rename(fout.name, fin.name)
  42. except (OSError, IOError):
  43. print ("ERROR: Can't find %s" % filename)
  44. sys.exit(1)
  45. return oldvalues
  46. def move_desktop_file(root, target_data, prefix):
  47. # The desktop file is rightly installed into install_data. But it should
  48. # always really be installed into prefix, because while we can install
  49. # normal data files anywhere we want, the desktop file needs to exist in
  50. # the main system to be found. Only actually useful for /opt installs.
  51. old_desktop_path = os.path.normpath(root + target_data +
  52. '/share/applications')
  53. old_desktop_file = old_desktop_path + '/organiccode.desktop'
  54. desktop_path = os.path.normpath(root + prefix + '/share/applications')
  55. desktop_file = desktop_path + '/organiccode.desktop'
  56. if not os.path.exists(old_desktop_file):
  57. print ("ERROR: Can't find", old_desktop_file)
  58. sys.exit(1)
  59. elif target_data != prefix + '/':
  60. # This is an /opt install, so rename desktop file to use extras-
  61. desktop_file = desktop_path + '/extras-organiccode.desktop'
  62. try:
  63. os.makedirs(desktop_path)
  64. os.rename(old_desktop_file, desktop_file)
  65. os.rmdir(old_desktop_path)
  66. except OSError as e:
  67. print ("ERROR: Can't rename", old_desktop_file, ":", e)
  68. sys.exit(1)
  69. return desktop_file
  70. def update_desktop_file(filename, target_pkgdata, target_scripts):
  71. try:
  72. fin = file(filename, 'r')
  73. fout = file(filename + '.new', 'w')
  74. for line in fin:
  75. if 'Icon=' in line:
  76. line = "Icon=%s\n" % (target_pkgdata + 'media/organiccode.svg')
  77. elif 'Exec=' in line:
  78. cmd = line.split("=")[1].split(None, 1)
  79. line = "Exec=%s" % (target_scripts + 'organiccode')
  80. if len(cmd) > 1:
  81. line += " %s" % cmd[1].strip() # Add script arguments back
  82. line += "\n"
  83. fout.write(line)
  84. fout.flush()
  85. fout.close()
  86. fin.close()
  87. os.rename(fout.name, fin.name)
  88. except (OSError, IOError):
  89. print ("ERROR: Can't find %s" % filename)
  90. sys.exit(1)
  91. def compile_schemas(root, target_data):
  92. if target_data == '/usr/':
  93. return # /usr paths don't need this, they will be handled by dpkg
  94. schemadir = os.path.normpath(root + target_data + 'share/glib-2.0/schemas')
  95. if (os.path.isdir(schemadir) and
  96. os.path.isfile('/usr/bin/glib-compile-schemas')):
  97. os.system('/usr/bin/glib-compile-schemas "%s"' % schemadir)
  98. class InstallAndUpdateDataDirectory(DistUtilsExtra.auto.install_auto):
  99. def run(self):
  100. DistUtilsExtra.auto.install_auto.run(self)
  101. target_data = '/' + os.path.relpath(self.install_data, self.root) + '/'
  102. target_pkgdata = target_data + 'share/organiccode/'
  103. target_scripts = '/' + os.path.relpath(self.install_scripts, self.root) + '/'
  104. values = {'__organiccode_data_directory__': "'%s'" % (target_pkgdata),
  105. '__version__': "'%s'" % self.distribution.get_version()}
  106. update_config(self.install_lib, values)
  107. desktop_file = move_desktop_file(self.root, target_data, self.prefix)
  108. update_desktop_file(desktop_file, target_pkgdata, target_scripts)
  109. compile_schemas(self.root, target_data)
  110. ##################################################################################
  111. ###################### YOU SHOULD MODIFY ONLY WHAT IS BELOW ######################
  112. ##################################################################################
  113. DistUtilsExtra.auto.setup(
  114. name='organiccode',
  115. version='0.1-public1',
  116. license='GPL-3',
  117. author='Bryan M. Allred',
  118. author_email='bryan.allred@gmail.com',
  119. description='UI for managing Gource',
  120. long_description='A simple front-end program designed to help create version control visualizations using Gource.',
  121. url='https://launchpad.net/organiccode',
  122. cmdclass={'install': InstallAndUpdateDataDirectory}
  123. )