def test_files_changed(self): """Test if file changes are correctly detected Make sure to handle not getting any files correctly""" path = os.path.join(os.path.dirname(__file__), 'content') filename = os.path.join(path, 'article_with_metadata.rst') changed = utils.files_changed(path, 'rst') self.assertEquals(changed, True) changed = utils.files_changed(path, 'rst') self.assertEquals(changed, False) t = time.time() os.utime(filename, (t, t)) changed = utils.files_changed(path, 'rst') self.assertEquals(changed, True) self.assertAlmostEqual(utils.LAST_MTIME, t, delta=1) empty_path = os.path.join(os.path.dirname(__file__), 'empty') try: os.mkdir(empty_path) os.mkdir(os.path.join(empty_path, "empty_folder")) shutil.copy(__file__, empty_path) with self.assertRaises(NoFilesError): utils.files_changed(empty_path, 'rst') except OSError: self.fail("OSError Exception in test_files_changed test") finally: shutil.rmtree(empty_path, True)
def test_files_changed(self): # Test if file changes are correctly detected # Make sure to handle not getting any files correctly. dirname = os.path.join(os.path.dirname(__file__), 'content') path = os.path.join(dirname, 'article_with_metadata.rst') changed = utils.files_changed(dirname, 'rst') self.assertEquals(changed, True) changed = utils.files_changed(dirname, 'rst') self.assertEquals(changed, False) t = time.time() os.utime(path, (t, t)) changed = utils.files_changed(dirname, 'rst') self.assertEquals(changed, True) self.assertAlmostEqual(utils.LAST_MTIME, t, delta=1) empty_path = os.path.join(os.path.dirname(__file__), 'empty') try: os.mkdir(empty_path) os.mkdir(os.path.join(empty_path, "empty_folder")) shutil.copy(__file__, empty_path) with self.assertRaises(NoFilesError): utils.files_changed(empty_path, 'rst') except OSError: self.fail("OSError Exception in test_files_changed test") finally: shutil.rmtree(empty_path, True)
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: 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) 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 test_files_changed(self): "Test if file changes are correctly detected" path = os.path.join(os.path.dirname(__file__), 'content') filename = os.path.join(path, 'article_with_metadata.rst') changed = utils.files_changed(path, 'rst') self.assertEquals(changed, True) changed = utils.files_changed(path, 'rst') self.assertEquals(changed, False) t = time.time() os.utime(filename, (t, t)) changed = utils.files_changed(path, 'rst') self.assertEquals(changed, True) self.assertAlmostEqual(utils.LAST_MTIME, t, places=0)
def test_files_changed(self): "Test if file changes are correctly detected" path = os.path.join(os.path.dirname(__file__), 'content') filename = os.path.join(path, 'article_with_metadata.rst') changed = utils.files_changed(path, 'rst') self.assertEquals(changed, True) changed = utils.files_changed(path, 'rst') self.assertEquals(changed, False) t = time.time() os.utime(filename, (t, t)) changed = utils.files_changed(path, 'rst') self.assertEquals(changed, True) self.assertAlmostEqual(utils.LAST_MTIME, t, delta=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(): 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('--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() # 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) 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()
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(): 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', 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('--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() # 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) 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()
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))