def __call__(self, parser, namespace, values, option_string): init_logging(name=__name__) try: instance, settings = get_instance(namespace) except Exception as e: logger.critical("%s: %s", e.__class__.__name__, e) console.print_exception() sys.exit(getattr(e, 'exitcode', 1)) if values: # One or more arguments provided, so only print those settings for setting in values: if setting in settings: # Only add newline between setting name and value if dict if isinstance(settings[setting], (dict, tuple, list)): setting_format = '\n{}:\n{}' else: setting_format = '\n{}: {}' console.print( setting_format.format( setting, pprint.pformat(settings[setting]))) else: console.print( '\n{} is not a recognized setting.'.format(setting)) break else: # No argument was given to --print-settings, so print all settings console.print(settings) parser.exit()
def list_plugins(ns_pkg=None): from pelican.log import init as init_logging init_logging(logging.INFO) ns_plugins = get_namespace_plugins(ns_pkg) if ns_plugins: logger.info('Plugins found:\n' + '\n'.join(ns_plugins)) else: logger.info('No plugins are installed')
def main(argv=None): args = parse_arguments(argv) logs_dedup_min_level = getattr(logging, args.logs_dedup_min_level) init_logging(level=args.verbosity, fatal=args.fatal, name=__name__, logs_dedup_min_level=logs_dedup_min_level) logger.debug('Pelican version: %s', __version__) logger.debug('Python version: %s', sys.version.split()[0]) try: pelican, settings = get_instance(args) if args.autoreload and args.listen: excqueue = multiprocessing.Queue() p1 = multiprocessing.Process(target=autoreload, args=(args, excqueue)) p2 = multiprocessing.Process(target=listen, args=(settings.get('BIND'), settings.get('PORT'), settings.get("OUTPUT_PATH"), excqueue)) p1.start() p2.start() exc = excqueue.get() p1.terminate() p2.terminate() if exc is not None: logger.critical(exc) elif args.autoreload: autoreload(args) elif args.listen: listen(settings.get('BIND'), settings.get('PORT'), settings.get("OUTPUT_PATH")) else: watcher = FileSystemWatcher(args.settings, Readers, settings) watcher.check() with console.status("Generating..."): pelican.run() except KeyboardInterrupt: logger.warning('Keyboard interrupt received. Exiting.') except Exception as e: logger.critical("%s: %s", e.__class__.__name__, e) if args.verbosity == logging.DEBUG: console.print_exception() sys.exit(getattr(e, 'exitcode', 1))
# If the default guess is too generic, try the python-magic library if mimetype == 'application/octet-stream' and magic_from_file: mimetype = magic_from_file(path, mime=True) return mimetype class RootedHTTPServer(BaseHTTPServer.HTTPServer): def __init__(self, base_path, *args, **kwargs): BaseHTTPServer.HTTPServer.__init__(self, *args, **kwargs) self.RequestHandlerClass.base_path = base_path if __name__ == '__main__': init_logging(level=logging.INFO) logger.warning("'python -m pelican.server' is deprecated.\nThe " "Pelican development server should be run via " "'pelican --listen' or 'pelican -l'.\nThis can be combined " "with regeneration as 'pelican -lr'.\nRerun 'pelican-" "quickstart' to get new Makefile and tasks.py files.") args = parse_arguments() RootedHTTPServer.allow_reuse_address = True try: httpd = RootedHTTPServer(args.path, (args.server, args.port), ComplexHTTPRequestHandler) if args.ssl: httpd.socket = ssl.wrap_socket(httpd.socket, keyfile=args.key, certfile=args.cert, server_side=True)
def main(): args = parse_arguments() logs_dedup_min_level = getattr(logging, args.logs_dedup_min_level) init_logging(args.verbosity, args.fatal, logs_dedup_min_level=logs_dedup_min_level) logger.debug('Pelican version: %s', __version__) logger.debug('Python version: %s', sys.version.split()[0]) try: pelican, settings = get_instance(args) readers = Readers(settings) reader_descs = sorted(set(['%s (%s)' % (type(r).__name__, ', '.join(r.file_extensions)) for r in readers.readers.values() if r.enabled])) watchers = {'content': folder_watcher(pelican.path, readers.extensions, pelican.ignore_files), 'theme': folder_watcher(pelican.theme, [''], pelican.ignore_files), 'settings': file_watcher(args.settings)} old_static = settings.get("STATIC_PATHS", []) for static_path in old_static: # use a prefix to avoid possible overriding of standard watchers # above watchers['[static]%s' % static_path] = folder_watcher( os.path.join(pelican.path, static_path), [''], pelican.ignore_files) if args.autoreload and args.listen: excqueue = multiprocessing.Queue() p1 = multiprocessing.Process( target=autoreload, args=(watchers, args, old_static, reader_descs, excqueue)) p2 = multiprocessing.Process( target=listen, args=(settings.get('BIND'), settings.get('PORT'), settings.get("OUTPUT_PATH"), excqueue)) p1.start() p2.start() exc = excqueue.get() p1.terminate() p2.terminate() logger.critical(exc) elif args.autoreload: print(' --- AutoReload Mode: Monitoring `content`, `theme` and' ' `settings` for changes. ---') autoreload(watchers, args, old_static, reader_descs) elif args.listen: listen(settings.get('BIND'), settings.get('PORT'), settings.get("OUTPUT_PATH")) else: if next(watchers['content']) is None: logger.warning( 'No valid files found in content for ' + 'the active readers:\n' + '\n'.join(reader_descs)) if next(watchers['theme']) is None: logger.warning('Empty theme folder. Using `basic` theme.') pelican.run() except Exception as e: logger.critical('%s', e) if args.verbosity == logging.DEBUG: raise else: sys.exit(getattr(e, 'exitcode', 1))
def main(): args = parse_arguments() logs_dedup_min_level = getattr(logging, args.logs_dedup_min_level) init_logging(args.verbosity, args.fatal, logs_dedup_min_level=logs_dedup_min_level) logger.debug('Pelican version: %s', __version__) logger.debug('Python version: %s', sys.version.split()[0]) try: pelican, settings = get_instance(args) readers = Readers(settings) watchers = { 'content': folder_watcher(pelican.path, readers.extensions, pelican.ignore_files), 'theme': folder_watcher(pelican.theme, [''], pelican.ignore_files), 'settings': file_watcher(args.settings) } old_static = settings.get("STATIC_PATHS", []) for static_path in old_static: # use a prefix to avoid possible overriding of standard watchers # above watchers['[static]%s' % static_path] = folder_watcher( os.path.join(pelican.path, static_path), [''], pelican.ignore_files) if args.autoreload: print(' --- AutoReload Mode: Monitoring `content`, `theme` and' ' `settings` for changes. ---') while True: try: # Check source dir for changed files ending with the given # extension in the settings. In the theme dir is no such # restriction; all files are recursively checked if they # have changed, no matter what extension the filenames # have. modified = {k: next(v) for k, v in watchers.items()} if modified['settings']: pelican, settings = get_instance(args) # Adjust static watchers if there are any changes new_static = settings.get("STATIC_PATHS", []) # Added static paths # Add new watchers and set them as modified new_watchers = set(new_static).difference(old_static) for static_path in new_watchers: static_key = '[static]%s' % static_path watchers[static_key] = folder_watcher( os.path.join(pelican.path, static_path), [''], pelican.ignore_files) modified[static_key] = next(watchers[static_key]) # Removed static paths # Remove watchers and modified values old_watchers = set(old_static).difference(new_static) for static_path in old_watchers: static_key = '[static]%s' % static_path watchers.pop(static_key) modified.pop(static_key) # Replace old_static with the new one old_static = new_static if any(modified.values()): print('\n-> Modified: {}. re-generating...'.format( ', '.join(k for k, v in modified.items() if v))) if modified['content'] is None: logger.warning('No valid files found in content.') if modified['theme'] is None: logger.warning('Empty theme folder. Using `basic` ' 'theme.') pelican.run() except KeyboardInterrupt: logger.warning("Keyboard interrupt, quitting.") break except Exception as e: if (args.verbosity == logging.DEBUG): raise logger.warning('Caught exception "%s". Reloading.', e) finally: time.sleep(.5) # sleep to avoid cpu load else: if next(watchers['content']) is None: logger.warning('No valid files found in content.') if next(watchers['theme']) is None: logger.warning('Empty theme folder. Using `basic` theme.') pelican.run() except Exception as e: logger.critical('%s', e) if args.verbosity == logging.DEBUG: raise else: sys.exit(getattr(e, 'exitcode', 1))
def main(): args = parse_arguments() logs_dedup_min_level = getattr(logging, args.logs_dedup_min_level) init_logging(args.verbosity, args.fatal, logs_dedup_min_level=logs_dedup_min_level) logger.debug('Pelican version: %s', __version__) logger.debug('Python version: %s', sys.version.split()[0]) try: pelican, settings = get_instance(args) readers = Readers(settings) watchers = {'content': folder_watcher(pelican.path, readers.extensions, pelican.ignore_files), 'theme': folder_watcher(pelican.theme, [''], pelican.ignore_files), 'settings': file_watcher(args.settings)} old_static = settings.get("STATIC_PATHS", []) for static_path in old_static: # use a prefix to avoid possible overriding of standard watchers # above watchers['[static]%s' % static_path] = folder_watcher( os.path.join(pelican.path, static_path), [''], pelican.ignore_files) if args.autoreload: print(' --- AutoReload Mode: Monitoring `content`, `theme` and' ' `settings` for changes. ---') while True: try: # Check source dir for changed files ending with the given # extension in the settings. In the theme dir is no such # restriction; all files are recursively checked if they # have changed, no matter what extension the filenames # have. modified = {k: next(v) for k, v in watchers.items()} if modified['settings']: pelican, settings = get_instance(args) # Adjust static watchers if there are any changes new_static = settings.get("STATIC_PATHS", []) # Added static paths # Add new watchers and set them as modified new_watchers = set(new_static).difference(old_static) for static_path in new_watchers: static_key = '[static]%s' % static_path watchers[static_key] = folder_watcher( os.path.join(pelican.path, static_path), [''], pelican.ignore_files) modified[static_key] = next(watchers[static_key]) # Removed static paths # Remove watchers and modified values old_watchers = set(old_static).difference(new_static) for static_path in old_watchers: static_key = '[static]%s' % static_path watchers.pop(static_key) modified.pop(static_key) # Replace old_static with the new one old_static = new_static if any(modified.values()): print('\n-> Modified: {}. re-generating...'.format( ', '.join(k for k, v in modified.items() if v))) if modified['content'] is None: logger.warning('No valid files found in content.') if modified['theme'] is None: logger.warning('Empty theme folder. Using `basic` ' 'theme.') pelican.run() except KeyboardInterrupt: logger.warning("Keyboard interrupt, quitting.") break except Exception as e: if (args.verbosity == logging.DEBUG): raise logger.warning( 'Caught exception "%s". Reloading.', e) finally: time.sleep(.5) # sleep to avoid cpu load else: if next(watchers['content']) is None: logger.warning('No valid files found in content.') if next(watchers['theme']) is None: logger.warning('Empty theme folder. Using `basic` theme.') pelican.run() except Exception as e: logger.critical('%s', e) if args.verbosity == logging.DEBUG: raise else: sys.exit(getattr(e, 'exitcode', 1))
# If the default guess is too generic, try the python-magic library if mimetype == 'application/octet-stream' and magic_from_file: mimetype = magic_from_file(path, mime=True) return mimetype class RootedHTTPServer(BaseHTTPServer.HTTPServer): def __init__(self, base_path, *args, **kwargs): BaseHTTPServer.HTTPServer.__init__(self, *args, **kwargs) self.RequestHandlerClass.base_path = base_path if __name__ == '__main__': init_logging(level=logging.INFO) logger.warning("'python -m pelican.server' is deprecated.\nThe " "Pelican development server should be run via " "'pelican --listen' or 'pelican -l'.\nThis can be combined " "with regeneration as 'pelican -lr'.\nRerun 'pelican-" "quickstart' to get new Makefile and tasks.py files.") args = parse_arguments() RootedHTTPServer.allow_reuse_address = True try: httpd = RootedHTTPServer( args.path, (args.server, args.port), ComplexHTTPRequestHandler) if args.ssl: httpd.socket = ssl.wrap_socket( httpd.socket, keyfile=args.key, certfile=args.cert, server_side=True) except ssl.SSLError as e: