Updated htaccess to Apache 2.4 compat
[biaweb_qt.git] / biaweb_exporter.py
index 9531159..6cba706 100644 (file)
@@ -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
@@ -132,7 +132,7 @@ def generate_search_index (dbname, conf, full_text_index = True):
                fhtaccess = open (htaccess_path, "w+")
                fhtaccess.write (biaweb_strings.searchindex_htaccess)
                fhtaccess.close ()
-       except OSError, IOError:
+       except (OSError, IOError):
                return False
 
        # finally return true
@@ -147,7 +147,7 @@ def copy_files_folders (conf, files_to_copy, folders_to_copy):
                try:
                        os.mkdir (os.path.join (conf[5], "cgi-bin"))
                        shutil.copy2 (search_script_path, os.path.join(conf[5], "cgi-bin"))
-               except IOError, OSError:
+               except (IOError, OSError):
                        return False
 
        # try to copy the star rating images  to destination directory if possible
@@ -157,12 +157,12 @@ def copy_files_folders (conf, files_to_copy, folders_to_copy):
        if os.path.exists (rating_img_star):
                try:
                        shutil.copy2 (rating_img_star, conf[5])
-               except IOError, OSError:
+               except (IOError, OSError):
                        return False
        if os.path.exists (rating_img_greystar):
                try:
                        shutil.copy2 (rating_img_greystar, conf[5])
-               except IOError, OSError:
+               except (IOError, OSError):
                        return False
 
        # additional files to copy
@@ -175,7 +175,7 @@ def copy_files_folders (conf, files_to_copy, folders_to_copy):
                        full_dest = os.path.join (conf[5], dest)
                        try:
                                shutil.copy2 (src, full_dest)
-                       except IOError, OSError:
+                       except (IOError, OSError):
                                return False
 
        # additional folders to copy
@@ -187,7 +187,7 @@ def copy_files_folders (conf, files_to_copy, folders_to_copy):
                        full_dest = os.path.join (conf[5], dest)
                        try:
                                shutil.copytree (src, full_dest)
-                       except IOError, OSError:
+                       except (IOError, OSError):
                                return False
 
        # finally return true
@@ -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
@@ -219,7 +219,7 @@ def generate_article_pages (dbname, conf, templates, category_str, bestrated_str
                                                                                                        article_contents = art[4])
 
                # now build the article page
-               articlepage_str = tpl_main.safe_substitute (site_title = conf[1],
+               articlepage_str = tpl_main.safe_substitute (site_title = art[1],
                                                                                                        site_url = "http://" + conf[0],
                                                                                                        meta_keywords = art[3],
                                                                                                        meta_description = art[2],
@@ -233,7 +233,7 @@ def generate_article_pages (dbname, conf, templates, category_str, bestrated_str
                try:
                        farticle = open (os.path.join (conf[5], art[13], art[8] + ".html"), "w+")
                        farticle.write (articlepage_str)
-               except OSError, IOError:
+               except (OSError, IOError):
                        return False
 
        # finally return true
@@ -253,12 +253,12 @@ def generate_category_indices (dbname, conf, templates, category_str, bestrated_
                try:
                        # create the category directory
                        os.mkdir (os.path.join (conf[5], cat[3]))
-               except IOError, OSError:
+               except (IOError, OSError):
                        return False
 
                # 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 = []
@@ -282,7 +282,7 @@ def generate_category_indices (dbname, conf, templates, category_str, bestrated_
                                                                                                                table_rows = tablerows_str)
 
                # now create the index page
-               categoryindex_str =  tpl_main.safe_substitute (site_title = conf[1],
+               categoryindex_str =  tpl_main.safe_substitute (site_title = conf[1] + " - " + cat[1],
                                                                                                                site_url = "http://" + conf[0],
                                                                                                                meta_keywords = conf[2],
                                                                                                                meta_description = cat[2],
@@ -298,7 +298,7 @@ def generate_category_indices (dbname, conf, templates, category_str, bestrated_
                        fcatindex = open (os.path.join (conf[5], cat[3], "index.html"), "w+")
                        fcatindex.write (categoryindex_str)
                        fcatindex.close ()
-               except OSError, IOError:
+               except (OSError, IOError):
                        return False
 
        # finally return true
@@ -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 = []
@@ -339,7 +339,7 @@ def generate_rss_feed (dbname, conf):
        try:
                frss = open (os.path.join (conf[5], "subscribe.xml"), "w+")
                frss.write (rss_str)
-       except IOError, OSError:
+       except (IOError, OSError):
                return False
 
        # finally return true
@@ -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 = []
@@ -399,7 +399,7 @@ def generate_home_page (dbname, conf, templates, category_str, bestrated_str):
                findex = open (os.path.join (conf[5], "index.html"), "w+")
                findex.write (main_str)
                findex.close ()
-       except IOError, OSError:
+       except (IOError, OSError):
                return False
 
        # write the style.css file in the destination directory
@@ -407,7 +407,7 @@ def generate_home_page (dbname, conf, templates, category_str, bestrated_str):
                fstyle = open (os.path.join (conf[5], "style.css"), "w+")
                fstyle.write (templates[5][1])
                fstyle.close ()
-       except IOError, OSError:
+       except (IOError, OSError):
                return False
 
        return True
@@ -416,13 +416,19 @@ def generate_home_page (dbname, conf, templates, category_str, bestrated_str):
 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 is False:
+               return False
+
        # get the templates
        tpls = biaweb_db.get_templates (dbname)
+       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
@@ -431,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)
@@ -446,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