12 from __future__
import absolute_import
13 from __future__
import print_function
17 import sys, os, subprocess, traceback
18 from project_modules.jobsuberror
import JobsubError
19 from larbatch_utilities
import convert_str
24 import project_utilities
25 from project_modules.batchstatus
import BatchStatus
31 import tkinter.filedialog
as tkinter_filedialog
32 import tkinter.messagebox
as tkinter_messagebox
33 import tkinter.font
as tkinter_font
36 import tkFileDialog
as tkinter_filedialog
37 import tkMessageBox
as tkinter_messagebox
38 import tkFont
as tkinter_font
40 from project_gui_modules.projectview
import ProjectView
41 from project_gui_modules.textwindow
import TextWindow
59 self.root.title(
'project')
60 self.root.protocol(
'WM_DELETE_WINDOW', self.
close)
64 tk.Frame.__init__(self, self.
root)
65 self.pack(expand=1, fill=tk.BOTH)
85 for n
in range(1, len(sys.argv)):
87 self.
open(xmlpath, choose=
False)
95 self.rowconfigure(2, weight=1)
96 self.columnconfigure(0, weight=1)
105 self.project_view.grid(row=1, column=0, sticky=tk.E+tk.W)
110 self.console.grid(row=2, column=0, sticky=tk.N+tk.E+tk.W+tk.S)
119 self.after(120000, self.
often)
125 self.after(120000, self.
often)
134 self.menubar.grid(row=0, column=0, sticky=tk.E+tk.W)
138 mbutton = tk.Menubutton(self.
menubar, text=
'File', font=tkinter_font.Font(size=12))
139 mbutton.pack(side=tk.LEFT)
140 file_menu = tk.Menu(mbutton)
141 file_menu.add_command(label=
'Open Project', command=self.
open)
142 file_menu.add_command(label=
'Quit', command=self.
close)
143 mbutton[
'menu'] = file_menu
147 mbutton = tk.Menubutton(self.
menubar, text=
'View', font=tkinter_font.Font(size=12))
148 mbutton.pack(side=tk.LEFT)
149 view_menu = tk.Menu(mbutton)
150 view_menu.add_command(label=
'XML', command=self.
xml_display)
151 mbutton[
'menu'] = view_menu
155 mbutton = tk.Menubutton(self.
menubar, text=
'Project', font=tkinter_font.Font(size=12))
156 mbutton.pack(side=tk.LEFT)
158 self.project_menu.add_command(label=
'Next Project', command=self.
next_project,
160 self.project_menu.add_command(label=
'Previous Project', command=self.
previous_project,
162 self.project_menu.add_separator()
174 mbutton = tk.Menubutton(self.
menubar, text=
'Stage', font=tkinter_font.Font(size=12))
175 mbutton.pack(side=tk.LEFT)
177 self.stage_menu.add_command(label=
'Next Stage', command=self.
next_stage,
179 self.stage_menu.add_command(label=
'Previous Stage', command=self.
previous_stage,
181 self.stage_menu.add_separator()
193 mbutton = tk.Menubutton(self.
menubar, text=
'Output', font=tkinter_font.Font(size=12))
194 mbutton.pack(side=tk.LEFT)
196 self.output_menu.add_command(label=
'Check', command=self.
check)
197 self.output_menu.add_command(label=
'Checkana', command=self.
checkana)
198 self.output_menu.add_command(label=
'Fetchlog', command=self.
fetchlog)
199 self.output_menu.add_command(label=
'Shorten', command=self.
shorten)
200 self.output_menu.add_separator()
201 self.output_menu.add_command(label=
'Histogram merge', command=self.
mergehist)
202 self.output_menu.add_command(label=
'Ntuple merge', command=self.
mergentuple)
203 self.output_menu.add_command(label=
'Custom merge', command=self.
merge)
204 self.output_menu.add_separator()
205 self.output_menu.add_command(label=
'Clean', command=self.
clean)
210 mbutton = tk.Menubutton(self.
menubar, text=
'Batch', font=tkinter_font.Font(size=12))
211 mbutton.pack(side=tk.LEFT)
213 self.batch_menu.add_command(label=
'Submit', command=self.
submit)
214 self.batch_menu.add_command(label=
'Makeup', command=self.
makeup)
215 self.batch_menu.add_command(label=
'Update', command=self.
update_jobs)
216 self.batch_menu.add_command(label=
'Kill', command=self.
kill_jobs)
221 mbutton = tk.Menubutton(self.
menubar, text=
'SAM-art', font=tkinter_font.Font(size=12))
222 mbutton.pack(side=tk.LEFT)
224 self.sam_menu.add_command(label=
'Check Declarations', command=self.
check_declarations)
225 self.sam_menu.add_command(label=
'Declare Files', command=self.
declare)
226 self.sam_menu.add_command(label=
'Test Declarations', command=self.
test_declarations)
227 self.sam_menu.add_separator()
228 self.sam_menu.add_command(label=
'Check Dataset Definition', command=self.
check_definition)
229 self.sam_menu.add_command(label=
'Create Dataset Definition', command=self.
define)
230 self.sam_menu.add_command(label=
'Test Dataset Definition', command=self.
test_definition)
231 self.sam_menu.add_separator()
232 self.sam_menu.add_command(label=
'Check Locations', command=self.
check_locations)
233 self.sam_menu.add_command(label=
'Check Tape Locations', command=self.
check_tape)
234 self.sam_menu.add_command(label=
'Add Disk Locations', command=self.
add_locations)
235 self.sam_menu.add_command(label=
'Clean Disk Locations', command=self.
clean_locations)
236 self.sam_menu.add_command(label=
'Remove Disk Locations', command=self.
remove_locations)
237 self.sam_menu.add_command(label=
'Upload to Enstore', command=self.
upload)
238 self.sam_menu.add_separator()
239 self.sam_menu.add_command(label=
'Audit', command=self.
audit)
244 mbutton = tk.Menubutton(self.
menubar, text=
'SAM-ana', font=tkinter_font.Font(size=12))
245 mbutton.pack(side=tk.LEFT)
248 self.sam_menu.add_command(label=
'Declare Files', command=self.
declare_ana)
250 self.sam_menu.add_separator()
251 self.sam_menu.add_command(label=
'Check Dataset Definition',
253 self.sam_menu.add_command(label=
'Create Dataset Definition', command=self.
define_ana)
254 self.sam_menu.add_command(label=
'Test Dataset Definition',
256 self.sam_menu.add_separator()
258 self.sam_menu.add_command(label=
'Check Tape Locations', command=self.
check_ana_tape)
259 self.sam_menu.add_command(label=
'Add Disk Locations', command=self.
add_ana_locations)
262 self.sam_menu.add_command(label=
'Upload to Enstore', command=self.
upload_ana)
269 mbutton = tk.Menubutton(self.
menubar, text=
'Help', font=tkinter_font.Font(size=12))
270 mbutton.pack(side=tk.RIGHT)
272 self.help_menu.add_command(label=
'project.py help', command=self.
help)
273 self.help_menu.add_command(label=
'XML help', command=self.
xmlhelp)
280 def open(self, xml_path=None, choose=True):
282 types = ((
'XML files',
'*.xml'),
284 d = tkinter_filedialog.Open(filetypes=types, parent=self.
root)
291 top=self.winfo_toplevel()
292 old_cursor = top[
'cursor']
295 top[
'cursor'] =
'watch'
296 top.update_idletasks()
298 if len(new_project_defs) > 0:
299 project_defs.extend(new_project_defs)
300 top[
'cursor'] = old_cursor
302 top[
'cursor'] = old_cursor
304 message =
'Error opening %s\n%s' % (xml_path, e[1])
305 traceback.print_tb(e[2])
306 tkinter_messagebox.showerror(
'', message)
309 if len(project_defs) > 0:
310 project_name = project_defs[0].name
312 xml_name = os.path.basename(xml_path)
313 n = xml_name.find(
'.xml')
315 project_name = xml_name[0: n]
317 project_name = xml_name
323 if project_name == project_tuple[0]:
330 self.projects.append((project_name, xml_path, project_defs))
334 callback = tk._setit(tk.StringVar(), project_name, callback=self.
choose_project)
335 self.project_menu.add_command(label=project_name, command=callback)
352 project_name = project_tuple[0]
353 xml_path = project_tuple[1]
354 project_defs = project_tuple[2]
355 if project_name == value:
361 self.project_view.set_project(project_name, xml_path, project_defs)
365 self.stage_menu.delete(3, tk.END)
366 self.stage_menu.add_separator()
367 for project_def
in project_defs:
368 for stage
in project_def.stages:
369 callback = tk._setit(tk.StringVar(), stage.name, callback=self.
choose_stage)
370 self.stage_menu.add_command(label=stage.name, command=callback)
376 raise 'No project: %s' % value
382 for stage
in project_def.stages:
383 if stage.name == value:
412 project_name = project_tuple[0]
434 previous_project_name = self.
projects[-1][0]
436 project_name = project_tuple[0]
440 previous_project_name = project_name
449 self.project_view.make_xml_window()
475 tkinter_messagebox.showwarning(
'',
'No project selected.')
478 tkinter_messagebox.showwarning(
'',
'No stage selected.')
480 top=self.winfo_toplevel()
481 old_cursor = top[
'cursor']
483 top[
'cursor'] =
'watch'
484 top.update_idletasks()
486 quick=self.current_stage_def.validate_on_worker)
487 top[
'cursor'] = old_cursor
489 top[
'cursor'] = old_cursor
491 traceback.print_tb(e[2])
492 tkinter_messagebox.showerror(
'', e[1])
493 self.project_view.update_status()
499 tkinter_messagebox.showwarning(
'',
'No project selected.')
502 tkinter_messagebox.showwarning(
'',
'No stage selected.')
504 top=self.winfo_toplevel()
505 old_cursor = top[
'cursor']
507 top[
'cursor'] =
'watch'
508 top.update_idletasks()
510 top[
'cursor'] = old_cursor
512 top[
'cursor'] = old_cursor
514 traceback.print_tb(e[2])
515 tkinter_messagebox.showerror(
'', e[1])
516 self.project_view.update_status()
522 tkinter_messagebox.showwarning(
'',
'No project selected.')
525 tkinter_messagebox.showwarning(
'',
'No stage selected.')
527 top=self.winfo_toplevel()
528 old_cursor = top[
'cursor']
530 top[
'cursor'] =
'watch'
531 top.update_idletasks()
533 top[
'cursor'] = old_cursor
535 top[
'cursor'] = old_cursor
537 traceback.print_tb(e[2])
538 tkinter_messagebox.showerror(
'', e[1])
544 tkinter_messagebox.showwarning(
'',
'No project selected.')
547 tkinter_messagebox.showwarning(
'',
'No stage selected.')
549 top=self.winfo_toplevel()
550 old_cursor = top[
'cursor']
552 top[
'cursor'] =
'watch'
553 top.update_idletasks()
555 top[
'cursor'] = old_cursor
557 top[
'cursor'] = old_cursor
559 traceback.print_tb(e[2])
560 tkinter_messagebox.showerror(
'', e[1])
561 self.project_view.update_status()
567 tkinter_messagebox.showwarning(
'',
'No project selected.')
570 tkinter_messagebox.showwarning(
'',
'No stage selected.')
572 top=self.winfo_toplevel()
573 old_cursor = top[
'cursor']
575 top[
'cursor'] =
'watch'
576 top.update_idletasks()
579 top[
'cursor'] = old_cursor
581 top[
'cursor'] = old_cursor
583 traceback.print_tb(e[2])
584 tkinter_messagebox.showerror(
'', e[1])
585 self.project_view.update_status()
591 tkinter_messagebox.showwarning(
'',
'No project selected.')
594 tkinter_messagebox.showwarning(
'',
'No stage selected.')
597 top=self.winfo_toplevel()
598 old_cursor = top[
'cursor']
600 top[
'cursor'] =
'watch'
601 top.update_idletasks()
603 recur=self.current_stage_def.recur)
604 top[
'cursor'] = old_cursor
606 top[
'cursor'] = old_cursor
608 traceback.print_tb(e[2])
609 tkinter_messagebox.showerror(
'', e[1])
610 BatchStatus.update_jobs()
611 self.project_view.update_status()
617 tkinter_messagebox.showwarning(
'',
'No project selected.')
620 tkinter_messagebox.showwarning(
'',
'No stage selected.')
623 top=self.winfo_toplevel()
624 old_cursor = top[
'cursor']
626 top[
'cursor'] =
'watch'
627 top.update_idletasks()
629 recur=self.current_stage_def.recur)
630 top[
'cursor'] = old_cursor
632 top[
'cursor'] = old_cursor
634 traceback.print_tb(e[2])
635 tkinter_messagebox.showerror(
'', e[1])
636 BatchStatus.update_jobs()
637 self.project_view.update_status()
642 self.project_view.update_jobs()
648 tkinter_messagebox.showwarning(
'',
'No project selected.')
651 tkinter_messagebox.showwarning(
'',
'No stage selected.')
654 top=self.winfo_toplevel()
655 old_cursor = top[
'cursor']
657 top[
'cursor'] =
'watch'
658 top.update_idletasks()
659 BatchStatus.update_jobs()
660 jobs = BatchStatus.get_jobs()
661 top[
'cursor'] = old_cursor
663 top[
'cursor'] = old_cursor
665 traceback.print_tb(e[2])
666 tkinter_messagebox.showerror(
'', e[1])
676 workscript =
'%s-%s-%s.sh' % (self.current_stage_def.name,
677 self.current_project_def.name,
678 self.current_project_def.release_tag)
679 if script.find(workscript) == 0:
680 cp_server = jobid.split(
'@')
681 if len(cp_server) == 2:
682 clusproc = cp_server[0]
683 server = cp_server[1]
684 cp = clusproc.split(
'.')
688 cluster_id =
'%s@%s' % (cluster, server)
689 if not cluster_id
in cluster_ids:
690 cluster_ids.add(cluster_id)
694 for cluster_id
in cluster_ids:
695 print(
'Kill cluster id %s' % cluster_id)
696 command = [
'jobsub_rm']
697 if self.current_project_def.server !=
'-' and self.current_project_def.server !=
'':
698 command.append(
'--jobsub-server=%s' % self.current_project_def.server)
699 command.append(
'--jobid=%s' % cluster_id)
700 command.append(
'--role=%s' % project_utilities.get_role())
701 jobinfo = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
702 jobout, joberr = jobinfo.communicate()
707 raise JobsubError(command, rc, jobout, joberr)
716 tkinter_messagebox.showwarning(
'',
'No project selected.')
719 tkinter_messagebox.showwarning(
'',
'No stage selected.')
721 top=self.winfo_toplevel()
722 old_cursor = top[
'cursor']
724 top[
'cursor'] =
'watch'
725 top.update_idletasks()
727 top[
'cursor'] = old_cursor
729 top[
'cursor'] = old_cursor
731 traceback.print_tb(e[2])
732 tkinter_messagebox.showerror(
'', e[1])
738 tkinter_messagebox.showwarning(
'',
'No project selected.')
741 tkinter_messagebox.showwarning(
'',
'No stage selected.')
743 top=self.winfo_toplevel()
744 old_cursor = top[
'cursor']
746 top[
'cursor'] =
'watch'
747 top.update_idletasks()
749 top[
'cursor'] = old_cursor
751 top[
'cursor'] = old_cursor
753 traceback.print_tb(e[2])
754 tkinter_messagebox.showerror(
'', e[1])
760 tkinter_messagebox.showwarning(
'',
'No project selected.')
763 tkinter_messagebox.showwarning(
'',
'No stage selected.')
765 top=self.winfo_toplevel()
766 old_cursor = top[
'cursor']
768 top[
'cursor'] =
'watch'
769 top.update_idletasks()
771 top[
'cursor'] = old_cursor
773 top[
'cursor'] = old_cursor
775 traceback.print_tb(e[2])
776 tkinter_messagebox.showerror(
'', e[1])
782 tkinter_messagebox.showwarning(
'',
'No project selected.')
785 tkinter_messagebox.showwarning(
'',
'No stage selected.')
787 top=self.winfo_toplevel()
788 old_cursor = top[
'cursor']
790 top[
'cursor'] =
'watch'
791 top.update_idletasks()
793 self.current_stage_def.outdir, declare=
True, ana=ana)
794 top[
'cursor'] = old_cursor
796 top[
'cursor'] = old_cursor
798 traceback.print_tb(e[2])
799 tkinter_messagebox.showerror(
'', e[1])
810 tkinter_messagebox.showwarning(
'',
'No project selected.')
813 tkinter_messagebox.showwarning(
'',
'No stage selected.')
815 top=self.winfo_toplevel()
816 old_cursor = top[
'cursor']
818 top[
'cursor'] =
'watch'
819 top.update_idletasks()
821 self.current_stage_def.outdir, declare=
False, ana=ana)
822 top[
'cursor'] = old_cursor
824 top[
'cursor'] = old_cursor
826 traceback.print_tb(e[2])
827 tkinter_messagebox.showerror(
'', e[1])
838 tkinter_messagebox.showwarning(
'',
'No project selected.')
841 tkinter_messagebox.showwarning(
'',
'No stage selected.')
843 top=self.winfo_toplevel()
844 old_cursor = top[
'cursor']
846 top[
'cursor'] =
'watch'
847 top.update_idletasks()
852 top[
'cursor'] = old_cursor
854 top[
'cursor'] = old_cursor
856 traceback.print_tb(e[2])
857 tkinter_messagebox.showerror(
'', e[1])
868 tkinter_messagebox.showwarning(
'',
'No project selected.')
871 tkinter_messagebox.showwarning(
'',
'No stage selected.')
873 top=self.winfo_toplevel()
874 old_cursor = top[
'cursor']
878 defname = self.current_stage_def.ana_defname
880 defname = self.current_stage_def.defname
883 top[
'cursor'] =
'watch'
884 top.update_idletasks()
889 top[
'cursor'] = old_cursor
891 top[
'cursor'] = old_cursor
893 traceback.print_tb(e[2])
894 tkinter_messagebox.showerror(
'', e[1])
905 tkinter_messagebox.showwarning(
'',
'No project selected.')
908 tkinter_messagebox.showwarning(
'',
'No stage selected.')
910 top=self.winfo_toplevel()
911 old_cursor = top[
'cursor']
915 defname = self.current_stage_def.ana_defname
917 defname = self.current_stage_def.defname
920 top[
'cursor'] =
'watch'
921 top.update_idletasks()
926 top[
'cursor'] = old_cursor
928 top[
'cursor'] = old_cursor
930 traceback.print_tb(e[2])
931 tkinter_messagebox.showerror(
'', e[1])
942 tkinter_messagebox.showwarning(
'',
'No project selected.')
945 tkinter_messagebox.showwarning(
'',
'No stage selected.')
950 defname = self.current_stage_def.ana_defname
952 defname = self.current_stage_def.defname
954 tkinter_messagebox.showwarning(
'No sam dataset definition specified.')
957 top=self.winfo_toplevel()
958 old_cursor = top[
'cursor']
960 top[
'cursor'] =
'watch'
961 top.update_idletasks()
963 top[
'cursor'] = old_cursor
965 top[
'cursor'] = old_cursor
967 traceback.print_tb(e[2])
968 tkinter_messagebox.showerror(
'', e[1])
979 tkinter_messagebox.showwarning(
'',
'No project selected.')
982 tkinter_messagebox.showwarning(
'',
'No stage selected.')
984 top=self.winfo_toplevel()
985 old_cursor = top[
'cursor']
987 top[
'cursor'] =
'watch'
988 top.update_idletasks()
997 top[
'cursor'] = old_cursor
999 top[
'cursor'] = old_cursor
1001 traceback.print_tb(e[2])
1002 tkinter_messagebox.showerror(
'', e[1])
1013 tkinter_messagebox.showwarning(
'',
'No project selected.')
1016 tkinter_messagebox.showwarning(
'',
'No stage selected.')
1018 top=self.winfo_toplevel()
1019 old_cursor = top[
'cursor']
1021 top[
'cursor'] =
'watch'
1022 top.update_idletasks()
1027 top[
'cursor'] = old_cursor
1029 top[
'cursor'] = old_cursor
1031 traceback.print_tb(e[2])
1032 tkinter_messagebox.showerror(
'', e[1])
1043 tkinter_messagebox.showwarning(
'',
'No project selected.')
1046 tkinter_messagebox.showwarning(
'',
'No stage selected.')
1048 top=self.winfo_toplevel()
1049 old_cursor = top[
'cursor']
1051 top[
'cursor'] =
'watch'
1052 top.update_idletasks()
1061 top[
'cursor'] = old_cursor
1063 top[
'cursor'] = old_cursor
1065 traceback.print_tb(e[2])
1066 tkinter_messagebox.showerror(
'', e[1])
1077 tkinter_messagebox.showwarning(
'',
'No project selected.')
1080 tkinter_messagebox.showwarning(
'',
'No stage selected.')
1082 top=self.winfo_toplevel()
1083 old_cursor = top[
'cursor']
1085 top[
'cursor'] =
'watch'
1086 top.update_idletasks()
1095 top[
'cursor'] = old_cursor
1097 top[
'cursor'] = old_cursor
1099 traceback.print_tb(e[2])
1100 tkinter_messagebox.showerror(
'', e[1])
1111 tkinter_messagebox.showwarning(
'',
'No project selected.')
1114 tkinter_messagebox.showwarning(
'',
'No stage selected.')
1116 top=self.winfo_toplevel()
1117 old_cursor = top[
'cursor']
1119 top[
'cursor'] =
'watch'
1120 top.update_idletasks()
1129 top[
'cursor'] = old_cursor
1131 top[
'cursor'] = old_cursor
1133 traceback.print_tb(e[2])
1134 tkinter_messagebox.showerror(
'', e[1])
1145 tkinter_messagebox.showwarning(
'',
'No project selected.')
1148 tkinter_messagebox.showwarning(
'',
'No stage selected.')
1150 top=self.winfo_toplevel()
1151 old_cursor = top[
'cursor']
1153 top[
'cursor'] =
'watch'
1154 top.update_idletasks()
1163 top[
'cursor'] = old_cursor
1165 top[
'cursor'] = old_cursor
1167 traceback.print_tb(e[2])
1168 tkinter_messagebox.showerror(
'', e[1])
1179 tkinter_messagebox.showwarning(
'',
'No project selected.')
1182 tkinter_messagebox.showwarning(
'',
'No stage selected.')
1184 top=self.winfo_toplevel()
1185 old_cursor = top[
'cursor']
1187 top[
'cursor'] =
'watch'
1188 top.update_idletasks()
1190 top[
'cursor'] = old_cursor
1192 top[
'cursor'] = old_cursor
1194 traceback.print_tb(e[2])
1195 tkinter_messagebox.showerror(
'', e[1])
1205 command = [
'project.py',
'--help']
1206 helptext =
convert_str(subprocess.check_output(command))
1218 command = [
'project.py',
'--xmlhelp']
1219 helptext =
convert_str(subprocess.check_output(command))
def test_ana_declarations
do one_file $F done echo for F in find $TOP name CMakeLists txt print
def previous_stage_handler
def previous_project_handler
def check_ana_declarations