itkdb-gtk 0.10.9.dev4__py3-none-any.whl → 0.10.10__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of itkdb-gtk might be problematic. Click here for more details.

@@ -21,7 +21,6 @@ import gi
21
21
  gi.require_version("Gtk", "3.0")
22
22
  from gi.repository import Gtk, Gdk, Gio, GObject
23
23
 
24
- HELP_LINK="https://itkdb-gtk.docs.cern.ch/panelVisualInspection.html"
25
24
 
26
25
  class TestJson(GObject.Object):
27
26
  """To store test JSOn."""
@@ -41,13 +40,13 @@ class PanelVisualInspection(dbGtkUtils.ITkDBWindow):
41
40
  SN, ORDER, PASSED, N_FILES, F_LIST, TEST_J, ALL = range(7)
42
41
  F_DEFECT, F_NAME, F_PATH = range(3)
43
42
 
44
- def __init__(self, session, title="PanelVisualInspection", help_link=HELP_LINK):
43
+ def __init__(self, session, title="PanelVisualInspection", help_link=None):
45
44
  super().__init__(title=title,
46
45
  session=session,
47
46
  show_search="Find object with given SN.",
48
47
  help_link=help_link)
49
48
 
50
- self.institute = "IFIC"
49
+ self.institute = self.pdb_user["institutions"][0]["code"]
51
50
  self.global_image = None
52
51
  self.global_link = None
53
52
 
@@ -64,7 +63,7 @@ class PanelVisualInspection(dbGtkUtils.ITkDBWindow):
64
63
  self.mainBox.pack_start(grid, False, False, 5)
65
64
 
66
65
  irow = 0
67
- receiver = self.create_institute_combo()
66
+ receiver = self.create_institute_combo(only_user=True)
68
67
  receiver.connect("changed", self.on_institute)
69
68
  receiver.set_tooltip_text("Select the Institute making the test.")
70
69
  dbGtkUtils.set_combo_iter(receiver, self.institute)
@@ -511,7 +510,7 @@ class PanelVisualInspection(dbGtkUtils.ITkDBWindow):
511
510
  ipos = rc.find("The following details may help:")
512
511
  msg = rc[ipos:]
513
512
  dbGtkUtils.complain("Failed uploading test {}-{}".format(payload["component"], payload["testType"]), msg)
514
- self.write_message(msg)
513
+ self.write_message(msg+"\n")
515
514
 
516
515
  else:
517
516
  self.write_message("Upload {}-{} successfull\n".format(payload["component"], payload["testType"]))
@@ -525,15 +524,16 @@ class PanelVisualInspection(dbGtkUtils.ITkDBWindow):
525
524
  rc = ITkDButils.set_test_run_parameter(self.session,
526
525
  ITkDButils.uploaded_test_runs[0],
527
526
  "COMMENT", "Picture of PW carrier")
528
-
527
+
529
528
  rc = ITkDButils.set_test_run_parameter(self.session,
530
529
  ITkDButils.uploaded_test_runs[0],
531
530
  "LINK_TO_PICTURE", global_link)
532
531
  if rc:
533
532
  ipos = rc.find("The following details may help:")
534
533
  msg = rc[ipos:]
535
- dbGtkUtils.complain("Failed updating LINK_TO_PICTURE {}-{}".format(payload["component"], payload["testType"]), msg)
536
- self.write_message(msg)
534
+ dbGtkUtils.complain("Failed updating LINK_TO_PICTURE {}-{}".format(payload["component"],
535
+ payload["testType"]), msg)
536
+ self.write_message(msg+'\n')
537
537
 
538
538
  elif payload["testType"] == "VISUAL_INSPECTION_RECEPTION":
539
539
  rc = ITkDButils.create_test_run_comment(self.session,
@@ -542,8 +542,11 @@ class PanelVisualInspection(dbGtkUtils.ITkDBWindow):
542
542
  if rc:
543
543
  ipos = rc.find("The following details may help:")
544
544
  msg = rc[ipos:]
545
- dbGtkUtils.complain("Failed adding global link as comment: {}-{}".format(payload["component"], payload["testType"]), msg)
546
- self.write_message(msg)
545
+ dbGtkUtils.complain("Failed adding global link as comment: {}-{}".format(payload["component"],
546
+ payload["testType"]), msg)
547
+ self.write_message(msg+"\n")
548
+ else:
549
+ self.write_message("Image: {}\n".format(global_link))
547
550
 
548
551
 
549
552
  n_items += 1
@@ -560,6 +563,8 @@ class PanelVisualInspection(dbGtkUtils.ITkDBWindow):
560
563
  def main():
561
564
  """Main entry."""
562
565
  # DB login
566
+ HELP_LINK="https://itkdb-gtk.docs.cern.ch/panelVisualInspection.html"
567
+
563
568
  dlg = ITkDBlogin.ITkDBlogin()
564
569
  client = dlg.get_client()
565
570
  if client is None:
@@ -569,7 +574,7 @@ def main():
569
574
 
570
575
  client.user_gui = dlg
571
576
 
572
- gTest = PanelVisualInspection(client)
577
+ gTest = PanelVisualInspection(client, help_link=HELP_LINK)
573
578
 
574
579
  gTest.present()
575
580
  gTest.connect("destroy", Gtk.main_quit)
@@ -40,7 +40,7 @@ class PetalReceptionTests(dbGtkUtils.ITkDBWindow):
40
40
 
41
41
  def __init__(self, session, help_link=None):
42
42
  """Initialization."""
43
- super().__init__(title="ITkDB Dashboard",
43
+ super().__init__(title="Petal Reception Tests",
44
44
  session=session,
45
45
  show_search="Find object with given SN.",
46
46
  help_link=help_link)
@@ -83,8 +83,8 @@ class PetalReceptionTests(dbGtkUtils.ITkDBWindow):
83
83
  lbl.set_xalign(0)
84
84
  grid.attach(lbl, 0, 1, 1, 1)
85
85
 
86
- self.institute = "IFIC"
87
- inst = self.create_institute_combo()
86
+ self.institute = self.pdb_user["institutions"][0]["code"]
87
+ inst = self.create_institute_combo(only_user=True)
88
88
  inst.connect("changed", self.new_institute)
89
89
  inst.set_tooltip_text("Select the Institute.")
90
90
  grid.attach(inst, 1, 1, 1, 1)
@@ -114,6 +114,10 @@ class PetalReceptionTests(dbGtkUtils.ITkDBWindow):
114
114
  # The text view
115
115
  self.mainBox.pack_end(self.message_panel.frame, True, True, 5)
116
116
 
117
+ # Set the default institute
118
+ dbGtkUtils.set_combo_iter(inst, self.institute)
119
+
120
+
117
121
  self.show_all()
118
122
 
119
123
  def on_SN_changed(self, entry, value):
@@ -139,7 +143,7 @@ class PetalReceptionTests(dbGtkUtils.ITkDBWindow):
139
143
  page.dict_dialog.factory_reset()
140
144
 
141
145
 
142
- def create_test_box(self, label, test_name, institute="IFIC"):
146
+ def create_test_box(self, label, test_name, institute=None):
143
147
  """Create and add to notebook a test dialog.
144
148
 
145
149
  Args:
@@ -148,6 +152,9 @@ class PetalReceptionTests(dbGtkUtils.ITkDBWindow):
148
152
  institute: The institute.
149
153
 
150
154
  """
155
+ if institute is None:
156
+ institute = self.institute
157
+
151
158
  defaults = {
152
159
  "institution": institute,
153
160
  "runNumber": "1",
@@ -180,7 +187,7 @@ class PetalReceptionTests(dbGtkUtils.ITkDBWindow):
180
187
  self.dbObject = ITkDButils.get_DB_component(self.session, SN)
181
188
 
182
189
  except Exception as E:
183
- self.write_message(str(E))
190
+ self.write_message(str(E)+'\n')
184
191
  dbGtkUtils.complain("Could not find object in DB", str(E))
185
192
  self.dbObject = None
186
193
  return
@@ -191,7 +198,7 @@ class PetalReceptionTests(dbGtkUtils.ITkDBWindow):
191
198
  """Add a new defect."""
192
199
  page = self.notebook.get_nth_page(self.notebook.get_current_page())
193
200
  values = dbGtkUtils.get_a_list_of_values("Insert new defect", ("Type", "Description/v"))
194
- if len(values):
201
+ if len(values)>0:
195
202
  defect = {"name": values[0], "description": values[1]}
196
203
  page.dict_dialog.values["defects"].append(defect)
197
204
  page.dict_dialog.refresh()
@@ -273,6 +280,8 @@ class PetalReceptionTests(dbGtkUtils.ITkDBWindow):
273
280
  def main():
274
281
  """Main entry."""
275
282
  # DB login
283
+ HELP_LINK="https://itkdb-gtk.docs.cern.ch/petalReceptionTests.html"
284
+
276
285
  dlg = ITkDBlogin.ITkDBlogin()
277
286
  client = dlg.get_client()
278
287
  if client is None:
@@ -282,7 +291,7 @@ def main():
282
291
 
283
292
  client.user_gui = dlg
284
293
 
285
- gTest = PetalReceptionTests(client)
294
+ gTest = PetalReceptionTests(client, help_link=HELP_LINK)
286
295
 
287
296
  gTest.present()
288
297
  gTest.connect("destroy", Gtk.main_quit)
@@ -1,6 +1,5 @@
1
1
  #!/usr/bin/env python3
2
2
  """GUI to upload tests."""
3
- import argparse
4
3
  import fnmatch
5
4
  import json
6
5
  import os
@@ -64,7 +63,26 @@ def all_files(root, patterns='*', single_level=False, yield_folders=False):
64
63
 
65
64
 
66
65
  class TestList(object):
67
- SN, TestType, RunNumber, Date, Institute, Stage, currentStage, Path, Json, Nattch, Attachments, Ncomm, Comments, Ndef, Defects, ALL = range(16)
66
+ """Enumeration with TreeView model columns."""
67
+ (
68
+ SN,
69
+ TestType,
70
+ RunNumber,
71
+ Date,
72
+ Institute,
73
+ Stage,
74
+ currentStage,
75
+ Path,
76
+ Json,
77
+ Nattch,
78
+ Attachments,
79
+ Ncomm,
80
+ Comments,
81
+ Ndef,
82
+ Defects,
83
+ Color,
84
+ ALL,
85
+ ) = range(17)
68
86
 
69
87
 
70
88
  def check_data(data):
@@ -113,6 +131,7 @@ class UploadMultipleTests(dbGtkUtils.ITkDBWindow):
113
131
  self.tests = []
114
132
  self.data = None
115
133
  self.tree = None
134
+ self.def_color = None
116
135
 
117
136
  self.init_window()
118
137
 
@@ -174,7 +193,23 @@ class UploadMultipleTests(dbGtkUtils.ITkDBWindow):
174
193
 
175
194
  def create_tree_view(self, size=150):
176
195
  """Creates the tree vew with the attachments."""
177
- model = Gtk.ListStore(str, str, str, str, str, str, str, str, object, int, object, int, object, int, object)
196
+ model = Gtk.ListStore(str, # SN
197
+ str, # test type
198
+ str, # runNumber
199
+ str, # date
200
+ str, # institute
201
+ str, # stage
202
+ str, # stage
203
+ str, # ifile
204
+ object, # data
205
+ int, # num. attch.
206
+ object, # attachments
207
+ int, # num. comments
208
+ object, # comments
209
+ int, # num defects
210
+ object, # defects
211
+ str # color
212
+ )
178
213
  self.tree = Gtk.TreeView(model=model)
179
214
  self.tree.connect("button-press-event", self.button_pressed)
180
215
  scrolled = Gtk.ScrolledWindow()
@@ -187,7 +222,8 @@ class UploadMultipleTests(dbGtkUtils.ITkDBWindow):
187
222
  self.tree.append_column(column)
188
223
 
189
224
  renderer = Gtk.CellRendererText()
190
- column = Gtk.TreeViewColumn("Test Type", renderer, text=TestList.TestType)
225
+ self.def_color = renderer.get_property("foreground-rgba").to_string()
226
+ column = Gtk.TreeViewColumn("Test Type", renderer, text=TestList.TestType, foreground=TestList.Color)
191
227
  self.tree.append_column(column)
192
228
 
193
229
  renderer = Gtk.CellRendererText()
@@ -376,7 +412,7 @@ class UploadMultipleTests(dbGtkUtils.ITkDBWindow):
376
412
  """Set the test stage."""
377
413
  model, lv_iter, val = data
378
414
  SN = val[TestList.SN]
379
- combo, currentStage = self.get_component_stages(SN)
415
+ combo, _ = self.get_component_stages(SN)
380
416
 
381
417
  dlg = Gtk.Dialog(title="Add Attachment")
382
418
 
@@ -429,68 +465,84 @@ class UploadMultipleTests(dbGtkUtils.ITkDBWindow):
429
465
  return combo, currentStage
430
466
 
431
467
  except Exception:
432
- self.write_message("Something went wring with the stages")
468
+ self.write_message("Something went wrong with the stages\n")
433
469
  return [None, None]
434
470
 
471
+ def add_test_data_to_view(self, data, ifile=None, folder=None):
472
+ """Add a test data to the tree view."""
473
+ has_errors = False
474
+ default_site = None
475
+
476
+ errors, missing = check_data(data)
477
+ if len(missing) > 0:
478
+ self.write_message("Some keys are missing in the JSon file.\n")
479
+ self.write_message("{}\n".format("\n".join(['\t'+line for line in missing])))
480
+
481
+ if "institution" in missing and len(missing) == 1:
482
+ if default_site is None:
483
+ site, use_default = self.get_test_institute()
484
+ if use_default:
485
+ default_site = site
486
+ else:
487
+ site = default_site
488
+
489
+ if site:
490
+ data["institution"] = site
491
+ self.write_message("Setting Institution to {}\n".format(data["institution"]))
492
+
493
+ else:
494
+ has_errors = True
495
+ dbGtkUtils.complain("Invalid JSON file\n{}".format('\n'.join(errors)),"--")
496
+
497
+ if not has_errors:
498
+ attachments = []
499
+ if "attachments" in data:
500
+ for att in data["attachments"]:
501
+ path = Path(att["path"])
502
+ if path.exists():
503
+ path = path.expanduser().resolve()
504
+ else:
505
+ if folder is not None:
506
+ path = folder / path.name
507
+
508
+ if path.exists():
509
+ attachments.append(ITkDButils.Attachment(path=path,
510
+ title=att["title"],
511
+ desc=att["description"]))
512
+ else:
513
+ self.write_message("Ignoring atachment {}".format(data["path"]))
514
+
515
+ # We need to delete this, which is "unofficial"
516
+ del data["attachments"]
517
+
518
+ model = self.tree.get_model()
519
+ comments = data.get("comments", [])
520
+ defects = data.get("defects", [])
521
+ the_date = handle_test_date(data["date"])
522
+ combo, currentStage = self.get_component_stages(data["component"])
523
+ if data["passed"]:
524
+ if data["problems"]:
525
+ color = "orange"
526
+ else:
527
+ color = self.def_color
528
+ else:
529
+ color = "firebrick"
530
+
531
+ model.append([data["component"], data["testType"], data["runNumber"], the_date,
532
+ data["institution"], currentStage, currentStage,
533
+ ifile, data, len(attachments), attachments,
534
+ len(comments), comments, len(defects), defects, color])
535
+
435
536
  def add_tests_to_view(self, files):
436
537
  """Add the input fiels to the treeview."""
437
- default_site = None
438
538
  for ifile in files:
439
539
  try:
440
- has_errors = False
540
+ self.write_message("{}\n".format(Path(ifile).name))
541
+ folder = Path(ifile).parent
542
+
441
543
  data = json.loads(open(ifile, 'r', encoding="UTF-8").read())
442
- errors, missing = check_data(data)
443
- if len(missing) > 0:
444
- self.write_message("{}\n".format(Path(ifile).name))
445
- self.write_message("Some keys are missing in the JSon file.\n")
446
- self.write_message("{}\n".format("\n".join(['\t'+line for line in missing])))
447
-
448
- if "institution" in missing and len(missing) == 1:
449
- if default_site is None:
450
- site, use_default = self.get_test_institute()
451
- if use_default:
452
- default_site = site
453
- else:
454
- site = default_site
455
-
456
- if site:
457
- data["institution"] = site
458
- self.write_message("Setting Institution to {}\n".format(data["institution"]))
544
+ self.add_test_data_to_view(data, ifile=ifile, folder=folder)
459
545
 
460
- else:
461
- has_errors = True
462
- dbGtkUtils.complain("Invalid JSON file\n{}".format('\n'.join(errors)), ifile)
463
-
464
- if not has_errors:
465
- attachments = []
466
- if "attachments" in data:
467
- folder = Path(ifile).parent
468
- for att in data["attachments"]:
469
- path = Path(att["path"])
470
- if path.exists():
471
- path = path.expanduser().resolve()
472
- else:
473
- path = folder / path.name
474
-
475
- if path.exists():
476
- attachments.append(ITkDButils.Attachment(path=path,
477
- title=att["title"],
478
- desc=att["description"]))
479
- else:
480
- self.write_message("Ignoring atachment {}".format(data["path"]))
481
-
482
- # We need to delete tis, which is "unofficial"
483
- del data["attachments"]
484
-
485
- model = self.tree.get_model()
486
- comments = data.get("comments", [])
487
- defects = data.get("defects", [])
488
- the_date = handle_test_date(data["date"])
489
- combo, currentStage = self.get_component_stages(data["component"])
490
- model.append([data["component"], data["testType"], data["runNumber"], the_date,
491
- data["institution"], currentStage, currentStage,
492
- ifile, data, len(attachments), attachments,
493
- len(comments), comments, len(defects), defects])
494
546
 
495
547
  except Exception as E:
496
548
  self.write_message("Cannot load file {}\n".format(ifile))
@@ -600,6 +652,8 @@ class UploadMultipleTests(dbGtkUtils.ITkDBWindow):
600
652
  """Uploads tests and attachments."""
601
653
  model = self.tree.get_model()
602
654
  lv_iter = model.get_iter_first()
655
+ ngood = 0
656
+ nbad = 0
603
657
  while lv_iter:
604
658
  past_iter = None
605
659
  values = model[lv_iter]
@@ -611,20 +665,28 @@ class UploadMultipleTests(dbGtkUtils.ITkDBWindow):
611
665
  if rc:
612
666
  ipos = rc.find("The following details may help:")
613
667
  msg = rc[ipos:]
614
- dbGtkUtils.complain("Failed uploading test {}-{}".format(payload["component"], payload["testType"]), msg)
615
- self.write_message(msg)
668
+ dbGtkUtils.complain("Failed uploading test {}-{}".format(payload["component"], payload["testType"]))
669
+ self.write_message("Failed uploading test {}-{}\n{}\n".format(payload["component"], payload["testType"], msg))
670
+ nbad += 1
616
671
 
617
672
  else:
618
673
  self.write_message("Upload {}-{} successfull\n".format(payload["component"], payload["testType"]))
619
674
  past_iter = lv_iter
675
+ ngood += 1
620
676
 
621
677
  lv_iter = model.iter_next(lv_iter)
622
678
  if past_iter:
623
679
  model.remove(past_iter)
624
680
 
681
+ if nbad>0:
682
+ dbGtkUtils.complain("Failed to upload all tests", "{} test had errors.\nThey are left in the ListView.")
683
+ else:
684
+ dbGtkUtils.complain("All {} tests uploaded succesfully".format(ngood))
685
+
625
686
 
626
687
  def main():
627
- """Main entry."""
688
+ """Main entry."""
689
+ HELP_LINK="https://itkdb-gtk.docs.cern.ch/uploadMultipleTests.html"
628
690
  # DB login
629
691
  dlg = ITkDBlogin.ITkDBlogin()
630
692
  client = dlg.get_client()
@@ -636,7 +698,7 @@ def main():
636
698
  client.user_gui = dlg
637
699
 
638
700
  # Start GUI
639
- UpT = UploadMultipleTests(client)
701
+ UpT = UploadMultipleTests(client, help_link=HELP_LINK)
640
702
 
641
703
  if gtk_runs:
642
704
  UpT.present()
itkdb_gtk/UploadTest.py CHANGED
@@ -9,7 +9,6 @@ try:
9
9
  import itkdb_gtk
10
10
 
11
11
  except ImportError:
12
- from pathlib import Path
13
12
  cwd = Path(__file__).parent.parent
14
13
  sys.path.append(cwd.as_posix())
15
14
 
@@ -93,6 +92,7 @@ class UploadTest(dbGtkUtils.ITkDBWindow):
93
92
  self.attachments = []
94
93
  self.comments = []
95
94
  self.defects = []
95
+ self.currentStage = None
96
96
  if attachment is not None:
97
97
  if isinstance(attachment, ITkDButils.Attachment):
98
98
  if attachment.path is not None:
@@ -211,14 +211,15 @@ class UploadTest(dbGtkUtils.ITkDBWindow):
211
211
  ifile = Path(self.payload).expanduser().resolve().as_posix()
212
212
  self.testF.set_filename(ifile)
213
213
  self.on_test_file(self.testF)
214
- self.write_message("Loaded {}".format(the_path.name))
214
+ self.write_message("Loaded {}\n".format(the_path.name))
215
215
 
216
216
  else:
217
217
  print("Input file does not exists: {}".format(self.payload))
218
218
 
219
219
  except TypeError:
220
220
  self.load_payload(self.payload)
221
- self.write_message("Loaded memory payload.")
221
+ self.write_message("Loaded memory payload.\n")
222
+ self.testF.set_sensitive(False)
222
223
 
223
224
  if len(self.attachments) > 0:
224
225
  self.btn_attch.set_label("Attachments ({})".format(len(self.attachments)))
@@ -293,7 +294,7 @@ class UploadTest(dbGtkUtils.ITkDBWindow):
293
294
  self.objStage.set_active(indx)
294
295
 
295
296
  except Exception:
296
- self.write_message("Something went wring with the stages")
297
+ self.write_message("Something went wrong with the stages\n")
297
298
 
298
299
 
299
300
  def on_test_file(self, fdlg):
@@ -303,7 +304,7 @@ class UploadTest(dbGtkUtils.ITkDBWindow):
303
304
 
304
305
  # The file exists by definition
305
306
  try:
306
- self.data = json.loads(open(fnam).read())
307
+ self.data = json.loads(open(fnam, encoding="UTF-8").read())
307
308
  errors, missing = check_data(self.data)
308
309
  self.complete_missing(missing, errors)
309
310
  self.set_stages()
@@ -326,7 +327,7 @@ class UploadTest(dbGtkUtils.ITkDBWindow):
326
327
  self.write_message("Setting Institution to {}\n".format(self.data["institution"]))
327
328
 
328
329
  else:
329
- dbGtkUtils.complain("Invalid JSON data".format('\n'.join(errors)))
330
+ dbGtkUtils.complain("Invalid JSON data\n{}".format('\n'.join(errors)))
330
331
 
331
332
  self.find_attachments()
332
333
  self.find_comments()
@@ -451,12 +452,13 @@ class UploadTest(dbGtkUtils.ITkDBWindow):
451
452
  dbGtkUtils.complain("Failed uploading test", msg)
452
453
 
453
454
  else:
454
- self.write_message("Upload successfull")
455
+ self.write_message("Upload successfull\n")
455
456
  dbGtkUtils.ask_for_confirmation("Upload successfull", "")
456
457
 
457
458
 
458
459
  def main():
459
460
  """Main entry."""
461
+ HELP_LINK="https://itkdb-gtk.docs.cern.ch/uploadSingleTest.html"
460
462
  parser = argparse.ArgumentParser()
461
463
 
462
464
  parser.add_argument("--test-file", help="Name of json file with test data")
@@ -482,6 +484,7 @@ def main():
482
484
  # Start GUI
483
485
  UpT = UploadTest(client,
484
486
  payload=args.test_file,
487
+ help_link=HELP_LINK,
485
488
  attachment=ITkDButils.Attachment(path=args.attachment,
486
489
  title=args.attach_title,
487
490
  desc=args.attach_desc))