From 1e98086e7040991b7aa6904fbac30f256a84f299 Mon Sep 17 00:00:00 2001 From: Harishankar Date: Thu, 2 Dec 2010 15:43:48 +0530 Subject: [PATCH] Specific boolean comparisons in code made literal Changed all comparisons with False in code now to literal checking (ie. used "var is False" rather than "var == False"). This will avoid some unforseen circumstances. --- biaweb_exporter.py | 30 +++++++++++++++--------------- main_window.py | 6 +++--- templates_dialog.py | 4 ++-- 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/biaweb_exporter.py b/biaweb_exporter.py index 52d9a02..b940867 100644 --- a/biaweb_exporter.py +++ b/biaweb_exporter.py @@ -76,7 +76,7 @@ def generate_search_index (dbname, conf, full_text_index = True): # get all the articles arts = biaweb_db.site_articles (dbname) # if cannot get articles - if arts == False: + if arts is False: return False # if full text index, then field should be article content otherwise keywords @@ -202,7 +202,7 @@ def generate_article_pages (dbname, conf, templates, category_str, bestrated_str # get all articles from the database articles = biaweb_db.site_articles (dbname) - if articles == False: + if articles is False: return # walk through each article and generate the file in the appropriate category @@ -258,7 +258,7 @@ def generate_category_indices (dbname, conf, templates, category_str, bestrated_ # now get the list of articles for the specified category articles_list = biaweb_db.site_articles (dbname, cat[0]) - if articles_list == False: + if articles_list is False: return False tableitems = [] @@ -313,7 +313,7 @@ def generate_rss_feed (dbname, conf): # get the latest articles (limit by number of rss items) arts = biaweb_db.site_latest_articles (dbname, conf[4]) - if arts == False: + if arts is False: return False rss_item_list = [] @@ -356,7 +356,7 @@ def generate_home_page (dbname, conf, templates, category_str, bestrated_str): # get the latest articles - conf[4] is num of rss entries to be used also latest_arts = biaweb_db.site_latest_articles (dbname, conf[4]) - if latest_arts == False: + if latest_arts is False: return False news_items = [] @@ -417,18 +417,18 @@ def generate_site (dbname, files_to_copy, folders_to_copy, search_type_full=True # get the configuration conf = biaweb_db.get_configuration (dbname) # if cannot get configuration - if conf == False: + if conf is False: return False # get the templates tpls = biaweb_db.get_templates (dbname) - if tpls == False: + if tpls is False: return False # get the list of categories cats = biaweb_db.get_categories (dbname) # cannot get categories return false - if cats == False: + if cats is False: return False # format the categories as a html bulleted list @@ -437,7 +437,7 @@ def generate_site (dbname, files_to_copy, folders_to_copy, search_type_full=True # get the best rated articles best_rated = biaweb_db.site_get_bestrated (dbname) # if cannot retrieve - if best_rated == False: + if best_rated is False: return False # format the best rated articles as a html bulleted list best_rated_str = html_format_best_rated (best_rated) @@ -452,32 +452,32 @@ def generate_site (dbname, files_to_copy, folders_to_copy, search_type_full=True # generate the index page including style sheet ret = generate_home_page (dbname, conf, tpls, cats_str, best_rated_str) - if ret == False: + if ret is False: return False # generate the rss feed ret = generate_rss_feed (dbname, conf) - if ret == False: + if ret is False: return False # generate the category directories and indices ret = generate_category_indices (dbname, conf, tpls, cats_str, best_rated_str, cats) - if ret == False: + if ret is False: return False # generate the article pages ret = generate_article_pages (dbname, conf, tpls, cats_str, best_rated_str) - if ret == False: + if ret is False: return False # copy other files/folders into the destination path ret = copy_files_folders (conf, files_to_copy, folders_to_copy) - if ret == False: + if ret is False: return False # now generate the search index database ret = generate_search_index (dbname, conf, search_type_full) - if ret == False: + if ret is False: return False # finally when all is successfully done return true diff --git a/main_window.py b/main_window.py index 799fdf8..57762af 100644 --- a/main_window.py +++ b/main_window.py @@ -23,7 +23,7 @@ class MainWindow (PyQt4.QtGui.QMainWindow, ui_main_window.Ui_MainWindow): recs = biaweb_db.get_categories (self.current_db) # check with False because None is returned when no records exist - if recs == False: + if recs is False: PyQt4.QtGui.QMessageBox.critical (self, "Error", "SQLite 3 error in getting the categories") return False @@ -40,7 +40,7 @@ class MainWindow (PyQt4.QtGui.QMainWindow, ui_main_window.Ui_MainWindow): recs = biaweb_db.get_articles (self.current_db, catid) # check with False because None is returned when no records exist - if recs == False: + if recs is False: PyQt4.QtGui.QMessageBox.critical (self, "Error", "SQLite 3 error in getting the articles") return False @@ -342,7 +342,7 @@ class MainWindow (PyQt4.QtGui.QMainWindow, ui_main_window.Ui_MainWindow): loaded_arts = self.repopulate_articles () # if failed in loading either categories or articles (note: checking against # False and not None) - if loaded_cats == False or loaded_arts == False: + if loaded_cats is False or loaded_arts is False: self.current_db = None PyQt4.QtGui.QMessageBox.critical (self, "Error", "SQLite 3 error in loading site database. This appears to be an invalid BiaWeb database") diff --git a/templates_dialog.py b/templates_dialog.py index 20f2e18..db61404 100644 --- a/templates_dialog.py +++ b/templates_dialog.py @@ -35,7 +35,7 @@ class TemplatesDialog (PyQt4.QtGui.QDialog, ui_templates_dialog.Ui_TemplatesDial tpl_str = biaweb_db.get_template_text (self.current_db, tpl_name) # if template string cannot be obtained for some reason - if tpl_str == False: + if tpl_str is False: PyQt4.QtGui.QMessageBox.critical (self, "Error", "SQLite 3 error in retrieving template") else: # open edit dialog with title "template name" and text as the template string @@ -47,6 +47,6 @@ class TemplatesDialog (PyQt4.QtGui.QDialog, ui_templates_dialog.Ui_TemplatesDial # update the template with the new template string ret = biaweb_db.update_template (self.current_db, tpl_name, upd_tpl_str) # if update failed - if ret == False: + if ret is False: PyQt4.QtGui.QMessageBox.critical (self, "Error", "SQLite 3 error in updating template") -- 2.20.1