def watch(ctx, verbose=False): '''Serve the blog and watch changes''' os.chdir(ROOT) from livereload import Server settings = get_settings() log.init(logging.DEBUG if verbose else logging.INFO) logging.getLogger('livereload').propagate = False logging.getLogger('tornado').propagate = False compile() server = Server() server.watch(CONF_FILE, compile) server.watch('theme', compile) DATA_PATHS = getattr(settings, 'DATA_PATHS', []) for root in set(DATA_PATHS): for data in getattr(settings, 'DATA', []): path = os.path.join(root, data) if os.path.exists(path): server.watch(path, compile) paths = settings.ARTICLE_PATHS + settings.PAGE_PATHS + settings.STATIC_PATHS for path in paths: server.watch(path, compile) server.serve(port=PORT, root=settings.OUTPUT_PATH)
def main(): args = parse_arguments() init(args.verbosity) try: generator = Generator(args) generator.generate() if args.serve: serve = server.ServeThread( generator.settings.get('OUTPUT_PATH', '.'), 'localhost', args.port) serve.daemon = True serve.start() if args.autoreload: generator.daemon = True generator.start() generator.join() elif args.serve: serve.join() except KeyboardInterrupt: logger.info("Keyboard interrupt, quitting.") except Exception as e: logger.critical('%s', e) if args.verbosity == logging.DEBUG: raise else: sys.exit(getattr(e, 'exitcode', 1))
def main(): argument_parser = create_argument_parser() args = argument_parser.parse_args() if not os.path.exists(args.output): try: os.mkdir(args.output) except OSError: error = "Unable to create the output folder: " + args.output exit(error) parser = blog2pelican.parsers.make_parser(args.engine, args) fields = parser.parse() if "wp_attach" in args and args.wp_attach: attachments = get_attachments(args.input) else: attachments = None # init logging init() fields2pelican( fields, args.markup, args.output, dircat=args.dircat or False, dirpage="dirpage" in args and args.dirpage or False, strip_raw="strip_raw" in args and args.strip_raw or False, disable_slugs="disable_slugs" in args and args.disable_slugs or False, filter_author=args.author, wp_custpost="wp_custpost" in args and args.wp_custpost or False, wp_attach="wp_attach" in args and args.wp_attach or False, attachments=attachments or None, )
def migrate_blog_to_pelican( self, repository, output_dir, output_markup, **kwargs, ): self._create_output_dir(output_dir) wp_attach = kwargs.get("wp_attach", False) attachments = get_attachments(kwargs.get("input")) if wp_attach else {} # init logging init() for content in iter(repository): fields2pelican( content, output_dir, output_markup, dircat=kwargs.get("dircat", False), dirpage=kwargs.get("dirpage", False), strip_raw=kwargs.get("strip_raw", False), disable_slugs=kwargs.get("disable_slugs", False), filter_author=kwargs.get("author"), wp_custpost=kwargs.get("wp_custpost", False), wp_attach=wp_attach, attachments=attachments, ) urls = attachments.get(None) if wp_attach and urls: print("downloading attachments that don't have a parent post") download_attachments(output_dir, urls)
def watch(ctx, verbose=False): '''Serve the blog and watch changes''' from livereload import Server settings = get_settings() log.init(logging.DEBUG if verbose else logging.INFO) logging.getLogger('livereload').propagate = False logging.getLogger('tornado').propagate = False compile() server = Server() server.watch(CONF_FILE, compile) server.watch('theme/static', compile) server.watch('theme/templates', compile) server.watch('theme/translations', compile) server.watch('data', compile) server.watch('plugins', reload_and_compile) paths = settings.ARTICLE_PATHS + settings.PAGE_PATHS for path in paths: server.watch(path, compile) server.serve(port=PORT, root=settings.OUTPUT_PATH)
def main(): args = parse_arguments() init(args.verbosity) pelican = get_instance(args) try: if args.autoreload: files_found_error = True 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. if (files_changed( pelican.path, pelican.markup, pelican.ignore_files) or files_changed( pelican.theme, [''], pelican.ignore_files )): if not files_found_error: files_found_error = True pelican.run() # reload also if settings.py changed if file_changed(args.settings): logger.info('%s changed, re-generating' % args.settings) pelican = get_instance(args) pelican.run() time.sleep(.5) # sleep to avoid cpu load except KeyboardInterrupt: logger.warning("Keyboard interrupt, quitting.") break except NoFilesError: if files_found_error: logger.warning("No valid files found in content. " "Nothing to generate.") files_found_error = False time.sleep(1) # sleep to avoid cpu load except Exception as e: logger.warning( 'Caught exception "{0}". Reloading.'.format(e)) continue else: pelican.run() except Exception as e: logger.critical(e) if (args.verbosity == logging.DEBUG): raise else: sys.exit(getattr(e, 'exitcode', 1))
def main(*margs, **kwargs): oldargs = None if margs or kwargs: # Backing up current arguments oldargs = sys.argv sys.argv = sys.argv[:1] args = parse_arguments(*margs, **kwargs) if margs or kwargs: # Restoring current arguments sys.argv = oldargs init(args.verbosity) pelican = get_instance(args) try: if args.autoreload: files_found_error = True 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. if files_changed(pelican.path, pelican.markup) or \ files_changed(pelican.theme, ['']): if not files_found_error: files_found_error = True pelican.run() # reload also if settings.py changed if file_changed(args.settings): logger.info('%s changed, re-generating' % args.settings) pelican = get_instance(args) pelican.run() time.sleep(.5) # sleep to avoid cpu load except KeyboardInterrupt: logger.warning("Keyboard interrupt, quitting.") break except NoFilesError: if files_found_error: logger.warning("No valid files found in content. " "Nothing to generate.") files_found_error = False time.sleep(1) # sleep to avoid cpu load except Exception, e: logger.warning( "Caught exception \"{}\". Reloading.".format(e) ) traceback.print_exc() continue else:
def main(): args = parse_arguments() init(args.verbosity) pelican = get_instance(args) try: if args.autoreload: files_found_error = True 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. if (files_changed(pelican.path, pelican.markup, pelican.ignore_files) or files_changed(pelican.theme, [''], pelican.ignore_files)): if not files_found_error: files_found_error = True pelican.run() # reload also if settings.py changed if file_changed(args.settings): logger.info('%s changed, re-generating' % args.settings) pelican = get_instance(args) pelican.run() time.sleep(.5) # sleep to avoid cpu load except KeyboardInterrupt: logger.warning("Keyboard interrupt, quitting.") break except NoFilesError: if files_found_error: logger.warning("No valid files found in content. " "Nothing to generate.") files_found_error = False time.sleep(1) # sleep to avoid cpu load except Exception as e: if (args.verbosity == logging.DEBUG): logger.critical(e.args) raise logger.warning( 'Caught exception "{0}". Reloading.'.format(e)) continue else: pelican.run() except Exception as e: logger.critical(e) if (args.verbosity == logging.DEBUG): raise else: sys.exit(getattr(e, 'exitcode', 1))
def main(): args = parse_arguments() init(args.verbosity) # Split the markup languages only if some have been given. Otherwise, # populate the variable with None. pelican = get_instance(args) try: if args.autoreload: files_found_error = True 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. if files_changed(pelican.path, pelican.markup) or \ files_changed(pelican.theme, ['']): if files_found_error == False: files_found_error = True pelican.run() # reload also if settings.py changed if file_changed(args.settings): logger.info('%s changed, re-generating' % args.settings) pelican = get_instance(args) pelican.run() time.sleep(.5) # sleep to avoid cpu load except KeyboardInterrupt: logger.warning("Keyboard interrupt, quitting.") break except NoFilesError: if files_found_error == True: logger.warning( "No valid files found in content. Nothing to generate." ) files_found_error = False time.sleep(1) # sleep to avoid cpu load except Exception, e: logger.warning( "Caught exception \"{}\". Reloading.".format(e)) continue else:
def main(): args = parse_arguments() init(args.verbosity) # Split the markup languages only if some have been given. Otherwise, # populate the variable with None. pelican = get_instance(args) try: if args.autoreload: files_found_error = True 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. if files_changed(pelican.path, pelican.markup) or \ files_changed(pelican.theme, ['']): if files_found_error == False: files_found_error = True pelican.run() # reload also if settings.py changed if file_changed(args.settings): logger.info('%s changed, re-generating' % args.settings) pelican = get_instance(args) pelican.run() time.sleep(.5) # sleep to avoid cpu load except KeyboardInterrupt: logger.warning("Keyboard interrupt, quitting.") break except NoFilesError: if files_found_error == True: logger.warning("No valid files found in content. Nothing to generate.") files_found_error = False time.sleep(1) # sleep to avoid cpu load except Exception, e: logger.warning( "Caught exception \"{}\". Reloading.".format(e) ) continue else:
def main(): args = parse_arguments() init(args.verbosity) # Split the markup languages only if some have been given. Otherwise, # populate the variable with None. markup = [a.strip().lower() for a in args.markup.split(',')]\ if args.markup else None settings = read_settings(args.settings) cls = settings.get('PELICAN_CLASS') if isinstance(cls, basestring): module, cls_name = cls.rsplit('.', 1) module = __import__(module) cls = getattr(module, cls_name) try: pelican = cls(settings, args.path, args.theme, args.output, markup, args.delete_outputdir) if args.autoreload: 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. if files_changed(pelican.path, pelican.markup) or \ files_changed(pelican.theme, ['']): pelican.run() time.sleep(.5) # sleep to avoid cpu load except KeyboardInterrupt: break else: pelican.run() except Exception, e: logger.critical(unicode(e)) if (args.verbosity == logging.DEBUG): raise else: sys.exit(getattr(e, 'exitcode', 1))
def main(): args = parse_arguments() init(args.verbosity) # Split the markup languages only if some have been given. Otherwise, # populate the variable with None. pelican = get_instance(args) try: if args.autoreload: 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. if files_changed(pelican.path, pelican.markup) or \ files_changed(pelican.theme, ['']): pelican.run() # reload also if settings.py changed if file_changed(args.settings): logger.info('%s changed, re-generating' % args.settings) pelican = get_instance(args) pelican.run() time.sleep(.5) # sleep to avoid cpu load except KeyboardInterrupt: break else: pelican.run() except Exception, e: logger.critical(unicode(e)) if (args.verbosity == logging.DEBUG): raise else: sys.exit(getattr(e, 'exitcode', 1))
def main(): args = parse_arguments() init(args.verbosity) 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)} for static_path in settings.get("STATIC_PATHS", []): watchers[static_path] = folder_watcher(static_path, [''], pelican.ignore_files) try: if args.autoreload: print(' --- AutoReload Mode: Monitoring `content`, `theme` and' ' `settings` for changes. ---') def _ignore_cache(pelican_obj): if pelican_obj.settings['AUTORELOAD_IGNORE_CACHE']: pelican_obj.settings['LOAD_CONTENT_CACHE'] = False 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()} original_load_cache = settings['LOAD_CONTENT_CACHE'] if modified['settings']: pelican, settings = get_instance(args) original_load_cache = settings['LOAD_CONTENT_CACHE'] _ignore_cache(pelican) 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() # restore original caching policy pelican.settings['LOAD_CONTENT_CACHE'] = original_load_cache except KeyboardInterrupt: logger.warning("Keyboard interrupt, quitting.") break except Exception as e: if (args.verbosity == logging.DEBUG): logger.critical(e.args) 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(): parser = argparse.ArgumentParser( description="Transform feed, Wordpress or Dotclear files to reST (rst) " "or Markdown (md) files. Be sure to have pandoc installed.", formatter_class=argparse.ArgumentDefaultsHelpFormatter) parser.add_argument(dest='input', help='The input file to read') parser.add_argument('--wpfile', action='store_true', dest='wpfile', help='Wordpress XML export') parser.add_argument('--dotclear', action='store_true', dest='dotclear', help='Dotclear export') parser.add_argument('--posterous', action='store_true', dest='posterous', help='Posterous export') parser.add_argument('--feed', action='store_true', dest='feed', help='Feed to parse') parser.add_argument('-o', '--output', dest='output', default='output', help='Output path') parser.add_argument('-m', '--markup', dest='markup', default='rst', help='Output markup format (supports rst & markdown)') parser.add_argument('--dir-cat', action='store_true', dest='dircat', help='Put files in directories with categories name') parser.add_argument('--dir-page', action='store_true', dest='dirpage', help=('Put files recognised as pages in "pages/" sub-directory' ' (wordpress import only)')) parser.add_argument('--strip-raw', action='store_true', dest='strip_raw', help="Strip raw HTML code that can't be converted to " "markup such as flash embeds or iframes (wordpress import only)") parser.add_argument('--disable-slugs', action='store_true', dest='disable_slugs', help='Disable storing slugs from imported posts within output. ' 'With this disabled, your Pelican URLs may not be consistent ' 'with your original posts.') parser.add_argument('-e', '--email', dest='email', help="Email address (posterous import only)") parser.add_argument('-p', '--password', dest='password', help="Password (posterous import only)") args = parser.parse_args() input_type = None if args.wpfile: input_type = 'wordpress' elif args.dotclear: input_type = 'dotclear' elif args.posterous: input_type = 'posterous' elif args.feed: input_type = 'feed' else: error = "You must provide either --wpfile, --dotclear, --posterous or --feed options" exit(error) if not os.path.exists(args.output): try: os.mkdir(args.output) except OSError: error = "Unable to create the output folder: " + args.output exit(error) if input_type == 'wordpress': fields = wp2fields(args.input) elif input_type == 'dotclear': fields = dc2fields(args.input) elif input_type == 'posterous': fields = posterous2fields(args.input, args.email, args.password) elif input_type == 'feed': fields = feed2fields(args.input) init() # init logging fields2pelican(fields, args.markup, args.output, dircat=args.dircat or False, dirpage=args.dirpage or False, strip_raw=args.strip_raw or False, disable_slugs=args.disable_slugs or False)
def main(): parser = argparse.ArgumentParser(description="""A tool to generate a static blog, with restructured text input files.""") parser.add_argument(dest='path', nargs='?', help='Path where to find the content files') parser.add_argument('-t', '--theme-path', dest='theme', help='Path where to find the theme templates. If not specified, it' 'will use the default one included with pelican.') parser.add_argument('-o', '--output', dest='output', help='Where to output the generated files. If not specified, a directory' ' will be created, named "output" in the current path.') parser.add_argument('-m', '--markup', default=None, dest='markup', help='the list of markup language to use (rst or md). Please indicate ' 'them separated by commas') parser.add_argument('-s', '--settings', dest='settings', help='the settings of the application. Default to None.') parser.add_argument('-k', '--keep-output-directory', dest='keep', action='store_true', help='Keep the output directory and just update all the generated files.' 'Default is to delete the output directory.') parser.add_argument('-v', '--verbose', action='store_const', const=log.INFO, dest='verbosity', help='Show all messages') parser.add_argument('-q', '--quiet', action='store_const', const=log.CRITICAL, dest='verbosity', help='Show only critical errors') parser.add_argument('-D', '--debug', action='store_const', const=log.DEBUG, dest='verbosity', help='Show all message, including debug messages') parser.add_argument('--version', action='version', version=VERSION, help='Print the pelican version and exit') parser.add_argument('-r', '--autoreload', dest='autoreload', action='store_true', help="Relaunch pelican each time a modification occurs on the content" "files") args = parser.parse_args() log.init(args.verbosity) # Split the markup languages only if some have been given. Otherwise, populate # the variable with None. markup = [a.strip().lower() for a in args.markup.split(',')] if args.markup else None if args.settings is None: settings = {} settings = read_settings(args.settings) cls = settings.get('PELICAN_CLASS') if isinstance(cls, basestring): module, cls_name = cls.rsplit('.', 1) module = __import__(module) cls = getattr(module, cls_name) try: pelican = cls(settings, args.path, args.theme, args.output, markup, args.keep) if args.autoreload: while True: try: if files_changed(pelican.path, pelican.markup): pelican.run() except KeyboardInterrupt: break else: pelican.run() except Exception, e: log.critical(str(e))
def main(): args = parse_arguments() init(args.verbosity) 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) try: 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(): parser = argparse.ArgumentParser(description="""A tool to generate a static blog, with restructured text input files.""") parser.add_argument(dest='path', nargs='?', help='Path where to find the content files') parser.add_argument( '-t', '--theme-path', dest='theme', help='Path where to find the theme templates. If not specified, it' 'will use the default one included with pelican.') parser.add_argument( '-o', '--output', dest='output', help='Where to output the generated files. If not specified, a directory' ' will be created, named "output" in the current path.') parser.add_argument( '-m', '--markup', default=None, dest='markup', help='the list of markup language to use (rst or md). Please indicate ' 'them separated by commas') parser.add_argument( '-s', '--settings', dest='settings', default='', help='the settings of the application. Default to False.') parser.add_argument('-d', '--delete-output-directory', dest='delete_outputdir', action='store_true', help='Delete the output directory.') parser.add_argument('-v', '--verbose', action='store_const', const=log.INFO, dest='verbosity', help='Show all messages') parser.add_argument('-q', '--quiet', action='store_const', const=log.CRITICAL, dest='verbosity', help='Show only critical errors') parser.add_argument('-D', '--debug', action='store_const', const=log.DEBUG, dest='verbosity', help='Show all message, including debug messages') parser.add_argument('--version', action='version', version=__version__, help='Print the pelican version and exit') parser.add_argument( '-r', '--autoreload', dest='autoreload', action='store_true', help="Relaunch pelican each time a modification occurs on the content" "files") args = parser.parse_args() log.init(args.verbosity) # Split the markup languages only if some have been given. Otherwise, populate # the variable with None. markup = [a.strip().lower() for a in args.markup.split(',')] if args.markup else None settings = read_settings(args.settings) cls = settings.get('PELICAN_CLASS') if isinstance(cls, basestring): module, cls_name = cls.rsplit('.', 1) module = __import__(module) cls = getattr(module, cls_name) try: pelican = cls(settings, args.path, args.theme, args.output, markup, args.delete_outputdir) if args.autoreload: 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. if files_changed(pelican.path, pelican.markup) or \ files_changed(pelican.theme, ['']): pelican.run() time.sleep(.5) # sleep to avoid cpu load except KeyboardInterrupt: break else: pelican.run() except Exception, e: log.critical(unicode(e)) if (args.verbosity == log.DEBUG): raise else: sys.exit(getattr(e, 'exitcode', 1))
def main(): parser = argparse.ArgumentParser(description="""A tool to generate a static blog, with restructured text input files.""") parser.add_argument(dest='path', nargs='?', help='Path where to find the content files') parser.add_argument( '-t', '--theme-path', dest='theme', help='Path where to find the theme templates. If not specified, it' 'will use the default one included with pelican.') parser.add_argument( '-o', '--output', dest='output', help='Where to output the generated files. If not specified, a directory' ' will be created, named "output" in the current path.') parser.add_argument( '-m', '--markup', default=None, dest='markup', help='the list of markup language to use (rst or md). Please indicate ' 'them separated by commas') parser.add_argument( '-s', '--settings', dest='settings', help='the settings of the application. Default to None.') parser.add_argument( '-k', '--keep-output-directory', dest='keep', action='store_true', help='Keep the output directory and just update all the generated files.' 'Default is to delete the output directory.') parser.add_argument('-v', '--verbose', action='store_const', const=log.INFO, dest='verbosity', help='Show all messages') parser.add_argument('-q', '--quiet', action='store_const', const=log.CRITICAL, dest='verbosity', help='Show only critical errors') parser.add_argument('-D', '--debug', action='store_const', const=log.DEBUG, dest='verbosity', help='Show all message, including debug messages') parser.add_argument('--version', action='version', version=VERSION, help='Print the pelican version and exit') parser.add_argument( '-r', '--autoreload', dest='autoreload', action='store_true', help="Relaunch pelican each time a modification occurs on the content" "files") args = parser.parse_args() log.init(args.verbosity) # Split the markup languages only if some have been given. Otherwise, populate # the variable with None. markup = [a.strip().lower() for a in args.markup.split(',')] if args.markup else None if args.settings is None: settings = {} settings = read_settings(args.settings) cls = settings.get('PELICAN_CLASS') if isinstance(cls, basestring): module, cls_name = cls.rsplit('.', 1) module = __import__(module) cls = getattr(module, cls_name) try: pelican = cls(settings, args.path, args.theme, args.output, markup, args.keep) if args.autoreload: while True: try: if files_changed(pelican.path, pelican.markup): pelican.run() except KeyboardInterrupt: break else: pelican.run() except Exception, e: log.critical(str(e))
def main(): parser = argparse.ArgumentParser(description="""A tool to generate a static blog, with restructured text input files.""") parser.add_argument(dest='path', nargs='?', help='Path where to find the content files') parser.add_argument('-t', '--theme-path', dest='theme', help='Path where to find the theme templates. If not specified, it' 'will use the default one included with pelican.') parser.add_argument('-o', '--output', dest='output', help='Where to output the generated files. If not specified, a directory' ' will be created, named "output" in the current path.') parser.add_argument('-m', '--markup', default=None, dest='markup', help='the list of markup language to use (rst or md). Please indicate ' 'them separated by commas') parser.add_argument('-s', '--settings', dest='settings', default='', help='the settings of the application. Default to False.') parser.add_argument('-d', '--delete-output-directory', dest='delete_outputdir', action='store_true', help='Delete the output directory.') parser.add_argument('-v', '--verbose', action='store_const', const=log.INFO, dest='verbosity', help='Show all messages') parser.add_argument('-q', '--quiet', action='store_const', const=log.CRITICAL, dest='verbosity', help='Show only critical errors') parser.add_argument('-D', '--debug', action='store_const', const=log.DEBUG, dest='verbosity', help='Show all message, including debug messages') parser.add_argument('--version', action='version', version=__version__, help='Print the pelican version and exit') parser.add_argument('-r', '--autoreload', dest='autoreload', action='store_true', help="Relaunch pelican each time a modification occurs on the content" "files") args = parser.parse_args() log.init(args.verbosity) # Split the markup languages only if some have been given. Otherwise, populate # the variable with None. markup = [a.strip().lower() for a in args.markup.split(',')] if args.markup else None settings = read_settings(args.settings) cls = settings.get('PELICAN_CLASS') if isinstance(cls, basestring): module, cls_name = cls.rsplit('.', 1) module = __import__(module) cls = getattr(module, cls_name) try: pelican = cls(settings, args.path, args.theme, args.output, markup, args.delete_outputdir) if args.autoreload: 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. if files_changed(pelican.path, pelican.markup) or \ files_changed(pelican.theme, ['']): pelican.run() time.sleep(.5) # sleep to avoid cpu load except KeyboardInterrupt: break else: pelican.run() except Exception, e: log.critical(unicode(e)) if (args.verbosity == log.DEBUG): raise else: sys.exit(getattr(e, 'exitcode', 1))
def main(): parser = argparse.ArgumentParser( description="Transform feed, Blogger, Dotclear, Posterous, Tumblr, or" "WordPress files into reST (rst) or Markdown (md) files. " "Be sure to have pandoc installed.", formatter_class=argparse.ArgumentDefaultsHelpFormatter) parser.add_argument(dest='input', help='The input file to read') parser.add_argument('--blogger', action='store_true', dest='blogger', help='Blogger XML export') parser.add_argument('--dotclear', action='store_true', dest='dotclear', help='Dotclear export') parser.add_argument('--posterous', action='store_true', dest='posterous', help='Posterous export') parser.add_argument('--tumblr', action='store_true', dest='tumblr', help='Tumblr export') parser.add_argument('--wpfile', action='store_true', dest='wpfile', help='Wordpress XML export') parser.add_argument('--feed', action='store_true', dest='feed', help='Feed to parse') parser.add_argument('-o', '--output', dest='output', default='content', help='Output path') parser.add_argument('-m', '--markup', dest='markup', default='rst', help='Output markup format (supports rst & markdown)') parser.add_argument('--dir-cat', action='store_true', dest='dircat', help='Put files in directories with categories name') parser.add_argument( '--dir-page', action='store_true', dest='dirpage', help=('Put files recognised as pages in "pages/" sub-directory' ' (blogger and wordpress import only)')) parser.add_argument('--filter-author', dest='author', help='Import only post from the specified author') parser.add_argument( '--strip-raw', action='store_true', dest='strip_raw', help="Strip raw HTML code that can't be converted to " "markup such as flash embeds or iframes (wordpress import only)") parser.add_argument( '--wp-custpost', action='store_true', dest='wp_custpost', help='Put wordpress custom post types in directories. If used with ' '--dir-cat option directories will be created as ' '/post_type/category/ (wordpress import only)') parser.add_argument( '--wp-attach', action='store_true', dest='wp_attach', help='(wordpress import only) Download files uploaded to wordpress as ' 'attachments. Files will be added to posts as a list in the post ' 'header. All files will be downloaded, even if ' "they aren't associated with a post. Files will be downloaded " 'with their original path inside the output directory. ' 'e.g. output/wp-uploads/date/postname/file.jpg ' '-- Requires an internet connection --') parser.add_argument( '--disable-slugs', action='store_true', dest='disable_slugs', help='Disable storing slugs from imported posts within output. ' 'With this disabled, your Pelican URLs may not be consistent ' 'with your original posts.') parser.add_argument('-e', '--email', dest='email', help="Email address (posterous import only)") parser.add_argument('-p', '--password', dest='password', help="Password (posterous import only)") parser.add_argument('-b', '--blogname', dest='blogname', help="Blog name (Tumblr import only)") args = parser.parse_args() input_type = None if args.blogger: input_type = 'blogger' elif args.dotclear: input_type = 'dotclear' elif args.posterous: input_type = 'posterous' elif args.tumblr: input_type = 'tumblr' elif args.wpfile: input_type = 'wordpress' elif args.feed: input_type = 'feed' else: error = ('You must provide either --blogger, --dotclear, ' '--posterous, --tumblr, --wpfile or --feed options') exit(error) if not os.path.exists(args.output): try: os.mkdir(args.output) except OSError: error = 'Unable to create the output folder: ' + args.output exit(error) if args.wp_attach and input_type != 'wordpress': error = ('You must be importing a wordpress xml ' 'to use the --wp-attach option') exit(error) if input_type == 'blogger': fields = blogger2fields(args.input) elif input_type == 'dotclear': fields = dc2fields(args.input) elif input_type == 'posterous': fields = posterous2fields(args.input, args.email, args.password) elif input_type == 'tumblr': fields = tumblr2fields(args.input, args.blogname) elif input_type == 'wordpress': fields = wp2fields(args.input, args.wp_custpost or False) elif input_type == 'feed': fields = feed2fields(args.input) if args.wp_attach: attachments = get_attachments(args.input) else: attachments = None # init logging init() fields2pelican(fields, args.markup, args.output, dircat=args.dircat or False, dirpage=args.dirpage or False, strip_raw=args.strip_raw or False, disable_slugs=args.disable_slugs or False, filter_author=args.author, wp_custpost=args.wp_custpost or False, wp_attach=args.wp_attach or False, attachments=attachments or None)
def main(): parser = argparse.ArgumentParser( description="Transform feed, Wordpress or Dotclear files to reST (rst) " "or Markdown (md) files. Be sure to have pandoc installed.", formatter_class=argparse.ArgumentDefaultsHelpFormatter) parser.add_argument(dest='input', help='The input file to read') parser.add_argument('--wpfile', action='store_true', dest='wpfile', help='Wordpress XML export') parser.add_argument('--dotclear', action='store_true', dest='dotclear', help='Dotclear export') parser.add_argument('--posterous', action='store_true', dest='posterous', help='Posterous export') parser.add_argument('--feed', action='store_true', dest='feed', help='Feed to parse') parser.add_argument('-o', '--output', dest='output', default='output', help='Output path') parser.add_argument('-m', '--markup', dest='markup', default='rst', help='Output markup format (supports rst & markdown)') parser.add_argument('--dir-cat', action='store_true', dest='dircat', help='Put files in directories with categories name') parser.add_argument( '--strip-raw', action='store_true', dest='strip_raw', help="Strip raw HTML code that can't be converted to " "markup such as flash embeds or iframes (wordpress import only)") parser.add_argument( '--disable-slugs', action='store_true', dest='disable_slugs', help='Disable storing slugs from imported posts within output. ' 'With this disabled, your Pelican URLs may not be consistent ' 'with your original posts.') parser.add_argument('-e', '--email', dest='email', help="Email address (posterous import only)") parser.add_argument('-p', '--password', dest='password', help="Password (posterous import only)") args = parser.parse_args() input_type = None if args.wpfile: input_type = 'wordpress' elif args.dotclear: input_type = 'dotclear' elif args.posterous: input_type = 'posterous' elif args.feed: input_type = 'feed' else: error = "You must provide either --wpfile, --dotclear, --posterous or --feed options" exit(error) if not os.path.exists(args.output): try: os.mkdir(args.output) except OSError: error = "Unable to create the output folder: " + args.output exit(error) if input_type == 'wordpress': fields = wp2fields(args.input) elif input_type == 'dotclear': fields = dc2fields(args.input) elif input_type == 'posterous': fields = posterous2fields(args.input, args.email, args.password) elif input_type == 'feed': fields = feed2fields(args.input) init() # init logging fields2pelican(fields, args.markup, args.output, dircat=args.dircat or False, strip_raw=args.strip_raw or False, disable_slugs=args.disable_slugs or False)
def main(): args = parse_arguments() init(args.verbosity) 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)} for static_path in settings.get("STATIC_PATHS", []): watchers[static_path] = folder_watcher(static_path, [''], pelican.ignore_files) try: if args.autoreload: print(' --- AutoReload Mode: Monitoring `content`, `theme` and' ' `settings` for changes. ---') first_run = True # load cache on first run 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()} original_load_cache = settings['LOAD_CONTENT_CACHE'] if modified['settings']: pelican, settings = get_instance(args) if not first_run: original_load_cache = settings['LOAD_CONTENT_CACHE'] # invalidate cache pelican.settings['LOAD_CONTENT_CACHE'] = False 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.') elif modified['theme']: # theme modified, needs full rebuild -> no cache if not first_run: # but not on first run pelican.settings['LOAD_CONTENT_CACHE'] = False pelican.run() first_run = False # restore original caching policy pelican.settings['LOAD_CONTENT_CACHE'] = original_load_cache except KeyboardInterrupt: logger.warning("Keyboard interrupt, quitting.") break except Exception as e: if (args.verbosity == logging.DEBUG): logger.critical(e.args) raise logger.warning( 'Caught exception "{0}". Reloading.'.format(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: # localized systems have errors in native language if locale is set # so convert the message to unicode with the correct encoding msg = str(e) if not six.PY3: msg = msg.decode(locale.getpreferredencoding()) logger.critical(msg) if args.verbosity == logging.DEBUG: raise else: sys.exit(getattr(e, 'exitcode', 1))
def main(): parser = argparse.ArgumentParser( description="""A tool to generate a static blog, with restructured text input files.""" ) parser.add_argument(dest="path", nargs="?", help="Path where to find the content files") parser.add_argument( "-t", "--theme-path", dest="theme", help="Path where to find the theme templates. If not specified, it" "will use the default one included with pelican.", ) parser.add_argument( "-o", "--output", dest="output", help="Where to output the generated files. If not specified, a directory" ' will be created, named "output" in the current path.', ) parser.add_argument( "-m", "--markup", default=None, dest="markup", help="the list of markup language to use (rst or md). Please indicate " "them separated by commas", ) parser.add_argument("-s", "--settings", dest="settings", help="the settings of the application. Default to False.") parser.add_argument( "-d", "--delete-output-directory", dest="delete_outputdir", action="store_true", help="Delete the output directory.", ) parser.add_argument( "-v", "--verbose", action="store_const", const=log.INFO, dest="verbosity", help="Show all messages" ) parser.add_argument( "-q", "--quiet", action="store_const", const=log.CRITICAL, dest="verbosity", help="Show only critical errors" ) parser.add_argument( "-D", "--debug", action="store_const", const=log.DEBUG, dest="verbosity", help="Show all message, including debug messages", ) parser.add_argument("--version", action="version", version=VERSION, help="Print the pelican version and exit") parser.add_argument( "-r", "--autoreload", dest="autoreload", action="store_true", help="Relaunch pelican each time a modification occurs on the content" "files", ) args = parser.parse_args() log.init(args.verbosity) # Split the markup languages only if some have been given. Otherwise, populate # the variable with None. markup = [a.strip().lower() for a in args.markup.split(",")] if args.markup else None if args.settings is None: settings = {} settings = read_settings(args.settings) cls = settings.get("PELICAN_CLASS") if isinstance(cls, basestring): module, cls_name = cls.rsplit(".", 1) module = __import__(module) cls = getattr(module, cls_name) try: pelican = cls(settings, args.path, args.theme, args.output, markup, args.delete_outputdir) if args.autoreload: while True: try: if files_changed(pelican.path, pelican.markup): pelican.run() time.sleep(0.5) # sleep to avoid cpu load except KeyboardInterrupt: break else: pelican.run() except Exception, e: log.critical(str(e))
def main(): args = parse_arguments() init(args.verbosity) pelican = get_instance(args) watchers = { 'content': folder_watcher(pelican.path, pelican.markup, pelican.ignore_files), 'theme': folder_watcher(pelican.theme, [''], pelican.ignore_files), 'settings': file_watcher(args.settings) } # Watch for changes of the TEMPLATE_PAGES. Don't include these # inside `watchers`, as they could appear as a subdirectory of the # pelican.path. Since later the filenames are used in a # dictionary, the order in which the file is checked would be # unpredictable. template_watchers = {} if pelican.settings['TEMPLATE_PAGES']: dirs, extensions = directories_from_template_pages(pelican) for d in dirs: template_watchers[d] = folder_watcher(d, extensions, pelican.ignore_files) try: 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 = get_instance(args) should_regenerate = False 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.') should_regenerate |= True # Check the template watchers modified = { k: next(v) for k, v in template_watchers.items() } if any(modified.values()): print('\n-> Modified: {}. re-generating...'.format( ', '.join(k for k, v in modified.items() if v))) should_regenerate |= True if should_regenerate: pelican.run() except KeyboardInterrupt: logger.warning("Keyboard interrupt, quitting.") break except Exception as e: if (args.verbosity == logging.DEBUG): logger.critical(e.args) raise logger.warning( 'Caught exception "{0}". Reloading.'.format(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: # localized systems have errors in native language if locale is set # so convert the message to unicode with the correct encoding msg = str(e) if not six.PY3: msg = msg.decode(locale.getpreferredencoding(False)) logger.critical(msg) if (args.verbosity == logging.DEBUG): raise else: sys.exit(getattr(e, 'exitcode', 1))
def main(): args = parse_arguments() init(args.verbosity) pelican = get_instance(args) watchers = {'content': folder_watcher(pelican.path, pelican.markup, pelican.ignore_files), 'theme': folder_watcher(pelican.theme, [''], pelican.ignore_files), 'settings': file_watcher(args.settings)} try: 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 = get_instance(args) 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): logger.critical(e.args) raise logger.warning( 'Caught exception "{0}". Reloading.'.format(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: # localized systems have errors in native language if locale is set # so convert the message to unicode with the correct encoding msg = str(e) if not six.PY3: msg = msg.decode(locale.getpreferredencoding(False)) logger.critical(msg) if (args.verbosity == logging.DEBUG): raise else: sys.exit(getattr(e, 'exitcode', 1))
def main(): parser = argparse.ArgumentParser( description="Transform feed, WordPress, Tumblr, Dotclear, or Posterous " "files into reST (rst) or Markdown (md) files. Be sure to " "have pandoc installed.", formatter_class=argparse.ArgumentDefaultsHelpFormatter) parser.add_argument(dest='input', help='The input file to read') parser.add_argument('--wpfile', action='store_true', dest='wpfile', help='Wordpress XML export') parser.add_argument('--dotclear', action='store_true', dest='dotclear', help='Dotclear export') parser.add_argument('--posterous', action='store_true', dest='posterous', help='Posterous export') parser.add_argument('--tumblr', action='store_true', dest='tumblr', help='Tumblr export') parser.add_argument('--feed', action='store_true', dest='feed', help='Feed to parse') parser.add_argument('-o', '--output', dest='output', default='output', help='Output path') parser.add_argument('-m', '--markup', dest='markup', default='rst', help='Output markup format (supports rst & markdown)') parser.add_argument('--dir-cat', action='store_true', dest='dircat', help='Put files in directories with categories name') parser.add_argument('--dir-page', action='store_true', dest='dirpage', help=('Put files recognised as pages in "pages/" sub-directory' ' (wordpress import only)')) parser.add_argument('--filter-author', dest='author', help='Import only post from the specified author') parser.add_argument('--strip-raw', action='store_true', dest='strip_raw', help="Strip raw HTML code that can't be converted to " "markup such as flash embeds or iframes (wordpress import only)") parser.add_argument('--wp-custpost', action='store_true', dest='wp_custpost', help='Put wordpress custom post types in directories. If used with ' '--dir-cat option directories will be created as ' '/post_type/category/ (wordpress import only)') parser.add_argument('--wp-attach', action='store_true', dest='wp_attach', help='(wordpress import only) Download files uploaded to wordpress as ' 'attachments. Files will be added to posts as a list in the post ' 'header. All files will be downloaded, even if ' "they aren't associated with a post. Files with be downloaded " 'with their original path inside the output directory. ' 'e.g. output/wp-uploads/date/postname/file.jpg ' '-- Requires an internet connection --') parser.add_argument('--disable-slugs', action='store_true', dest='disable_slugs', help='Disable storing slugs from imported posts within output. ' 'With this disabled, your Pelican URLs may not be consistent ' 'with your original posts.') parser.add_argument('-e', '--email', dest='email', help="Email address (posterous import only)") parser.add_argument('-p', '--password', dest='password', help="Password (posterous import only)") parser.add_argument('-b', '--blogname', dest='blogname', help="Blog name (Tumblr import only)") args = parser.parse_args() input_type = None if args.wpfile: input_type = 'wordpress' elif args.dotclear: input_type = 'dotclear' elif args.posterous: input_type = 'posterous' elif args.tumblr: input_type = 'tumblr' elif args.feed: input_type = 'feed' else: error = "You must provide either --wpfile, --dotclear, --posterous, --tumblr or --feed options" exit(error) if not os.path.exists(args.output): try: os.mkdir(args.output) except OSError: error = "Unable to create the output folder: " + args.output exit(error) if args.wp_attach and input_type != 'wordpress': error = "You must be importing a wordpress xml to use the --wp-attach option" exit(error) if input_type == 'wordpress': fields = wp2fields(args.input, args.wp_custpost or False) elif input_type == 'dotclear': fields = dc2fields(args.input) elif input_type == 'posterous': fields = posterous2fields(args.input, args.email, args.password) elif input_type == 'tumblr': fields = tumblr2fields(args.input, args.blogname) elif input_type == 'feed': fields = feed2fields(args.input) if args.wp_attach: attachments = get_attachments(args.input) else: attachments = None init() # init logging fields2pelican(fields, args.markup, args.output, dircat=args.dircat or False, dirpage=args.dirpage or False, strip_raw=args.strip_raw or False, disable_slugs=args.disable_slugs or False, filter_author=args.author, wp_custpost = args.wp_custpost or False, wp_attach = args.wp_attach or False, attachments = attachments or None)
def main(): parser = argparse.ArgumentParser( description="Transform feed, WordPress, Tumblr, Dotclear, or Posterous " "files into reST (rst) or Markdown (md) files. Be sure to " "have pandoc installed.", formatter_class=argparse.ArgumentDefaultsHelpFormatter, ) parser.add_argument(dest="input", help="The input file to read") parser.add_argument("--wpfile", action="store_true", dest="wpfile", help="Wordpress XML export") parser.add_argument("--dotclear", action="store_true", dest="dotclear", help="Dotclear export") parser.add_argument("--posterous", action="store_true", dest="posterous", help="Posterous export") parser.add_argument("--tumblr", action="store_true", dest="tumblr", help="Tumblr export") parser.add_argument("--feed", action="store_true", dest="feed", help="Feed to parse") parser.add_argument("-o", "--output", dest="output", default="output", help="Output path") parser.add_argument( "-m", "--markup", dest="markup", default="rst", help="Output markup format (supports rst & markdown)" ) parser.add_argument( "--dir-cat", action="store_true", dest="dircat", help="Put files in directories with categories name" ) parser.add_argument( "--dir-page", action="store_true", dest="dirpage", help=('Put files recognised as pages in "pages/" sub-directory' " (wordpress import only)"), ) parser.add_argument("--filter-author", dest="author", help="Import only post from the specified author") parser.add_argument( "--strip-raw", action="store_true", dest="strip_raw", help="Strip raw HTML code that can't be converted to " "markup such as flash embeds or iframes (wordpress import only)", ) parser.add_argument( "--wp-custpost", action="store_true", dest="wp_custpost", help="Put wordpress custom post types in directories. If used with " "--dir-cat option directories will be created as " "/post_type/category/ (wordpress import only)", ) parser.add_argument( "--wp-attach", action="store_true", dest="wp_attach", help="(wordpress import only) Download files uploaded to wordpress as " "attachments. Files will be added to posts as a list in the post " "header. All files will be downloaded, even if " "they aren't associated with a post. Files with be downloaded " "with their original path inside the output directory. " "e.g. output/wp-uploads/date/postname/file.jpg " "-- Requires an internet connection --", ) parser.add_argument( "--disable-slugs", action="store_true", dest="disable_slugs", help="Disable storing slugs from imported posts within output. " "With this disabled, your Pelican URLs may not be consistent " "with your original posts.", ) parser.add_argument("-e", "--email", dest="email", help="Email address (posterous import only)") parser.add_argument("-p", "--password", dest="password", help="Password (posterous import only)") parser.add_argument("-b", "--blogname", dest="blogname", help="Blog name (Tumblr import only)") args = parser.parse_args() input_type = None if args.wpfile: input_type = "wordpress" elif args.dotclear: input_type = "dotclear" elif args.posterous: input_type = "posterous" elif args.tumblr: input_type = "tumblr" elif args.feed: input_type = "feed" else: error = "You must provide either --wpfile, --dotclear, --posterous, --tumblr or --feed options" exit(error) if not os.path.exists(args.output): try: os.mkdir(args.output) except OSError: error = "Unable to create the output folder: " + args.output exit(error) if args.wp_attach and input_type != "wordpress": error = "You must be importing a wordpress xml to use the --wp-attach option" exit(error) if input_type == "wordpress": fields = wp2fields(args.input, args.wp_custpost or False) elif input_type == "dotclear": fields = dc2fields(args.input) elif input_type == "posterous": fields = posterous2fields(args.input, args.email, args.password) elif input_type == "tumblr": fields = tumblr2fields(args.input, args.blogname) elif input_type == "feed": fields = feed2fields(args.input) if args.wp_attach: attachments = get_attachments(args.input) else: attachments = None init() # init logging fields2pelican( fields, args.markup, args.output, dircat=args.dircat or False, dirpage=args.dirpage or False, strip_raw=args.strip_raw or False, disable_slugs=args.disable_slugs or False, filter_author=args.author, wp_custpost=args.wp_custpost or False, wp_attach=args.wp_attach or False, attachments=attachments or None, )
def main(): args = parse_arguments() init(args.verbosity) 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) try: if args.autoreload: print(' --- AutoReload Mode: Monitoring `content`, `theme` and' ' `settings` for changes. ---') def _ignore_cache(pelican_obj): if pelican_obj.settings['AUTORELOAD_IGNORE_CACHE']: pelican_obj.settings['LOAD_CONTENT_CACHE'] = False 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()} original_load_cache = settings['LOAD_CONTENT_CACHE'] if modified['settings']: pelican, settings = get_instance(args) original_load_cache = settings['LOAD_CONTENT_CACHE'] _ignore_cache(pelican) # 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 for static_path in set(new_static).difference( old_static): 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 for static_path in set(old_static).difference( new_static): 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() # restore original caching policy pelican.settings[ 'LOAD_CONTENT_CACHE'] = original_load_cache except KeyboardInterrupt: logger.warning("Keyboard interrupt, quitting.") break except Exception as e: if (args.verbosity == logging.DEBUG): logger.critical(e.args) 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(): parser = argparse.ArgumentParser( description="Transform feed, Wordpress or Dotclear files to reST (rst) " "or Markdown (md) files. Be sure to have pandoc installed.", formatter_class=argparse.ArgumentDefaultsHelpFormatter, ) parser.add_argument(dest="input", help="The input file to read") parser.add_argument("--wpfile", action="store_true", dest="wpfile", help="Wordpress XML export") parser.add_argument("--dotclear", action="store_true", dest="dotclear", help="Dotclear export") parser.add_argument("--posterous", action="store_true", dest="posterous", help="Posterous export") parser.add_argument("--feed", action="store_true", dest="feed", help="Feed to parse") parser.add_argument("-o", "--output", dest="output", default="output", help="Output path") parser.add_argument( "-m", "--markup", dest="markup", default="rst", help="Output markup format (supports rst & markdown)" ) parser.add_argument( "--dir-cat", action="store_true", dest="dircat", help="Put files in directories with categories name" ) parser.add_argument( "--strip-raw", action="store_true", dest="strip_raw", help="Strip raw HTML code that can't be converted to " "markup such as flash embeds or iframes (wordpress import only)", ) parser.add_argument( "--disable-slugs", action="store_true", dest="disable_slugs", help="Disable storing slugs from imported posts within output. " "With this disabled, your Pelican URLs may not be consistent " "with your original posts.", ) parser.add_argument("-e", "--email", dest="email", help="Email address (posterous import only)") parser.add_argument("-p", "--password", dest="password", help="Password (posterous import only)") args = parser.parse_args() input_type = None if args.wpfile: input_type = "wordpress" elif args.dotclear: input_type = "dotclear" elif args.posterous: input_type = "posterous" elif args.feed: input_type = "feed" else: error = "You must provide either --wpfile, --dotclear, --posterous or --feed options" exit(error) if not os.path.exists(args.output): try: os.mkdir(args.output) except OSError: error = "Unable to create the output folder: " + args.output exit(error) if input_type == "wordpress": fields = wp2fields(args.input) elif input_type == "dotclear": fields = dc2fields(args.input) elif input_type == "posterous": fields = posterous2fields(args.input, args.email, args.password) elif input_type == "feed": fields = feed2fields(args.input) init() # init logging fields2pelican( fields, args.markup, args.output, dircat=args.dircat or False, strip_raw=args.strip_raw or False, disable_slugs=args.disable_slugs or False, )
def main(): args = parse_arguments() init(args.verbosity) 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) } try: 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) 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): logger.critical(e.args) raise logger.warning( 'Caught exception "{0}". Reloading.'.format(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: # localized systems have errors in native language if locale is set # so convert the message to unicode with the correct encoding msg = str(e) if not six.PY3: msg = msg.decode(locale.getpreferredencoding()) logger.critical(msg) if (args.verbosity == logging.DEBUG): raise else: sys.exit(getattr(e, 'exitcode', 1))
def main(): args = parse_arguments() init(args.verbosity) 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), } for static_path in settings.get("STATIC_PATHS", []): watchers[static_path] = folder_watcher(static_path, [""], pelican.ignore_files) try: if args.autoreload: print(" --- AutoReload Mode: Monitoring `content`, `theme` and" " `settings` for changes. ---") def _ignore_cache(pelican_obj): if pelican_obj.settings["AUTORELOAD_IGNORE_CACHE"]: pelican_obj.settings["LOAD_CONTENT_CACHE"] = False 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()} original_load_cache = settings["LOAD_CONTENT_CACHE"] if modified["settings"]: pelican, settings = get_instance(args) original_load_cache = settings["LOAD_CONTENT_CACHE"] print(pelican.settings["AUTORELOAD_IGNORE_CACHE"]) _ignore_cache(pelican) 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() # restore original caching policy pelican.settings["LOAD_CONTENT_CACHE"] = original_load_cache except KeyboardInterrupt: logger.warning("Keyboard interrupt, quitting.") break except Exception as e: if args.verbosity == logging.DEBUG: logger.critical(e.args) raise logger.warning('Caught exception "{0}". Reloading.'.format(e)) finally: time.sleep(0.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: # localized systems have errors in native language if locale is set # so convert the message to unicode with the correct encoding msg = str(e) if not six.PY3: msg = msg.decode(locale.getpreferredencoding()) logger.critical(msg) if args.verbosity == logging.DEBUG: raise else: sys.exit(getattr(e, "exitcode", 1))