PageRenderTime 231ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/js/lib/Socket.IO-node/support/expresso/deps/jscoverage/js/config/nsinstall.py

http://github.com/onedayitwillmake/RealtimeMultiplayerNodeJs
Python | 139 lines | 72 code | 13 blank | 54 comment | 17 complexity | 8b434a0e9d3cb4c4fecd56dd1e8d614d MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1, MPL-2.0-no-copyleft-exception, BSD-3-Clause
  1. # ***** BEGIN LICENSE BLOCK *****
  2. # Version: MPL 1.1/GPL 2.0/LGPL 2.1
  3. #
  4. # The contents of this file are subject to the Mozilla Public License Version
  5. # 1.1 (the "License"); you may not use this file except in compliance with
  6. # the License. You may obtain a copy of the License at
  7. # http://www.mozilla.org/MPL/
  8. #
  9. # Software distributed under the License is distributed on an "AS IS" basis,
  10. # WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  11. # for the specific language governing rights and limitations under the
  12. # License.
  13. #
  14. # The Original Code is Mozilla.
  15. #
  16. # The Initial Developer of the Original Code is
  17. # the Mozilla Foundation.
  18. # Portions created by the Initial Developer are Copyright (C) 2007
  19. # the Initial Developer. All Rights Reserved.
  20. #
  21. # Contributor(s):
  22. # Axel Hecht <axel@pike.org>
  23. #
  24. # Alternatively, the contents of this file may be used under the terms of
  25. # either the GNU General Public License Version 2 or later (the "GPL"), or
  26. # the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  27. # in which case the provisions of the GPL or the LGPL are applicable instead
  28. # of those above. If you wish to allow use of your version of this file only
  29. # under the terms of either the GPL or the LGPL, and not to allow others to
  30. # use your version of this file under the terms of the MPL, indicate your
  31. # decision by deleting the provisions above and replace them with the notice
  32. # and other provisions required by the GPL or the LGPL. If you do not delete
  33. # the provisions above, a recipient may use your version of this file under
  34. # the terms of any one of the MPL, the GPL or the LGPL.
  35. #
  36. # ***** END LICENSE BLOCK *****
  37. # This is a partial python port of nsinstall.
  38. # It's intended to be used when there's no natively compile nsinstall
  39. # available, and doesn't intend to be fully equivalent.
  40. # Its major use is for l10n repackaging on systems that don't have
  41. # a full build environment set up.
  42. # The basic limitation is, it doesn't even try to link and ignores
  43. # all related options.
  44. from optparse import OptionParser
  45. import os
  46. import os.path
  47. import sys
  48. import shutil
  49. usage = "usage: %prog [options] arg1 [arg2 ...] target-directory"
  50. p = OptionParser(usage=usage)
  51. p.add_option('-D', action="store_true",
  52. help="Create a single directory only")
  53. p.add_option('-t', action="store_true",
  54. help="Preserve time stamp")
  55. p.add_option('-m', action="store",
  56. help="Set mode", metavar="mode")
  57. p.add_option('-d', action="store_true",
  58. help="Create directories in target")
  59. p.add_option('-R', action="store_true",
  60. help="Use relative symbolic links (ignored)")
  61. p.add_option('-l', action="store_true",
  62. help="Create link (ignored)")
  63. p.add_option('-L', action="store", metavar="linkprefix",
  64. help="Link prefix (ignored)")
  65. # The remaining arguments are not used in our tree, thus they're not
  66. # implented.
  67. def BadArg(option, opt, value, parser):
  68. parser.error('option not supported: %s' % opt)
  69. p.add_option('-C', action="callback", metavar="CWD",
  70. callback=BadArg,
  71. help="NOT SUPPORTED")
  72. p.add_option('-o', action="callback", callback=BadArg,
  73. help="Set owner (NOT SUPPORTED)", metavar="owner")
  74. p.add_option('-g', action="callback", callback=BadArg,
  75. help="Set group (NOT SUPPORTED)", metavar="group")
  76. (options, args) = p.parse_args()
  77. if options.m:
  78. # mode is specified
  79. try:
  80. options.m = int(options.m, 8)
  81. except:
  82. sys.stderr.write('nsinstall: ' + options.m + ' is not a valid mode\n')
  83. sys.exit(1)
  84. # just create one directory?
  85. if options.D:
  86. if len(args) != 1:
  87. sys.exit(1)
  88. if os.path.exists(args[0]):
  89. if not os.path.isdir(args[0]):
  90. sys.stderr.write('nsinstall: ' + args[0] + ' is not a directory\n')
  91. sys.exit(1)
  92. if options.m:
  93. os.chmod(args[0], options.m)
  94. sys.exit()
  95. if options.m:
  96. os.makedirs(args[0], options.m)
  97. else:
  98. os.makedirs(args[0])
  99. sys.exit()
  100. # nsinstall arg1 [...] directory
  101. if len(args) < 2:
  102. p.error('not enough arguments')
  103. # set up handler
  104. if options.d:
  105. # we're supposed to create directories
  106. def handleTarget(srcpath, targetpath):
  107. # target directory was already created, just use mkdir
  108. os.mkdir(dest)
  109. else:
  110. # we're supposed to copy files
  111. def handleTarget(srcpath, targetpath):
  112. if options.t:
  113. shutil.copy2(srcpath, targetpath)
  114. else:
  115. shutil.copy(srcpath, targetpath)
  116. # the last argument is the target directory
  117. target = args.pop()
  118. # ensure target directory
  119. if not os.path.isdir(target):
  120. os.makedirs(target)
  121. for f in args:
  122. dest = os.path.join(target,
  123. os.path.basename(os.path.normpath(f)))
  124. handleTarget(f, dest)
  125. if options.m:
  126. os.chmod(dest, options.m)