setup.py 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. import glob
  2. import os
  3. import shutil
  4. import subprocess
  5. import sys
  6. from distutils.cmd import Command
  7. from setuptools import setup
  8. from lvc.variables import (
  9. __version__
  10. )
  11. if sys.version < '2.7':
  12. raise RuntimeError('LVC requires Python 2.7')
  13. def icon_data_files():
  14. sizes = [16, 22, 32, 48]
  15. data_files = []
  16. for size in sizes:
  17. d = os.path.join("icons", "hicolor", "%sx%s" % (size, size), "apps")
  18. source = os.path.join(SETUP_DIR, d, "librevideoconverter.png")
  19. dest = os.path.join("/usr/share/", d)
  20. data_files.append((dest, [source]))
  21. return data_files
  22. def application_data_files():
  23. return [
  24. ('/usr/share/applications',
  25. [os.path.join(SETUP_DIR, 'librevideoconverter.desktop')]),
  26. ]
  27. def data_files():
  28. return application_data_files() + icon_data_files()
  29. class sdist_deb(Command):
  30. description = ("Build a debian source package.")
  31. user_options = [
  32. ('dist-dir=', 'd',
  33. "directory to put the source distribution archive(s) in "
  34. "[default: dist]"),
  35. ]
  36. def initialize_options(self):
  37. self.dist_dir = None
  38. def finalize_options(self):
  39. if self.dist_dir is None:
  40. self.dist_dir = 'dist'
  41. self.dist_dir = os.path.abspath(self.dist_dir)
  42. def run(self):
  43. self.run_command("sdist")
  44. self.setup_dirs()
  45. for debian_dir in glob.glob(os.path.join(
  46. SETUP_DIR, 'debian-*')):
  47. self.build_for_release(debian_dir)
  48. os.chdir(self.orig_dir)
  49. print('')
  50. print("debian source build complete")
  51. print("files are in %s" % self.work_dir)
  52. def build_for_release(self, debian_dir):
  53. os.chdir(self.work_dir)
  54. source_tree = os.path.join(
  55. self.work_dir,
  56. 'librevideoconverter-%s' % __version__)
  57. if os.path.exists(source_tree):
  58. shutil.rmtree(source_tree)
  59. self.extract_tarball()
  60. self.copy_debian_directory(debian_dir)
  61. os.chdir('librevideoconverter-%s' % __version__)
  62. subprocess.check_call(['dpkg-buildpackage', '-S'])
  63. def setup_dirs(self):
  64. self.orig_dir = os.getcwd()
  65. self.work_dir = os.path.join(self.dist_dir, 'deb')
  66. if os.path.exists(self.work_dir):
  67. shutil.rmtree(self.work_dir)
  68. os.makedirs(self.work_dir)
  69. def extract_tarball(self):
  70. tarball = os.path.join(
  71. self.dist_dir,
  72. "librevideoconverter-%s.tar.gz" % __version__)
  73. subprocess.check_call(["tar", "zxf", tarball])
  74. shutil.copyfile(
  75. tarball,
  76. "librevideoconverter_%s.orig.tar.gz" % __version__)
  77. def copy_debian_directory(self, debian_dir):
  78. dest = os.path.join(
  79. self.work_dir,
  80. 'librevideoconverter-%s/debian' % __version__)
  81. shutil.copytree(debian_dir, dest)
  82. setup(
  83. cmdclass={
  84. 'sdist_deb': sdist_deb,
  85. },
  86. data_files=data_files(),
  87. scripts=['scripts/libre-video-converter.py'],
  88. **SETUP_ARGS
  89. )