X-Git-Url: https://harishankar.org/repos/?p=biaweb_qt.git;a=blobdiff_plain;f=biaweb_exporter.py;fp=biaweb_exporter.py;h=4560181e352e430939deb13806577ad5437572ab;hp=e824c086a484037713453babdd8fca1548859204;hb=826408979db0e8e4675d51def6ce7dadd305cf9c;hpb=b168780a0609f1a8ca2632d6f5e783f200e594d3 diff --git a/biaweb_exporter.py b/biaweb_exporter.py index e824c08..4560181 100644 --- a/biaweb_exporter.py +++ b/biaweb_exporter.py @@ -3,6 +3,7 @@ import os import os.path +import sys import time import sqlite3 import string @@ -48,6 +49,63 @@ def html_format_rating (rating): rating_str = "".join (items) return rating_str +# function to copy additional files and folders to the destination path +def copy_files_folders (conf, files_to_copy, folders_to_copy): + # create the cgi-bin directory and try to copy search.py into the destination directory if possible + # otherwise user must copy it manually + search_script_path = os.path.join (sys.path[0], "search.py") + if os.path.exists (search_script_path): + 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: + return False + + # try to copy the star rating images to destination directory if possible + # otherwise user must copy it manually + rating_img_star = os.path.join (sys.path[0], "star.gif") + rating_img_greystar = os.path.join (sys.path[0], "star-grey.gif") + if os.path.exists (rating_img_star): + try: + shutil.copy2 (rating_img_star, conf[5]) + except IOError, OSError: + return False + if os.path.exists (rating_img_greystar): + try: + shutil.copy2 (rating_img_greystar, conf[5]) + except IOError, OSError: + return False + + # additional files to copy + + # first copy files + # check if files to copy is not empty + if files_to_copy <> []: + for src, dest in files_to_copy: + # get full path from relative path in dest + full_dest = os.path.join (conf[5], dest) + try: + shutil.copy2 (src, full_dest) + except IOError, OSError: + return False + + # additional folders to copy + + # now copy the folders + if folders_to_copy <> []: + for src, dest in folders_to_copy: + # get full path from relative path in dest + full_dest = os.path.join (conf[5], dest) + try: + shutil.copytree (src, full_dest) + except IOError, OSError: + return False + + # finally return true + return True + + + # function to generate article pages def generate_article_pages (dbname, conf, templates, category_str, bestrated_str): # main template @@ -273,5 +331,10 @@ def generate_site (dbname, files_to_copy, folders_to_copy, search_type_full=True if ret == 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: + return False + # finally when all is successfully done return true return True