PageRenderTime 70ms CodeModel.GetById 54ms app.highlight 12ms RepoModel.GetById 1ms 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 | 16 complexity | 8b434a0e9d3cb4c4fecd56dd1e8d614d MD5 | raw file
  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
 38# This is a partial python port of nsinstall.
 39# It's intended to be used when there's no natively compile nsinstall
 40# available, and doesn't intend to be fully equivalent.
 41# Its major use is for l10n repackaging on systems that don't have
 42# a full build environment set up.
 43# The basic limitation is, it doesn't even try to link and ignores
 44# all related options.
 45
 46from optparse import OptionParser
 47import os
 48import os.path
 49import sys
 50import shutil
 51
 52usage = "usage: %prog [options] arg1 [arg2 ...] target-directory"
 53p = OptionParser(usage=usage)
 54
 55p.add_option('-D', action="store_true",
 56             help="Create a single directory only")
 57p.add_option('-t', action="store_true",
 58             help="Preserve time stamp")
 59p.add_option('-m', action="store",
 60             help="Set mode", metavar="mode")
 61p.add_option('-d', action="store_true",
 62             help="Create directories in target")
 63p.add_option('-R', action="store_true",
 64             help="Use relative symbolic links (ignored)")
 65p.add_option('-l', action="store_true",
 66             help="Create link (ignored)")
 67p.add_option('-L', action="store", metavar="linkprefix",
 68             help="Link prefix (ignored)")
 69
 70# The remaining arguments are not used in our tree, thus they're not
 71# implented.
 72def BadArg(option, opt, value, parser):
 73  parser.error('option not supported: %s' % opt)
 74
 75p.add_option('-C', action="callback", metavar="CWD",
 76             callback=BadArg,
 77             help="NOT SUPPORTED")
 78p.add_option('-o', action="callback", callback=BadArg,
 79             help="Set owner (NOT SUPPORTED)", metavar="owner")
 80p.add_option('-g', action="callback", callback=BadArg,
 81             help="Set group (NOT SUPPORTED)", metavar="group")
 82
 83(options, args) = p.parse_args()
 84
 85if options.m:
 86  # mode is specified
 87  try:
 88    options.m = int(options.m, 8)
 89  except:
 90    sys.stderr.write('nsinstall: ' + options.m + ' is not a valid mode\n')
 91    sys.exit(1)
 92
 93# just create one directory?
 94if options.D:
 95  if len(args) != 1:
 96    sys.exit(1)
 97  if os.path.exists(args[0]):
 98    if not os.path.isdir(args[0]):
 99      sys.stderr.write('nsinstall: ' + args[0] + ' is not a directory\n')
100      sys.exit(1)
101    if options.m:
102      os.chmod(args[0], options.m)
103    sys.exit()
104  if options.m:
105    os.makedirs(args[0], options.m)
106  else:
107    os.makedirs(args[0])
108  sys.exit()
109
110# nsinstall arg1 [...] directory
111if len(args) < 2:
112  p.error('not enough arguments')
113
114# set up handler
115if options.d:
116  # we're supposed to create directories
117  def handleTarget(srcpath, targetpath):
118    # target directory was already created, just use mkdir
119    os.mkdir(dest)
120else:
121  # we're supposed to copy files
122  def handleTarget(srcpath, targetpath):
123    if options.t:
124      shutil.copy2(srcpath, targetpath)
125    else:
126      shutil.copy(srcpath, targetpath)
127
128# the last argument is the target directory
129target = args.pop()
130# ensure target directory
131if not os.path.isdir(target):
132  os.makedirs(target)
133
134for f in args:
135  dest = os.path.join(target,
136                      os.path.basename(os.path.normpath(f)))
137  handleTarget(f, dest)
138  if options.m:
139    os.chmod(dest, options.m)