blob: 39b2c21e0606e63985e1ae5df821d0f28b561c83 [file] [log] [blame]
Joe Gregorioc47fab72011-07-06 08:29:20 -04001#!/usr/bin/python2.4
2# -*- coding: utf-8 -*-
3#
4# Copyright (C) 2010 Google Inc.
5#
6# Licensed under the Apache License, Version 2.0 (the "License");
7# you may not use this file except in compliance with the License.
8# You may obtain a copy of the License at
9#
10# http://www.apache.org/licenses/LICENSE-2.0
11#
12# Unless required by applicable law or agreed to in writing, software
13# distributed under the License is distributed on an "AS IS" BASIS,
14# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15# See the License for the specific language governing permissions and
16# limitations under the License.
17
18"""Copy files from source to dest expanding symlinks along the way.
19"""
20
Joe Gregoriod667c9d2011-10-17 13:25:24 -040021from shutil import copytree
Joe Gregoriob17c7632011-04-05 01:31:55 -040022
Joe Gregorioc47fab72011-07-06 08:29:20 -040023import gflags
24import sys
25
26
27FLAGS = gflags.FLAGS
28
Joe Gregoriod667c9d2011-10-17 13:25:24 -040029# Ignore these files and directories when copying over files into the snapshot.
30IGNORE = set(['.hg', 'httplib2', 'oauth2', 'simplejson', 'static', 'gflags.py',
31 'gflags_validators.py'])
32
33# In addition to the above files also ignore these files and directories when
34# copying over samples into the snapshot.
35IGNORE_IN_SAMPLES = set(['apiclient', 'oauth2client', 'uritemplate'])
36
37
Joe Gregorioc47fab72011-07-06 08:29:20 -040038gflags.DEFINE_string('source', '.', 'Directory name to copy from.')
39gflags.DEFINE_string('dest', 'snapshot', 'Directory name to copy to.')
40
41
Joe Gregoriod667c9d2011-10-17 13:25:24 -040042def _ignore(path, names):
43 retval = set()
44 if path != '.':
45 retval = retval.union(IGNORE_IN_SAMPLES.intersection(names))
46 retval = retval.union(IGNORE.intersection(names))
47 return retval
48
49
Joe Gregorioc47fab72011-07-06 08:29:20 -040050def main(argv):
51 # Let the gflags module process the command-line arguments
52 try:
53 argv = FLAGS(argv)
54 except gflags.FlagsError, e:
55 print '%s\\nUsage: %s ARGS\\n%s' % (e, argv[0], FLAGS)
56 sys.exit(1)
57
Joe Gregoriod667c9d2011-10-17 13:25:24 -040058 copytree(FLAGS.source, FLAGS.dest, symlinks=True,
59 ignore=_ignore)
Joe Gregorioc47fab72011-07-06 08:29:20 -040060
61
62if __name__ == '__main__':
63 main(sys.argv)