1 # BiaWeb Website content manager (c) 2010 V.Harishankar
8 import ui_generate_dialog
11 class GenerateDialog (PyQt4
.QtGui
.QDialog
, ui_generate_dialog
.Ui_SiteGenerateDialog
):
12 def __init__ (self
, master
, currentdb
):
13 PyQt4
.QtGui
.QDialog
.__init
__ (self
, master
)
16 # update the status of required additional files to be copied to
17 # the destination directory and warn the user accordingly
18 self
.set_required_files_status ()
21 self
.current_db
= currentdb
23 # function to set the status message of the required additional files to be copied to
24 # the destination directory. If any required additional file is missing in the script
25 # path then warn the user to copy those files manually to the destination directory
26 def set_required_files_status (self
):
27 search_script_path
= os
.path
.join (sys
.path
[0], "search.py")
28 star_image_path
= os
.path
.join (sys
.path
[0], "star.gif")
29 stargrey_image_path
= os
.path
.join (sys
.path
[0], "star-grey.gif")
31 # if search.py exists in script directory
32 if os
.path
.exists (search_script_path
):
33 self
.status_search_py
.setText ('<span style="color:darkgreen;">will be \
34 automatically copied to destination dir</span>')
36 self
.status_search_py
.setText ('<span style="color:darkred;">cannot be found.\
37 You must copy it manually to cgi-bin</span>')
39 # if star.gif exists in script directory
40 if os
.path
.exists (star_image_path
):
41 self
.status_star_gif
.setText ('<span style="color:darkgreen;">will be \
42 automatically copied to destination dir</span>')
44 self
.status_star_gif
.setText ('<span style="color:darkred;">Cannot be found. \
45 You must copy it manually to destination dir</span')
47 # if star-grey.gif exists in script directory
48 if os
.path
.exists (stargrey_image_path
):
49 self
.status_stargrey_gif
.setText ('<span style="color:darkgreen;">will be \
50 automatically copied to destination dir</span>')
52 self
.status_stargrey_gif
.setText ('<span style="color:darkred;">cannot be found. \
53 You must copy it manually to destination dir</span')
55 # to return the list of items from a tree widget
56 def get_list_from_tree (self
, treewidget
):
58 iter = PyQt4
.QtGui
.QTreeWidgetItemIterator (treewidget
)
60 # iterate through the list of files
62 # while there is still a valid item
64 # get the text in columns 0 and 1
65 src
= str (item
.text (0))
66 dst
= str (item
.text (1))
68 lstfiles
.append ( (src
, dst
) )
69 # increase iterator by 1
75 # when site generate button is clicked
76 def onSiteGenerate (self
):
77 files_list
= self
.get_list_from_tree (self
.additional_files
)
78 folder_list
= self
.get_list_from_tree (self
.additional_folders
)
79 if self
.fulltextindex
.isChecked ():
84 # confirm whether to delete the destination tree and work afresh
85 ans
= PyQt4
.QtGui
.QMessageBox
.question (self
, "Confirm",
86 "This will delete the destination tree completely \
87 and recreate the website. Are you sure you wish to proceed?",
88 PyQt4
.QtGui
.QMessageBox
.Yes
, PyQt4
.QtGui
.QMessageBox
.No
)
91 if ans
== PyQt4
.QtGui
.QMessageBox
.Yes
:
92 # call the main exporter to do our work
93 ret
= biaweb_exporter
.generate_site (self
.current_db
, files_list
, folder_list
, searchtype
)
95 # if failed to generate site or any part thereof
97 PyQt4
.QtGui
.QMessageBox
.critical (self
, "Error",
98 "System or SQLite 3 error in generating website or parts thereof")
100 PyQt4
.QtGui
.QMessageBox
.information (self
, "Success",
101 "Successfully generated website in destination path!")
103 # when folder add is clicked
104 def onFolderAdd (self
):
105 folder_to_add
= PyQt4
.QtGui
.QFileDialog
.getExistingDirectory (self
,
106 "Folder whose contents to add to destination", os
.path
.expanduser ("~"))
107 # if cancelled return
108 if not folder_to_add
:
111 dest_rel_path
, ok
= PyQt4
.QtGui
.QInputDialog
.getText (self
, "Desination",
112 "Copy to location (within destination path)")
116 folderitem
= PyQt4
.QtGui
.QTreeWidgetItem ([folder_to_add
, dest_rel_path
])
117 self
.additional_folders
.addTopLevelItem (folderitem
)
119 # when folder remove is clicked
120 def onFolderRemove (self
):
121 selitem
= self
.additional_folders
.currentItem ()
122 selindex
= self
.additional_folders
.indexOfTopLevelItem (selitem
)
126 self
.additional_folders
.takeTopLevelItem (selindex
)
129 # when file add is clicked
130 def onFileAdd (self
):
131 file_to_add
= PyQt4
.QtGui
.QFileDialog
.getOpenFileName (self
, "File to add to destination",
132 os
.path
.expanduser ("~"))
133 # if cancelled return
136 dest_rel_path
, ok
= PyQt4
.QtGui
.QInputDialog
.getText (self
, "Destination",
137 "Copy to location (within destination path)")
141 fileitem
= PyQt4
.QtGui
.QTreeWidgetItem ([file_to_add
, dest_rel_path
])
142 self
.additional_files
.addTopLevelItem (fileitem
)
144 # when file remove is clicked
145 def onFileRemove (self
):
146 selitem
= self
.additional_files
.currentItem ()
147 selindex
= self
.additional_files
.indexOfTopLevelItem (selitem
)
151 self
.additional_files
.takeTopLevelItem (selindex
)