PageRenderTime 55ms CodeModel.GetById 27ms RepoModel.GetById 1ms app.codeStats 0ms

/kde/display-settings/setup.py

https://bitbucket.org/baris/pardus-projects
Python | 196 lines | 132 code | 31 blank | 33 comment | 26 complexity | 4de618fc3574cfb3cf2bb4b3349737ed MD5 | raw file
  1. #!/usr/bin/python
  2. # -*- coding: utf-8 -*-
  3. #
  4. # Copyright (C) 2006-2011 TUBITAK/UEKAE
  5. #
  6. # This program is free software; you can redistribute it and/or modify it under
  7. # the terms of the GNU General Public License as published by the Free
  8. # Software Foundation; either version 2 of the License, or (at your option)
  9. # any later version.
  10. #
  11. # Please read the COPYING file.
  12. #
  13. import os
  14. import sys
  15. import glob
  16. import tempfile
  17. from distutils.core import setup
  18. from distutils.command.build import build
  19. from distutils.command.install import install
  20. from src.displaysettings import about
  21. PROJECT = about.appName
  22. # For future PDS integration, uncomment the following lines
  23. # when ready.
  24. if True:#'kde4' in sys.argv:
  25. #sys.argv.remove('kde4')
  26. FOR_KDE_4 = True
  27. print 'UI files will be created for KDE 4..'
  28. def makeDirs(directory):
  29. if not os.path.exists(directory):
  30. try:
  31. os.makedirs(directory)
  32. except OSError:
  33. pass
  34. def update_messages():
  35. files = tempfile.mkstemp()[1]
  36. # Collect UI files
  37. filelist = []
  38. for filename in glob.glob1("ui", "*.ui"):
  39. if FOR_KDE_4:
  40. os.system("/usr/kde/4/bin/pykde4uic -o ui/ui_%s.py ui/%s" % (filename.split(".")[0], filename))
  41. else:
  42. os.system("/usr/bin/pyuic4 -o ui/ui_%s.py ui/%s -g %s" % (filename.split(".")[0], filename, PROJECT))
  43. # Collect headers for desktop files
  44. for filename in glob.glob("data/*.desktop.in"):
  45. os.system("intltool-extract --type=gettext/ini %s" % filename)
  46. filelist = os.popen("find data src ui -name '*.h' -o -name '*.py'").read().strip().split("\n")
  47. filelist.sort()
  48. with open(files, "w") as _files:
  49. _files.write("\n".join(filelist))
  50. # Generate POT file
  51. os.system("xgettext --default-domain=%s \
  52. --keyword=_ \
  53. --keyword=N_ \
  54. --keyword=i18n \
  55. --keyword=ki18n \
  56. --kde \
  57. -ci18n -ki18n:1 -ki18nc:1c,2 -ki18np:1,2 -ki18ncp:1c,2,3 -ktr2i18n:1 \
  58. -kI18N_NOOP:1 -kI18N_NOOP2:1c,2 -kaliasLocale -kki18n:1 -kki18nc:1c,2 \
  59. -kki18np:1,2 -kki18ncp:1c,2,3 \
  60. --files-from=%s \
  61. -o po/%s.pot" % (PROJECT, files, PROJECT))
  62. # Update PO files
  63. for item in glob.glob1("po", "*.po"):
  64. os.system("msgmerge --update --no-wrap --sort-by-file po/%s po/%s.pot" % (item, PROJECT))
  65. # Cleanup
  66. os.unlink(files)
  67. for f in [_f for _f in filelist if _f.startswith("ui/") or _f.endswith(".h")]:
  68. try:
  69. os.unlink(f)
  70. except OSError:
  71. pass
  72. class Build(build):
  73. def run(self):
  74. # Clear all
  75. os.system("rm -rf build")
  76. makeDirs("build/app")
  77. makeDirs("build/lib/xcb")
  78. # Copy codes
  79. print "Copying PYs..."
  80. os.system("cp -R src/* build/app/")
  81. # Create xcb binding
  82. os.system("python xcb/py_client.py xcb/nvctrl.xml")
  83. self.move_file("nvctrl.py", "build/lib/xcb/")
  84. # Copy compiled UIs and RCs
  85. print "Generating UIs..."
  86. for filename in glob.glob1("ui", "*.ui"):
  87. os.system("/usr/kde/4/bin/pykde4uic -o build/app/%s/ui_%s.py ui/%s" % (about.modName, filename.split(".")[0], filename))
  88. print "Generating RCs..."
  89. for filename in glob.glob1("data", "*.qrc"):
  90. os.system("/usr/bin/pyrcc4 data/%s -o build/app/%s_rc.py" % (filename, filename.split(".")[0]))
  91. class Install(install):
  92. def run(self):
  93. install.run(self)
  94. if self.root:
  95. kde_dir = "%s/usr/kde/4" % self.root
  96. else:
  97. kde_dir = "/usr/kde/4"
  98. bin_dir = os.path.join(kde_dir, "bin")
  99. locale_dir = os.path.join(kde_dir, "share/locale")
  100. service_dir = os.path.join(kde_dir, "share/kde4/services")
  101. apps_dir = os.path.join(kde_dir, "share/applications/kde4")
  102. project_dir = os.path.join(kde_dir, "share/apps", about.appName)
  103. # Make directories
  104. print "Making directories..."
  105. makeDirs(bin_dir)
  106. makeDirs(locale_dir)
  107. makeDirs(service_dir)
  108. makeDirs(apps_dir)
  109. makeDirs(project_dir)
  110. # Install desktop files
  111. print "Installing desktop files..."
  112. for filename in glob.glob("data/*.desktop.in"):
  113. os.system("intltool-merge -d po %s %s" % (filename, filename[:-3]))
  114. self.copy_file("data/kcm_%s.desktop" % about.modName, service_dir)
  115. self.copy_file("data/kcm_displaydevices.desktop", service_dir)
  116. self.copy_file("data/%s.desktop" % about.modName, apps_dir)
  117. # Install codes
  118. print "Installing codes..."
  119. os.system("cp -R build/app/* %s/" % project_dir)
  120. # Install locales
  121. print "Installing locales..."
  122. for filename in glob.glob1("po", "*.po"):
  123. lang = filename.rsplit(".", 1)[0]
  124. os.system("msgfmt po/%s.po -o po/%s.mo" % (lang, lang))
  125. try:
  126. os.makedirs(os.path.join(locale_dir, "%s/LC_MESSAGES" % lang))
  127. except OSError:
  128. pass
  129. self.copy_file("po/%s.mo" % lang, os.path.join(locale_dir, "%s/LC_MESSAGES" % lang, "%s.mo" % about.catalog))
  130. # Rename
  131. #print "Renaming application.py..."
  132. #self.move_file(os.path.join(project_dir, "application.py"), os.path.join(project_dir, "%s.py" % about.appName))
  133. # Modes
  134. print "Changing file modes..."
  135. os.chmod(os.path.join(project_dir, "%s.sh" % about.appName), 0755)
  136. # Symlink
  137. try:
  138. if self.root:
  139. os.symlink(os.path.join(project_dir.replace(self.root, ""), "%s.sh" % about.appName), os.path.join(bin_dir, about.appName))
  140. else:
  141. os.symlink(os.path.join(project_dir, "%s.sh" % about.appName), os.path.join(bin_dir, about.appName))
  142. except OSError:
  143. pass
  144. if "update_messages" in sys.argv:
  145. update_messages()
  146. sys.exit(0)
  147. setup(
  148. name = about.appName,
  149. version = about.version,
  150. description = str(about.description.toString()),
  151. license = str(about.aboutData.licenseName(about.aboutData.ShortName)),
  152. author = "Pardus Developers",
  153. author_email = about.bugEmail,
  154. url = about.homePage,
  155. packages = [''],
  156. package_dir = {'': ''},
  157. data_files = [],
  158. cmdclass = {
  159. 'build': Build,
  160. 'install': Install,
  161. }
  162. )