Version 6.1.4.1, tag libreoffice-6.1.4.1
[LibreOffice.git] / external / nss / nsinstall.py
blob31b3de3450c59ac13efaf1fa4a2a83a0ed753e6d
1 # ***** BEGIN LICENSE BLOCK *****
2 # Version: MPL 1.1/GPL 2.0/LGPL 2.1
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/
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.
14 # The Original Code is Mozilla.
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.
21 # Contributor(s):
22 # Axel Hecht <axel@pike.org>
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.
36 # ***** END LICENSE BLOCK *****
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.
46 from optparse import OptionParser
47 import os
48 import os.path
49 import sys
50 import shutil
52 def nsinstall(argv):
53 usage = "usage: %prog [options] arg1 [arg2 ...] target-directory"
54 p = OptionParser(usage=usage)
56 p.add_option('-D', action="store_true",
57 help="Create a single directory only")
58 p.add_option('-t', action="store_true",
59 help="Preserve time stamp")
60 p.add_option('-m', action="store",
61 help="Set mode", metavar="mode")
62 p.add_option('-d', action="store_true",
63 help="Create directories in target")
64 p.add_option('-R', action="store_true",
65 help="Use relative symbolic links (ignored)")
66 p.add_option('-l', action="store_true",
67 help="Create link (ignored)")
68 p.add_option('-L', action="store", metavar="linkprefix",
69 help="Link prefix (ignored)")
71 # The remaining arguments are not used in our tree, thus they're not
72 # implented.
73 def BadArg(option, opt, value, parser):
74 parser.error('option not supported: %s' % opt)
76 p.add_option('-C', action="callback", metavar="CWD",
77 callback=BadArg,
78 help="NOT SUPPORTED")
79 p.add_option('-o', action="callback", callback=BadArg,
80 help="Set owner (NOT SUPPORTED)", metavar="owner")
81 p.add_option('-g', action="callback", callback=BadArg,
82 help="Set group (NOT SUPPORTED)", metavar="group")
84 (options, args) = p.parse_args(argv)
86 if options.m:
87 # mode is specified
88 try:
89 options.m = int(options.m, 8)
90 # I have no idea why nss insists on using this mode for installed headers.
91 # It causes problems with updating the files during a rebuild.
92 if options.m == 0o444:
93 options.m = 0o644
94 except:
95 sys.stderr.write('nsinstall: ' + options.m + ' is not a valid mode\n')
96 return 1
98 # just create one directory?
99 if options.D:
100 if len(args) != 1:
101 return 1
102 if os.path.exists(args[0]):
103 if not os.path.isdir(args[0]):
104 sys.stderr.write('nsinstall: ' + args[0] + ' is not a directory\n')
105 sys.exit(1)
106 if options.m:
107 os.chmod(args[0], options.m)
108 sys.exit()
109 if options.m:
110 os.makedirs(args[0], options.m)
111 else:
112 os.makedirs(args[0])
113 return 0
115 # nsinstall arg1 [...] directory
116 if len(args) < 2:
117 p.error('not enough arguments')
119 def copy_all_entries(entries, target):
120 for e in entries:
121 dest = os.path.join(target,
122 os.path.basename(os.path.normpath(e)))
123 handleTarget(e, dest)
124 if options.m:
125 os.chmod(dest, options.m)
127 # set up handler
128 if options.d:
129 # we're supposed to create directories
130 def handleTarget(srcpath, targetpath):
131 # target directory was already created, just use mkdir
132 os.mkdir(targetpath)
133 else:
134 # we're supposed to copy files
135 def handleTarget(srcpath, targetpath):
136 if os.path.isdir(srcpath):
137 if not os.path.exists(targetpath):
138 os.mkdir(targetpath)
139 entries = [os.path.join(srcpath, e) for e in os.listdir(srcpath)]
140 copy_all_entries(entries, targetpath)
141 # options.t is not relevant for directories
142 if options.m:
143 os.chmod(targetpath, options.m)
144 elif options.t:
145 if os.path.exists(targetpath):
146 os.remove(targetpath)
147 shutil.copy2(srcpath, targetpath)
148 else:
149 if os.path.exists(targetpath):
150 os.chmod(targetpath, 0o755)
151 os.remove(targetpath)
152 shutil.copy(srcpath, targetpath)
154 # the last argument is the target directory
155 target = args.pop()
156 # ensure target directory
157 if not os.path.isdir(target):
158 os.makedirs(target)
160 copy_all_entries(args, target)
161 return 0
163 if __name__ == '__main__':
164 sys.exit(nsinstall(sys.argv[1:]))