setup.py 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. #
  4. # Copyright (C) 2017 AquilaNipalensis
  5. #
  6. # This program is free software; you can redistribute it and/or modify it
  7. # under the terms of the GNU General Public License as published by the
  8. # Free Software Foundation; either version 2 of the License, or (at your
  9. # option) any later version. Please read the COPYING file.
  10. #
  11. import sys
  12. import os
  13. import glob
  14. import shutil
  15. import parser
  16. version = "3.0.0"
  17. distfiles = """
  18. setup.py
  19. bin/*.py
  20. etc/scomd.conf
  21. po/scomd.pot
  22. po/*.po
  23. """
  24. i18n_source_list = ["bin/scomd.py", "bin/service.py"]
  25. def update_messages():
  26. os.system("xgettext -o po/scomd.pot %s" % " ".join(i18n_source_list))
  27. for item in os.listdir("po"):
  28. if item.endswith(".po"):
  29. os.system("msgmerge -q -o temp.po po/%s po/scomd.pot" % item)
  30. os.system("cp temp.po po/%s" % item)
  31. os.system("rm -f temp.po")
  32. def make_dist():
  33. distdir = "scomd-%s" % version
  34. list = []
  35. for t in distfiles.split():
  36. list.extend(glob.glob(t))
  37. if os.path.exists(distdir):
  38. shutil.rmtree(distdir)
  39. os.mkdir(distdir)
  40. for file_ in list:
  41. cum = distdir[:]
  42. for d in os.path.dirname(file_).split('/'):
  43. dn = os.path.join(cum, d)
  44. cum = dn[:]
  45. if not os.path.exists(dn):
  46. os.mkdir(dn)
  47. shutil.copy(file_, os.path.join(distdir, file_))
  48. os.popen("tar -cjf %s %s" % ("scomd-" + version + ".tar.bz2", distdir))
  49. shutil.rmtree(distdir)
  50. def install_file(source, prefix, dest):
  51. dest = os.path.join(prefix, dest)
  52. if os.path.islink(dest):
  53. os.unlink(dest)
  54. try:
  55. os.makedirs(os.path.dirname(dest))
  56. except:
  57. pass
  58. print("installing '%s' to '%s'" % (source, dest))
  59. os.system("cp %s %s" % (source, dest))
  60. def install(args):
  61. if args == []:
  62. prefix = "/"
  63. else:
  64. prefix = args[0]
  65. # Make sure that there isn't a syntax error in scomd.py
  66. code = open("bin/scomd.py").read()
  67. parser.suite(code).compile()
  68. install_file("bin/scomd.py", prefix, "sbin/mudur.py")
  69. install_file("bin/scomd_tmpfiles.py", prefix, "sbin/mudur_tmpfiles.py")
  70. install_file("bin/scomd_cgroupfs.py", prefix, "sbin/mudur_cgroupfs.py")
  71. install_file("bin/update-environment.py", prefix, "sbin/update-environment")
  72. install_file("bin/update-fstab.py", prefix, "sbin/update-fstab")
  73. install_file("bin/compat.py", prefix, "etc/init.d/compat.py")
  74. install_file("bin/service.py", prefix, "bin/service")
  75. install_file("bin/adduser.py", prefix, "sbin/adduser")
  76. install_file("bin/deluser.py", prefix, "sbin/deluser")
  77. install_file("etc/scomd.conf", prefix, "etc/conf.d/mudur")
  78. for item in os.listdir("po"):
  79. if item.endswith(".po"):
  80. lang = item[:-3]
  81. dest = "usr/share/locale/%s/LC_MESSAGES/scomd.mo" % lang
  82. try:
  83. os.makedirs(os.path.dirname(os.path.join(prefix, dest)))
  84. except:
  85. pass
  86. path = os.path.join(prefix, dest)
  87. print("compiling '%s' translation '%s'" % (lang, path))
  88. os.system("msgfmt po/%s -o %s" % (item, path))
  89. def usage():
  90. print("setup.py install [prefix]")
  91. print("setup.py update_messages")
  92. print("setup.py dist")
  93. def do_setup(args):
  94. if args == []:
  95. usage()
  96. elif args[0] == "install":
  97. install(args[1:])
  98. elif args[0] == "update_messages":
  99. update_messages()
  100. elif args[0] == "dist":
  101. make_dist()
  102. else:
  103. usage()
  104. if __name__ == "__main__":
  105. do_setup(sys.argv[1:])