def handle(self, *args, **options): output_dir = options.get('output_dir') collectstatic = options.get('collectstatic') quiet = options.get('quiet') force = options.get('force') if quiet: stdout = self._quiet else: stdout = self.stdout.write if not output_dir: output_dir = getattr(settings, 'DISTILL_DIR', None) if not output_dir: e = 'Usage: ./manage.py distill-local [directory]' raise CommandError(e) if collectstatic: run_collectstatic(stdout) if not os.path.isdir(settings.STATIC_ROOT): e = 'Static source directory does not exist, run collectstatic' raise CommandError(e) output_dir = os.path.abspath(os.path.expanduser(output_dir)) stdout('') stdout('You have requested to create a static version of') stdout('this site into the output path directory:') stdout('') stdout(' Source static path: {}'.format(settings.STATIC_ROOT)) stdout(' Distill output path: {}'.format(output_dir)) stdout('') if os.path.isdir(output_dir): stdout('Distill output directory exists, clean up?') stdout('This will delete and recreate all files in the output dir') stdout('') if force: ans = 'yes' else: ans = input('Type \'yes\' to continue, or \'no\' to cancel: ') if ans.lower() == 'yes': stdout('Recreating output directory...') rmtree(output_dir) os.makedirs(output_dir) else: raise CommandError('Distilling site cancelled.') else: ans = input('Does not exist, create it? (YES/no): ') if ans.lower() == 'yes': stdout('Creating directory...') os.makedirs(output_dir) else: raise CommandError('Aborting...') stdout('') stdout('Generating static site into directory: {}'.format(output_dir)) try: render_to_dir(output_dir, urls_to_distill, stdout) except DistillError as err: raise raise_with_traceback(CommandError(str(err))) stdout('') stdout('Site generation complete.')
def handle(self, *args, **options): publish_target_name = options.get('publish_target_name') if not publish_target_name: publish_target_name = 'default' publish_targets = getattr(settings, 'DISTILL_PUBLISH', {}) publish_target = publish_targets.get(publish_target_name) if type(publish_target) != dict: e = 'Invalid publish target name: "{}"'.format(publish_target_name) e += ', check your settings.DISTILL_PUBLISH values' raise CommandError(e) publish_engine = publish_target.get('ENGINE') if not publish_engine: e = 'Publish target {} has no ENGINE'.format(publish_target_name) raise CommandError(e) collectstatic = options.get('collectstatic') quiet = options.get('quiet') force = options.get('force') if quiet: stdout = self._quiet else: stdout = self.stdout.write static_dir = settings.STATIC_ROOT static_url = settings.STATIC_URL try: output_dir = mkdtemp() if not output_dir.endswith(os.sep): output_dir += os.sep backend_class = get_backend(publish_engine) backend = backend_class(output_dir, publish_target) username = backend.account_username() container = backend.account_container() stdout('') stdout('You have requested to distill and publish this site') stdout('to the following target:') stdout('') stdout(' Settings name: {}'.format(publish_target_name)) stdout(' Engine: {}'.format(publish_engine)) stdout(' Username: {}'.format(username)) stdout(' Container: {}'.format(container)) stdout('') if collectstatic: run_collectstatic(stdout) if not os.path.isdir(settings.STATIC_ROOT): e = 'Static source directory does not exist, run collectstatic' raise CommandError(e) ans = input('Type \'yes\' to continue, or \'no\' to cancel: ') if ans.lower() == 'yes': pass else: raise CommandError('Publishing site cancelled.') self.stdout.write('') static_output_dir = os.path.join(output_dir, static_url[1:]) msg = 'Generating static site into directory: {}' stdout(msg.format(output_dir)) try: render_to_dir(output_dir, urls_to_distill, stdout) except DistillError as err: raise raise_with_traceback(CommandError(str(err))) stdout('') stdout('Publishing site') backend.index_local_files() publish_dir(output_dir, backend, stdout) finally: if os.path.exists(output_dir): stdout('Deleting temporary directory.') rmtree(output_dir) stdout('') stdout('Site generation and publishing complete.')