def _execute(self, options, args): """Start test server.""" out_dir = self.site.config['OUTPUT_FOLDER'] if not os.path.isdir(out_dir): LOGGER.error("Missing '{0}' folder?".format(out_dir)) else: os.chdir(out_dir) httpd = HTTPServer((options['address'], options['port']), OurHTTPRequestHandler) sa = httpd.socket.getsockname() LOGGER.notice("Serving HTTP on {0} port {1} ...".format(*sa)) httpd.serve_forever()
def spell_check(self, post, lang): """ Check spellings for the given post and given language. """ if enchant.dict_exists(lang): checker = SpellChecker(lang, filters=[EmailFilter, URLFilter]) checker.set_text(post.text(lang=lang, strip_html=True)) words = [error.word for error in checker] words = [ word for word in words if self._not_in_other_dictionaries(word, lang) ] LOGGER.notice('Mis-spelt words in %s: %s' % (post.fragment_deps(lang), ', '.join(words))) else: LOGGER.notice('No dictionary found for %s' % lang)
def spell_check(self, post, lang): """ Check spellings for the given post and given language. """ try: dictionary = enchant.request_dict(lang) checker = SpellChecker(lang, filters=[EmailFilter, URLFilter]) checker.set_text(post.text(lang=lang, strip_html=True)) words = [error.word for error in checker] words = [ word for word in words if not dictionary.check(word) ] LOGGER.notice( 'Mis-spelt words in %s: %s' % ( post.fragment_deps(lang), ', '.join(words) ) ) except enchant.DictNotFoundError: LOGGER.notice('No dictionary found for %s' % lang)
def spell_check(self, post, lang): """ Check spellings for the given post and given language. """ if enchant.dict_exists(lang): checker = SpellChecker(lang, filters=[EmailFilter, URLFilter]) checker.set_text(post.text(lang=lang, strip_html=True)) words = [error.word for error in checker] words = [ word for word in words if self._not_in_other_dictionaries(word, lang) ] LOGGER.notice( 'Mis-spelt words in %s: %s' % ( post.fragment_deps(lang), ', '.join(words) ) ) else: LOGGER.notice('No dictionary found for %s' % lang)
def _execute(self, command, args): # Get last succesful deploy date timestamp_path = os.path.join(self.site.config['CACHE_FOLDER'], 'lastdeploy') if self.site.config['COMMENT_SYSTEM_ID'] == 'nikolademo': LOGGER.warn("\nWARNING WARNING WARNING WARNING\n" "You are deploying using the nikolademo Disqus account.\n" "That means you will not be able to moderate the comments in your own site.\n" "And is probably not what you want to do.\n" "Think about it for 5 seconds, I'll wait :-)\n\n") time.sleep(5) deploy_drafts = self.site.config.get('DEPLOY_DRAFTS', True) deploy_future = self.site.config.get('DEPLOY_FUTURE', False) if not (deploy_drafts and deploy_future): # Remove drafts and future posts out_dir = self.site.config['OUTPUT_FOLDER'] self.site.scan_posts() for post in self.site.timeline: if (not deploy_drafts and post.is_draft) or \ (not deploy_future and post.publish_later): remove_file(os.path.join(out_dir, post.destination_path())) remove_file(os.path.join(out_dir, post.source_path)) for command in self.site.config['DEPLOY_COMMANDS']: try: with open(timestamp_path, 'rb') as inf: last_deploy = literal_eval(inf.read().strip()) except Exception: last_deploy = datetime(1970, 1, 1) # NOQA LOGGER.notice("==>", command) ret = subprocess.check_call(command, shell=True) if ret != 0: # failed deployment raise Exception("Failed deployment") LOGGER.notice("Successful deployment") new_deploy = datetime.now() # Store timestamp of successful deployment with codecs.open(timestamp_path, 'wb+', 'utf8') as outf: outf.write(repr(new_deploy))
def scan_links(self, find_sources=False): LOGGER.notice("Checking Links:") LOGGER.notice("===============") failure = False for task in os.popen('nikola list --all', 'r').readlines(): task = task.strip() if task.split(':')[0] in ( 'render_tags', 'render_archive', 'render_galleries', 'render_indexes', 'render_pages' 'render_site') and '.html' in task: if self.analyze(task, find_sources): failure = True if not failure: LOGGER.notice("All links checked.") return failure
def scan_files(self): failure = False LOGGER.notice("Checking Files:") LOGGER.notice("===============\n") only_on_output, only_on_input = self.real_scan_files() if only_on_output: only_on_output.sort() LOGGER.warn("Files from unknown origins:") for f in only_on_output: LOGGER.warn(f) failure = True if only_on_input: only_on_input.sort() LOGGER.warn("Files not generated:") for f in only_on_input: LOGGER.warn(f) if not failure: LOGGER.notice("All files checked.") return failure
def _execute(self, options={}, args=None): """Create a new site.""" if not args: print("Usage: nikola init folder [options]") return False target = args[0] if target is None: print(self.usage) else: if not options or not options.get('demo'): self.create_empty_site(target) LOGGER.notice('Created empty site at {0}.'.format(target)) else: self.copy_sample_site(target) LOGGER.notice("A new site with example data has been created at " "{0}.".format(target)) LOGGER.notice("See README.txt in that folder for more information.") self.create_configuration(target)
def setUpClass(): LOGGER.notice('--- TESTS FOR ItemScopeTag') LOGGER.level = logging.WARNING
def tearDownClass(): sys.stdout.write('\n') LOGGER.level = logbook.NOTICE LOGGER.notice('--- END OF TESTS FOR tags')
def setUpClass(): LOGGER.notice('--- TESTS FOR helloworld')
def tearDownClass(): sys.stdout.write('\n') LOGGER.level = logbook.NOTICE LOGGER.notice('--- END OF TESTS FOR link_figure')
def setUpModule(): LOGGER.notice('--- TESTS FOR tags') LOGGER.level = logging.WARNING
def tearDownClass(): sys.stdout.write('\n') LOGGER.level = logbook.NOTICE LOGGER.notice('--- END OF TESTS FOR ItemScopeNestedCompact')
def setUpClass(): LOGGER.notice('--- TESTS FOR ItemScope') LOGGER.level = logbook.WARNING
def tearDownClass(): sys.stdout.write('\n') LOGGER.level = logging.INFO LOGGER.notice('--- END OF TESTS FOR link_figure')
def tearDownClass(): sys.stdout.write('\n') #LOGGER.level = logbook.NOTICE LOGGER.notice('--- END OF TESTS FOR helloworld')
def setUpClass(): from nikola.__main__ import main main(['install_plugin', 'microdata']) LOGGER.notice('--- TESTS FOR ItemScope') LOGGER.level = logbook.WARNING
def setUpClass(): LOGGER.notice('--- TESTS FOR book_figure') LOGGER.level = logging.WARNING
def tearDownClass(): sys.stdout.write('\n') LOGGER.level = logging.INFO LOGGER.notice('--- END OF TESTS FOR ItemPropUrl')
def setUpClass(): LOGGER.notice('--- TESTS FOR ItemPropUrl') LOGGER.level = logging.WARNING
def setUpClass(): LOGGER.notice('--- TESTS FOR ItemScopeNestedCompact') LOGGER.level = logging.WARNING
def setUpClass(): LOGGER.notice('--- TESTS FOR ItemPropBlock') LOGGER.level = logbook.WARNING
def tearDownClass(): sys.stdout.write('\n') LOGGER.notice('--- END OF TESTS FOR helloworld')
def tearDownClass(): sys.stdout.write('\n') LOGGER.level = logbook.NOTICE LOGGER.notice('--- END OF TESTS FOR ItemPropUrl')
def update_feed(feed): modified = feed.last_modified.timetuple() etag = feed.etag try: parsed = feedparser.parse( feed.url, etag=etag, modified=modified ) feed.last_status = str(parsed.status) except: # Probably a timeout # TODO: log failure return if parsed.feed.get('title'): LOGGER.notice(parsed.feed.title) else: LOGGER.notice(feed.url) feed.etag = parsed.get('etag', 'foo') modified = tuple(parsed.get('date_parsed', (1970, 1, 1)))[:6] LOGGER.notice("==========>", modified) modified = datetime.datetime(*modified) feed.last_modified = modified feed.save() # No point in adding items from missinfg feeds if parsed.status > 400: # TODO log failure return for entry_data in parsed.entries: LOGGER.notice("=========================================") date = entry_data.get('published_parsed', None) if date is None: date = entry_data.get('updated_parsed', None) if date is None: LOGGER.error("Can't parse date from:\n", entry_data) return False LOGGER.notice("DATE:===>", date) date = datetime.datetime(*(date[:6])) title = "%s: %s" % (feed.name, entry_data.get('title', 'Sin tÃtulo')) content = entry_data.get('content', None) if content: content = content[0].value if not content: content = entry_data.get('description', None) if not content: content = entry_data.get('summary', 'Sin contenido') guid = str(entry_data.get('guid', entry_data.link)) link = entry_data.link LOGGER.notice(repr([date, title])) e = list(Entry.select().where(Entry.guid == guid)) LOGGER.notice( repr(dict( date=date, title=title, content=content, guid=guid, feed=feed, link=link, )) ) if not e: entry = Entry.create( date=date, title=title, content=content, guid=guid, feed=feed, link=link, ) else: entry = e[0] entry.date = date entry.title = title entry.content = content entry.link = link entry.save()
def setUpClass(): LOGGER.notice('--- TESTS FOR link_figure') LOGGER.level = logbook.WARNING
def generate_css(): # Compass compile for theme_name in self.site.THEMES: theme_root = os.path.abspath(utils.get_theme_path(theme_name)) compass_root = os.path.abspath(os.path.join(theme_root, 'style')) tmp_dir = os.path.abspath(os.path.join(theme_root, '_tmp')) if os.path.exists(compass_root): LOGGER.notice("PYGMENTS CSS CODE") create_code_css(self.site.config['CODE_COLOR_SCHEME'], os.path.join(compass_root, 'css', 'code.css')) LOGGER.notice("COMPASS COMPILE") run('compass clean', cwd=compass_root) run('compass compile', cwd=compass_root) LOGGER.notice("AUTOPREFIXER") LOGGER.notice("CWD: {}".format(theme_root)) run('autoprefixer -o _tmp/all.pre.css _tmp/all.css', cwd=theme_root) LOGGER.notice("CSSO (CSS optimizer)") LOGGER.notice("CWD: {}".format(theme_root)) run('csso _tmp/all.pre.css _tmp/all.min.css', cwd=theme_root) LOGGER.notice("Move CSS to output") css_output_dir = os.path.join(os.path.abspath(self.site.config['OUTPUT_FOLDER']), 'assets', 'css') utils.makedirs(css_output_dir) shutil.copy2(os.path.join(tmp_dir, 'all.min.css'), css_output_dir)
def setUpClass(): LOGGER.notice('--- TESTS FOR publication_list') LOGGER.level = logbook.WARNING
def tearDownModule(): sys.stdout.write('\n') LOGGER.level = logging.INFO LOGGER.notice('--- END OF TESTS FOR tags')
def tearDownClass(): sys.stdout.write('\n') LOGGER.level = logbook.NOTICE LOGGER.notice('--- END OF TESTS FOR publication_list')
def setUpClass(): LOGGER.notice('--- TESTS FOR publication_list') LOGGER.level = logging.WARNING
def setUpClass(): LOGGER.notice('--- TESTS FOR tags') LOGGER.level = logbook.WARNING
def setUpModule(): LOGGER.notice('--- TESTS FOR tags') LOGGER.level = logbook.WARNING
def say_hi(bye): if bye: LOGGER.notice('BYE WORLD') else: LOGGER.notice('HELLO WORLD')
def tearDownClass(): sys.stdout.write('\n') LOGGER.level = logging.INFO LOGGER.notice('--- END OF TESTS FOR publication_list')
def tearDownModule(): sys.stdout.write('\n') LOGGER.level = logbook.NOTICE LOGGER.notice('--- END OF TESTS FOR tags')