Craig Citro | 15744b1 | 2015-03-02 13:34:32 -0800 | [diff] [blame] | 1 | #!/usr/bin/env python |
Joe Gregorio | c47fab7 | 2011-07-06 08:29:20 -0400 | [diff] [blame] | 2 | # -*- coding: utf-8 -*- |
| 3 | # |
Craig Citro | 751b7fb | 2014-09-23 11:20:38 -0700 | [diff] [blame] | 4 | # Copyright 2014 Google Inc. All Rights Reserved. |
Joe Gregorio | c47fab7 | 2011-07-06 08:29:20 -0400 | [diff] [blame] | 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 Gregorio | d667c9d | 2011-10-17 13:25:24 -0400 | [diff] [blame] | 21 | from shutil import copytree |
Joe Gregorio | b17c763 | 2011-04-05 01:31:55 -0400 | [diff] [blame] | 22 | |
Joe Gregorio | 79daca0 | 2013-03-29 16:25:52 -0400 | [diff] [blame] | 23 | import argparse |
Joe Gregorio | c47fab7 | 2011-07-06 08:29:20 -0400 | [diff] [blame] | 24 | import sys |
| 25 | |
| 26 | |
Joe Gregorio | d667c9d | 2011-10-17 13:25:24 -0400 | [diff] [blame] | 27 | # Ignore these files and directories when copying over files into the snapshot. |
Joe Gregorio | 79daca0 | 2013-03-29 16:25:52 -0400 | [diff] [blame] | 28 | IGNORE = set(['.hg', 'httplib2', 'oauth2', 'simplejson', 'static']) |
Joe Gregorio | d667c9d | 2011-10-17 13:25:24 -0400 | [diff] [blame] | 29 | |
| 30 | # In addition to the above files also ignore these files and directories when |
| 31 | # copying over samples into the snapshot. |
John Asmuth | 864311d | 2014-04-24 15:46:08 -0400 | [diff] [blame] | 32 | IGNORE_IN_SAMPLES = set(['googleapiclient', 'oauth2client', 'uritemplate']) |
Joe Gregorio | d667c9d | 2011-10-17 13:25:24 -0400 | [diff] [blame] | 33 | |
Joe Gregorio | 79daca0 | 2013-03-29 16:25:52 -0400 | [diff] [blame] | 34 | parser = argparse.ArgumentParser(description=__doc__) |
Joe Gregorio | d667c9d | 2011-10-17 13:25:24 -0400 | [diff] [blame] | 35 | |
Joe Gregorio | 79daca0 | 2013-03-29 16:25:52 -0400 | [diff] [blame] | 36 | parser.add_argument('--source', default='.', |
| 37 | help='Directory name to copy from.') |
| 38 | |
| 39 | parser.add_argument('--dest', default='snapshot', |
| 40 | help='Directory name to copy to.') |
Joe Gregorio | c47fab7 | 2011-07-06 08:29:20 -0400 | [diff] [blame] | 41 | |
| 42 | |
Joe Gregorio | d667c9d | 2011-10-17 13:25:24 -0400 | [diff] [blame] | 43 | def _ignore(path, names): |
| 44 | retval = set() |
| 45 | if path != '.': |
| 46 | retval = retval.union(IGNORE_IN_SAMPLES.intersection(names)) |
| 47 | retval = retval.union(IGNORE.intersection(names)) |
| 48 | return retval |
| 49 | |
| 50 | |
Joe Gregorio | 79daca0 | 2013-03-29 16:25:52 -0400 | [diff] [blame] | 51 | def main(): |
Joe Gregorio | d667c9d | 2011-10-17 13:25:24 -0400 | [diff] [blame] | 52 | copytree(FLAGS.source, FLAGS.dest, symlinks=True, |
| 53 | ignore=_ignore) |
Joe Gregorio | c47fab7 | 2011-07-06 08:29:20 -0400 | [diff] [blame] | 54 | |
| 55 | |
| 56 | if __name__ == '__main__': |
Joe Gregorio | 79daca0 | 2013-03-29 16:25:52 -0400 | [diff] [blame] | 57 | FLAGS = parser.parse_args(sys.argv[1:]) |
| 58 | main() |