comparison piecrust/importing/piecrust.py @ 540:233234e02816

import: Fix the PieCrust 1 importer. I was completely confused between CWD, app root dir, and given root dir. Made the code hopefully a bit more clear.
author Ludovic Chabant <ludovic@chabant.com>
date Fri, 31 Jul 2015 00:36:25 -0700
parents 2823ea40cfac
children 8a96ff3f2b01
comparison
equal deleted inserted replaced
539:9093618aea08 540:233234e02816
21 help="The root directory of the PieCrust 1 website.") 21 help="The root directory of the PieCrust 1 website.")
22 parser.add_argument('--upgrade', action='store_true', 22 parser.add_argument('--upgrade', action='store_true',
23 help="Upgrade the current website in place.") 23 help="Upgrade the current website in place.")
24 24
25 def importWebsite(self, app, args): 25 def importWebsite(self, app, args):
26 if app.root_dir and args.upgrade: 26 if args.root_dir and args.upgrade:
27 raise Exception("Can't specifiy both a root directory and `--upgrade`.") 27 raise Exception("Can't specifiy both a root directory and `--upgrade`.")
28 if app.root_dir is None and not args.upgrade: 28 if args.root_dir is None and not args.upgrade:
29 raise Exception("Need to specify either a root directory or `--upgrade`.") 29 raise Exception("Need to specify either a root directory or `--upgrade`.")
30 30
31 root_dir = os.getcwd() if args.upgrade else app.root_dir 31 if app.root_dir is None and not args.upgrade:
32 logger.debug("Importing PieCrust 1 site from: %s" % root_dir) 32 raise Exception("Need to run the import from inside a PieCrust 2 "
33 "website. Use `--upgrade` to upgrade from inside "
34 "a PieCrust 1 website.")
35 if app.root_dir is not None and args.upgrade:
36 raise Exception("Already in a PieCrust 2 website. Specify the "
37 "PieCrust 1 website to import from.")
38
39 src_root_dir = os.getcwd() if args.upgrade else args.root_dir
40 out_root_dir = src_root_dir if args.upgrade else app.root_dir
41 logger.debug("Importing PieCrust 1 site from: %s" % src_root_dir)
33 exclude = args.exclude or [] 42 exclude = args.exclude or []
34 exclude += ['_cache', '_counter'] 43 exclude += ['_cache', '_counter']
35 self._startWalk(root_dir, exclude, root_dir, args.upgrade) 44 self._startWalk(src_root_dir, exclude, out_root_dir, args.upgrade)
36 if args.upgrade: 45 if args.upgrade:
37 self._cleanEmptyDirectories(root_dir) 46 self._cleanEmptyDirectories(src_root_dir)
38 logger.info("The PieCrust website was successfully imported.") 47 logger.info("The PieCrust website was successfully imported.")
39 48
40 def _importFile(self, full_fn, rel_fn, out_root_dir, is_move): 49 def _importFile(self, full_fn, rel_fn, out_root_dir, is_move):
41 logger.debug("- %s" % rel_fn) 50 logger.debug("- %s" % rel_fn)
42 dest_path = rel_fn 51 dest_path = rel_fn