import.py 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #!/usr/bin/env python
  2. # This Source Code Form is subject to the terms of the Mozilla Public
  3. # License, v. 2.0. If a copy of the MPL was not distributed with this
  4. # file, You can obtain one at http://mozilla.org/MPL/2.0/.
  5. #
  6. # Execute as: /import.py <source-distribution> <target-dir>
  7. # <target-dir> must have 'IMPORT_FILES' in it
  8. import sys
  9. import re
  10. import os
  11. import shutil
  12. def die(msg):
  13. sys.stderr.write('ERROR:' + msg + '\n')
  14. sys.exit(1)
  15. DISTRO = sys.argv[1]
  16. IMPORT_DIR = sys.argv[2]
  17. FILES = []
  18. f = open("%s/IMPORT_FILES" % IMPORT_DIR)
  19. for l in f:
  20. l = l.strip()
  21. l = l.strip("'")
  22. if l.startswith("#"):
  23. continue
  24. if not l:
  25. continue
  26. FILES.append(l)
  27. for f in FILES:
  28. print f
  29. SOURCE_PATH = "%s/%s"%(DISTRO,f)
  30. DEST_PATH = "%s/%s"%(IMPORT_DIR,f)
  31. if not os.path.exists(SOURCE_PATH):
  32. die("%s does not exist"%SOURCE_PATH)
  33. if not os.path.exists(os.path.dirname(DEST_PATH)):
  34. os.makedirs(os.path.dirname(DEST_PATH))
  35. shutil.copyfile(SOURCE_PATH, DEST_PATH)