123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150 |
- import os
- import sys
- try:
- import DistUtilsExtra.auto
- except ImportError:
- print >> sys.stderr, 'To build organiccode you need https://launchpad.net/python-distutils-extra'
- sys.exit(1)
- assert DistUtilsExtra.auto.__version__ >= '2.18', 'needs DistUtilsExtra.auto >= 2.18'
- def update_config(libdir, values={}):
- filename = os.path.join(libdir, 'organiccode_lib/organiccodeconfig.py')
- oldvalues = {}
- try:
- fin = file(filename, 'r')
- fout = file(filename + '.new', 'w')
- for line in fin:
- fields = line.split(' = ')
- if fields[0] in values:
- oldvalues[fields[0]] = fields[1].strip()
- line = "%s = %s\n" % (fields[0], values[fields[0]])
- fout.write(line)
- fout.flush()
- fout.close()
- fin.close()
- os.rename(fout.name, fin.name)
- except (OSError, IOError):
- print ("ERROR: Can't find %s" % filename)
- sys.exit(1)
- return oldvalues
- def move_desktop_file(root, target_data, prefix):
-
-
-
-
- old_desktop_path = os.path.normpath(root + target_data +
- '/share/applications')
- old_desktop_file = old_desktop_path + '/organiccode.desktop'
- desktop_path = os.path.normpath(root + prefix + '/share/applications')
- desktop_file = desktop_path + '/organiccode.desktop'
- if not os.path.exists(old_desktop_file):
- print ("ERROR: Can't find", old_desktop_file)
- sys.exit(1)
- elif target_data != prefix + '/':
-
- desktop_file = desktop_path + '/extras-organiccode.desktop'
- try:
- os.makedirs(desktop_path)
- os.rename(old_desktop_file, desktop_file)
- os.rmdir(old_desktop_path)
- except OSError as e:
- print ("ERROR: Can't rename", old_desktop_file, ":", e)
- sys.exit(1)
- return desktop_file
- def update_desktop_file(filename, target_pkgdata, target_scripts):
- try:
- fin = file(filename, 'r')
- fout = file(filename + '.new', 'w')
- for line in fin:
- if 'Icon=' in line:
- line = "Icon=%s\n" % (target_pkgdata + 'media/organiccode.svg')
- elif 'Exec=' in line:
- cmd = line.split("=")[1].split(None, 1)
- line = "Exec=%s" % (target_scripts + 'organiccode')
- if len(cmd) > 1:
- line += " %s" % cmd[1].strip()
- line += "\n"
- fout.write(line)
- fout.flush()
- fout.close()
- fin.close()
- os.rename(fout.name, fin.name)
- except (OSError, IOError):
- print ("ERROR: Can't find %s" % filename)
- sys.exit(1)
- def compile_schemas(root, target_data):
- if target_data == '/usr/':
- return
- schemadir = os.path.normpath(root + target_data + 'share/glib-2.0/schemas')
- if (os.path.isdir(schemadir) and
- os.path.isfile('/usr/bin/glib-compile-schemas')):
- os.system('/usr/bin/glib-compile-schemas "%s"' % schemadir)
- class InstallAndUpdateDataDirectory(DistUtilsExtra.auto.install_auto):
- def run(self):
- DistUtilsExtra.auto.install_auto.run(self)
- target_data = '/' + os.path.relpath(self.install_data, self.root) + '/'
- target_pkgdata = target_data + 'share/organiccode/'
- target_scripts = '/' + os.path.relpath(self.install_scripts, self.root) + '/'
- values = {'__organiccode_data_directory__': "'%s'" % (target_pkgdata),
- '__version__': "'%s'" % self.distribution.get_version()}
- update_config(self.install_lib, values)
- desktop_file = move_desktop_file(self.root, target_data, self.prefix)
- update_desktop_file(desktop_file, target_pkgdata, target_scripts)
- compile_schemas(self.root, target_data)
- DistUtilsExtra.auto.setup(
- name='organiccode',
- version='0.1-public1',
- license='GPL-3',
- author='Bryan M. Allred',
- author_email='bryan.allred@gmail.com',
- description='UI for managing Gource',
- long_description='A simple front-end program designed to help create version control visualizations using Gource.',
- url='https://launchpad.net/organiccode',
- cmdclass={'install': InstallAndUpdateDataDirectory}
- )
|