itkdb-gtk 0.10.9.dev3__py3-none-any.whl → 0.10.10.dev1__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.

@@ -9,7 +9,7 @@ import re
9
9
 
10
10
  try:
11
11
  import itkdb_gtk
12
-
12
+
13
13
  except ImportError:
14
14
  from pathlib import Path
15
15
  cwd = Path(__file__).parent.parent
@@ -28,7 +28,7 @@ gtk_runs, gtk_args = Gtk.init_check()
28
28
  class CreateShipments(dbGtkUtils.ITkDBWindow):
29
29
  """Create a shipment from input."""
30
30
 
31
- def __init__(self, session, help=None):
31
+ def __init__(self, session, help_link=None):
32
32
  """Initialization.
33
33
 
34
34
  Args:
@@ -41,7 +41,8 @@ class CreateShipments(dbGtkUtils.ITkDBWindow):
41
41
  self.attachment = None
42
42
  global gtk_runs
43
43
  if gtk_runs:
44
- super().__init__(session=session, title="Upload AVS Data", help=help, gtk_runs=gtk_runs)
44
+ super().__init__(session=session, title="Upload AVS Data",
45
+ help_link=help_link, gtk_runs=gtk_runs)
45
46
  self.init_window()
46
47
 
47
48
  def init_window(self):
@@ -193,28 +194,28 @@ class CreateShipments(dbGtkUtils.ITkDBWindow):
193
194
  dbGtkUtils.complain("Item {} is already in transit".format(SN),
194
195
  "This item is already in transit to {}".format(rc['shipmentDestination']['code']))
195
196
  return
196
-
197
+
197
198
  nick = rc['alternativeIdentifier']
198
- id = rc['id']
199
+ obj_id = rc['id']
199
200
  obj = rc['componentType']['name']
200
201
  loc = rc['currentLocation']['code']
201
202
  serialN = rc['serialNumber']
202
203
  if serialN is None:
203
- serialN = id
204
+ serialN = obj_id
204
205
 
205
206
  # Check tha tthe input is not already there
206
207
  model = self.tree.get_model()
207
- iter = model.get_iter_first()
208
- while iter:
209
- if model.get_value(iter, 0) == SN:
208
+ lv_iter = model.get_iter_first()
209
+ while lv_iter:
210
+ if model.get_value(lv_iter, 0) == SN:
210
211
  dbGtkUtils.complain("Duplicated item.",
211
212
  "Object {} is already in the list".format(SN))
212
213
  return
213
214
 
214
- iter = model.iter_next(iter)
215
+ lv_iter = model.iter_next(lv_iter)
215
216
 
216
217
  # Add the item in the liststore.
217
- model.append([serialN, nick, obj, loc, id])
218
+ model.append([serialN, nick, obj, loc, obj_id])
218
219
 
219
220
  except Exception:
220
221
  dbGtkUtils.complain("Error querying DB",
@@ -224,12 +225,12 @@ class CreateShipments(dbGtkUtils.ITkDBWindow):
224
225
  def remove_item(self, *args):
225
226
  """Remove selected item."""
226
227
  select = self.tree.get_selection()
227
- model, iter = select.get_selected()
228
- if iter:
229
- values = model[iter]
228
+ model, lv_iter = select.get_selected()
229
+ if lv_iter:
230
+ values = model[lv_iter]
230
231
  rc = dbGtkUtils.ask_for_confirmation("Remove this items ?", values[0])
231
232
  if rc:
232
- model.remove(iter)
233
+ model.remove(lv_iter)
233
234
 
234
235
  def add_attachment_dialog(self):
235
236
  """Create the add attachment dialog."""
@@ -282,7 +283,7 @@ class CreateShipments(dbGtkUtils.ITkDBWindow):
282
283
 
283
284
  T = T if len(T) else None
284
285
  D = D if len(D) else None
285
- att = ITkDButils.Attachment(path, T, D)
286
+ att = ITkDButils.Attachment(path=path, title=T, desc=D)
286
287
  self.attachment = att
287
288
 
288
289
  dlg.hide()
@@ -309,16 +310,16 @@ class CreateShipments(dbGtkUtils.ITkDBWindow):
309
310
  def send_items(self, *args):
310
311
  """Send items in liststore."""
311
312
  model = self.tree.get_model()
312
- iter = model.get_iter_first()
313
+ lv_iter = model.get_iter_first()
313
314
  items = []
314
315
  senders = {}
315
- while iter:
316
- values = model[iter]
316
+ while lv_iter:
317
+ values = model[lv_iter]
317
318
  items.append(values[0])
318
319
  senders[values[3]] = senders.setdefault(values[3], 0) + 1
319
- iter = model.iter_next(iter)
320
+ lv_iter = model.iter_next(lv_iter)
320
321
 
321
- if len(items):
322
+ if len(items)>0:
322
323
  if len(senders) != 1:
323
324
  dbGtkUtils.complain("Too many senders.",
324
325
  "There are objects located in differen sites:{}".format('\n'.join(senders.keys())))
itkdb_gtk/GetShipments.py CHANGED
@@ -1,19 +1,17 @@
1
1
  #!/usr/bin/env python3
2
2
  """GEt shipments to a particular site (default is IFIC)."""
3
- import pathlib
4
3
  import sys
4
+ from pathlib import Path
5
5
 
6
6
  try:
7
7
  import itkdb_gtk
8
-
8
+
9
9
  except ImportError:
10
- from pathlib import Path
11
10
  cwd = Path(__file__).parent.parent
12
11
  sys.path.append(cwd.as_posix())
13
12
 
14
13
  from itkdb_gtk import dbGtkUtils, ITkDBlogin, ITkDButils
15
14
  import gi
16
- import serial
17
15
 
18
16
  gi.require_version("Gtk", "3.0")
19
17
  from gi.repository import Gtk, Gio, GLib
@@ -40,13 +38,13 @@ def find_vtrx(client, SN):
40
38
 
41
39
  if nitem > 1:
42
40
  raise ValueError("Too many VTRx with same device SN.")
43
-
44
- return vtrx
41
+
42
+ return vtrx
45
43
 
46
44
  class ReceiveShipments(dbGtkUtils.ITkDBWindow):
47
45
  """Find shipments related to given recipient."""
48
46
 
49
- def __init__(self, session, recipient="IFIC", help=None):
47
+ def __init__(self, session, recipient=None, help_link=None):
50
48
  """Initialization.
51
49
 
52
50
  Args:
@@ -54,20 +52,24 @@ class ReceiveShipments(dbGtkUtils.ITkDBWindow):
54
52
  recipient: default recipient
55
53
 
56
54
  """
57
- self.recipient = recipient
58
55
  self.state = "inTransit"
59
56
  self.institute = None
60
57
  self.model = None
61
58
  self.store = None
59
+ self.tree = None
62
60
  self.shipments = {}
63
61
 
64
62
  global gtk_runs
65
63
  if gtk_runs:
66
- super().__init__(session=session, title="Upload AVS Data",
64
+ super().__init__(session=session, title="Receive Shipments",
67
65
  show_search="Click to search shipments",
68
- gtk_runs=gtk_runs, help=help)
66
+ gtk_runs=gtk_runs, help_link=help_link)
69
67
 
68
+ self.recipient = self.pdb_user["institutions"][0]["code"]
70
69
  self.init_window()
70
+ else:
71
+ pdb_user = ITkDButils.get_db_user(session)
72
+ self.recipient = pdb_user["institutions"][0]["code"]
71
73
 
72
74
  def init_window(self):
73
75
  """Initialize window."""
@@ -189,31 +191,16 @@ class ReceiveShipments(dbGtkUtils.ITkDBWindow):
189
191
 
190
192
  # search code in the list
191
193
  if self.store:
192
- iter = self.store.get_iter_first()
193
- while iter:
194
- if (self.store.get_value(iter, 0) == txt):
194
+ lv_iter = self.store.get_iter_first()
195
+ while lv_iter:
196
+ if (self.store.get_value(lv_iter, 0) == txt):
195
197
  self.write_message("...found\n")
196
- self.store[iter][3] = False
198
+ self.store[lv_iter][3] = False
197
199
 
198
- iter = self.store.iter_next(iter)
200
+ lv_iter = self.store.iter_next(lv_iter)
199
201
 
200
202
  return True
201
203
 
202
- def get_institute_list(self):
203
- """Get the institute list."""
204
- sites = self.session.get("listInstitutions", json={})
205
- liststore = Gtk.ListStore(str, str)
206
- for site in sites:
207
- self.code2inst[site['code']] = site['name']
208
- self.inst2code[site['name']] = site['code']
209
- liststore.append([site["code"], site["code"]])
210
- liststore.append([site["name"], site["code"]])
211
-
212
- completion = Gtk.EntryCompletion()
213
- completion.set_model(liststore)
214
- completion.set_text_column(0)
215
- return completion
216
-
217
204
  def on_cell_toggled(self, widget, path):
218
205
  """A cell has been toggled."""
219
206
  model = self.tree.get_model()
@@ -234,9 +221,9 @@ class ReceiveShipments(dbGtkUtils.ITkDBWindow):
234
221
 
235
222
  # Store the model associated to this shipment.
236
223
  self.store = self.shipments[shpmnt]
237
- filter = self.store.filter_new()
238
- filter.set_visible_column(3)
239
- self.tree.set_model(filter)
224
+ sfilter = self.store.filter_new()
225
+ sfilter.set_visible_column(3)
226
+ self.tree.set_model(sfilter)
240
227
 
241
228
  def on_status_changed(self, combo):
242
229
  """Status changed."""
@@ -250,30 +237,12 @@ class ReceiveShipments(dbGtkUtils.ITkDBWindow):
250
237
 
251
238
  self.state = name
252
239
 
253
- def get_institute_from_combo(self, combo):
254
- """Get Institute from combo."""
255
- tree_iter = combo.get_active_iter()
256
- if tree_iter is not None:
257
- model = combo.get_model()
258
- name = model[tree_iter][1]
259
-
260
- else:
261
- name = combo.get_child().get_text()
262
- if name in self.inst2code:
263
- name = self.inst2code[name]
264
-
265
- elif name not in self.code2inst:
266
- name = None
267
-
268
- return name
269
-
270
240
  def on_receiver(self, combo):
271
241
  """Sets the recipient."""
272
242
  name = self.get_institute_from_combo(combo)
273
243
  if name:
274
244
  self.recipient = name
275
- hb = self.get_titlebar()
276
- hb.props.title = "{} shipments".format(self.recipient)
245
+ self.set_window_title("{} shipments".format(self.recipient))
277
246
 
278
247
  def on_institute(self, combo):
279
248
  """New institute chosen."""
@@ -291,8 +260,10 @@ class ReceiveShipments(dbGtkUtils.ITkDBWindow):
291
260
  return
292
261
 
293
262
  payload = {
294
- "code": self.recipient,
295
- "status": self.state
263
+ "filterMap": {
264
+ "code": self.recipient,
265
+ "status": self.state
266
+ }
296
267
  }
297
268
  shpmts = self.session.get("listShipmentsByInstitution", json=payload)
298
269
 
@@ -329,25 +300,25 @@ class ReceiveShipments(dbGtkUtils.ITkDBWindow):
329
300
 
330
301
  # self.store is the model of the tree view
331
302
  if self.store:
332
- iter = self.store.get_iter_first()
333
- while iter:
334
- shpmnt = self.store.get_value(iter, 2)
303
+ lv_iter = self.store.get_iter_first()
304
+ while lv_iter:
305
+ shpmnt = self.store.get_value(lv_iter, 2)
335
306
  if shpmnt not in data:
336
307
  data[shpmnt] = create_shipment_status(shpmnt)
337
- names[shpmnt] = self.store.get_value(iter, 4)
308
+ names[shpmnt] = self.store.get_value(lv_iter, 4)
338
309
 
339
310
  item = {
340
- "code": self.store[iter][5],
341
- "delivered": not self.store[iter][3]
311
+ "code": self.store[lv_iter][5],
312
+ "delivered": not self.store[lv_iter][3]
342
313
  }
343
314
  data[shpmnt]["shipmentItems"].append(item)
344
315
 
345
- iter = self.store.iter_next(iter)
316
+ lv_iter = self.store.iter_next(lv_iter)
346
317
 
347
318
  else:
348
319
  self.write_message("Empty list of items.\n")
349
320
 
350
- for id, S in data.items():
321
+ for oid, S in data.items():
351
322
  # Check that all items are there
352
323
  nlost = 0
353
324
  for item in S["shipmentItems"]:
@@ -366,7 +337,7 @@ class ReceiveShipments(dbGtkUtils.ITkDBWindow):
366
337
  return
367
338
 
368
339
  # Open dialog to fill-in questions
369
- create_check_list(S["checklist"]["questionList"], names[id])
340
+ create_check_list(S["checklist"]["questionList"], names[oid])
370
341
 
371
342
  # send the update to the DB
372
343
  S['status'] = "delivered"
@@ -382,10 +353,10 @@ class ReceiveShipments(dbGtkUtils.ITkDBWindow):
382
353
  self.write_message("Could not update the shipment status.\n{}\n".foramt(rc))
383
354
 
384
355
  else:
385
- self.write_message("Shipment {} received\n".format(names[id]))
356
+ self.write_message("Shipment {} received\n".format(names[oid]))
386
357
  # Now remove the current shipment
387
- iter = self.cmb_shipment.get_active_iter()
388
- self.cmb_shipment.get_model().remove(iter)
358
+ lv_iter = self.cmb_shipment.get_active_iter()
359
+ self.cmb_shipment.get_model().remove(lv_iter)
389
360
  self.cmb_shipment.set_active(0)
390
361
 
391
362
 
itkdb_gtk/GlueWeight.py CHANGED
@@ -86,7 +86,7 @@ def remove_defaul_keys(data, default_value=-9999):
86
86
  class GlueWeight(Gtk.Window):
87
87
  """Upluead Glue Weight test."""
88
88
 
89
- def __init__(self, session, ifile=None, help=None):
89
+ def __init__(self, session, ifile=None, help_link=None):
90
90
  """Initialization.
91
91
 
92
92
  Args:
@@ -113,7 +113,7 @@ class GlueWeight(Gtk.Window):
113
113
  session, "MODULE", "GLUE_WEIGHT", defaults)
114
114
 
115
115
  if gtk_runs:
116
- super().__init__(title="Upload Glue Weight")
116
+ super().__init__(title="Upload Glue Weight", help_link=help_link)
117
117
  self.init_window()
118
118
 
119
119
  def init_window(self):
itkdb_gtk/ITkDBlogin.py CHANGED
@@ -239,10 +239,10 @@ class ITkDBlogin(Gtk.Dialog):
239
239
  self.ac1.set_visibility(False)
240
240
  self.ac2.set_visibility(False)
241
241
 
242
- grid.attach(Gtk.Label(label="Acces Code 1"), 0, irow, 1, 1)
242
+ grid.attach(Gtk.Label(label="Access Code 1"), 0, irow, 1, 1)
243
243
  grid.attach(self.ac1, 1, irow, 1, 1)
244
244
  irow = irow + 1
245
- grid.attach(Gtk.Label(label="Acces Code 1"), 0, irow, 1, 1)
245
+ grid.attach(Gtk.Label(label="Access Code 2"), 0, irow, 1, 1)
246
246
  grid.attach(self.ac2, 1, irow, 1, 1)
247
247
 
248
248
  btn = self.get_widget_for_response(Gtk.ResponseType.OK)
@@ -336,6 +336,10 @@ if __name__ == "__main__":
336
336
  # print(l)
337
337
 
338
338
  print("Hello {}".format(dlg.name))
339
+
340
+ rc = client.get("getUser", json={"userIdentity": dlg.user.identity})
341
+ print(rc)
342
+
339
343
  if gtk_runs:
340
344
  try:
341
345
  while True:
itkdb_gtk/ITkDButils.py CHANGED
@@ -10,19 +10,31 @@ import itkdb
10
10
 
11
11
  # The response of the DB
12
12
  db_response = ""
13
+ attachment_urls = {}
14
+ uploaded_test_runs = []
13
15
 
14
16
 
15
17
  # define an Attachment object.
16
18
  class Attachment(object):
17
19
  """Encapsulates Attachment information."""
18
20
 
19
- def __init__(self, path=None, title=None, desc=None):
21
+ def __init__(self, path=None, url=None, title=None, desc=None):
20
22
  """Initialization."""
21
23
  if path is not None:
22
24
  self.path = Path(path).expanduser().resolve()
25
+ self.type = "file"
23
26
  else:
24
27
  self.path = None
25
28
 
29
+ if url is not None:
30
+ self.url = url
31
+ self.type = "link"
32
+ else:
33
+ self.url = None
34
+
35
+ if self.path and self.url:
36
+ raise ValueError("Invalid Attachment. Has both file and link.")
37
+
26
38
  self.title = title
27
39
  self.desc = desc
28
40
 
@@ -44,7 +56,6 @@ def get_db_response():
44
56
  It is stores in a global variable. Trust the function if call
45
57
  right after your interaction with the DB.
46
58
  """
47
- global db_response
48
59
  return db_response
49
60
 
50
61
 
@@ -72,7 +83,8 @@ def get_db_date(timestamp=None):
72
83
  try:
73
84
  this_date = dateutil.parser.parse(timestamp)
74
85
  out = date2string(this_date)
75
- except Exception:
86
+
87
+ except (OverflowError, dateutil.parser.ParserError):
76
88
  out = ""
77
89
 
78
90
  return out
@@ -161,13 +173,13 @@ def create_component_attachment(client, SN, file_path, title=None, description="
161
173
  return db_response
162
174
 
163
175
 
164
- def set_component_property(client, SN, property, value):
176
+ def set_component_property(client, SN, the_property, value):
165
177
  """Set the value of an object property.
166
178
 
167
179
  Args:
168
180
  client: The DB client
169
181
  SN: The object SN
170
- property: The property name
182
+ the_property: The property name
171
183
  value: The property value
172
184
 
173
185
  """
@@ -175,7 +187,7 @@ def set_component_property(client, SN, property, value):
175
187
  try:
176
188
  db_response = client.post('setComponentProperty',
177
189
  json={'component': SN,
178
- 'code': property,
190
+ 'code': the_property,
179
191
  'value': value})
180
192
  return db_response
181
193
 
@@ -247,7 +259,7 @@ def get_DB_component(client, SN):
247
259
  db_response = str(e)
248
260
  return None
249
261
 
250
- def upload_test(client, data, attachments=None):
262
+ def upload_test(client, data, attachments=None, check_runNumber=False):
251
263
  """Upload a test to the DB.
252
264
 
253
265
  Args:
@@ -260,39 +272,124 @@ def upload_test(client, data, attachments=None):
260
272
 
261
273
  """
262
274
  global db_response
275
+ global attachment_urls
276
+ global uploaded_test_runs
277
+
278
+ uploaded_test_runs = []
279
+ attachment_urls = {}
280
+ db_response = None
281
+
282
+ # Check the given run_number. If already existing, give another one which
283
+ # will try to be consecutive.
284
+ if check_runNumber:
285
+ def get_new_value(values):
286
+ run_no = max([x for x in values.keys()])+1
287
+ return run_no
288
+
289
+ test_list = client.get("listTestRunsByComponent",
290
+ json={
291
+ "filterMap":{
292
+ "serialNumber": data["component"],
293
+ "state": "ready",
294
+ "testType":[data["testType"]]
295
+ }
296
+ }
297
+ )
298
+ values = {}
299
+ for T in test_list:
300
+ try:
301
+ run_no = int(T["runNumber"])
302
+ except ValueError:
303
+ run_no = get_new_value(values)
304
+
305
+ values[run_no] = 1
306
+
307
+ try:
308
+ if int(data["runNumber"]) in values.keys():
309
+ data["runNumber"] = "{}".format(get_new_value(values))
310
+ except ValueError:
311
+ data["runNumber"] = "{}".format(get_new_value(values))
312
+
313
+ # Try to upload the test
263
314
  try:
264
315
  db_response = client.post("uploadTestRunResults", json=data)
265
316
  testRun = db_response["testRun"]["id"]
317
+ uploaded_test_runs.append(testRun)
318
+
319
+ # Handle attachments.
320
+ attachment_urls = {}
266
321
  if attachments is not None:
267
322
  if not isinstance(attachments, Iterable):
268
323
  attachments = (attachments)
269
324
 
270
325
  for att in attachments:
271
- path = Path(att.path).expanduser().resolve()
272
- if not path.exists():
273
- print("File {} does not exist".format(path))
274
- continue
275
-
276
326
  data = {"testRun": testRun,
277
327
  "title": att.title if att.title is not None else path.name,
278
328
  "description": att.desc if att.desc is not None else path.name,
279
- "type": "file",
329
+ "type": att.type,
280
330
  }
281
- filetype = mimetypes.guess_type(path.name)
282
- attachment = {'data': (path.name, open(path.as_posix(), 'rb'), filetype[0])}
331
+ if att.type == "file":
332
+ path = Path(att.path).expanduser().resolve()
333
+ if not path.exists():
334
+ print("File {} does not exist".format(path))
335
+ continue
336
+
337
+ data["url"] = path.name
338
+ filetype = mimetypes.guess_type(path.name)
339
+ attachment = {'data': (path.name, open(path.as_posix(), 'rb'), filetype[0])}
340
+ else:
341
+ data["url"] = att.url
342
+ filetype = mimetypes.guess_type(att.url)
343
+ attachment = {'data':(att.url, None, "text/x-uri") }
344
+
283
345
  db_response = client.post('createTestRunAttachment',
284
346
  data=data,
285
347
  files=attachment)
286
-
348
+ try:
349
+ attachment_urls[path.name] = db_response['url']
350
+
351
+ except KeyError:
352
+ pass
353
+
287
354
 
288
355
  return None
289
356
 
290
357
  except Exception as e:
291
358
  return (str(e))
292
359
 
360
+ def set_test_run_parameter(session, test_run, parameter, value):
361
+ """Modify testRun Parameter
362
+
363
+ Args:
364
+ session: The ITkDB session
365
+ test_run: ID of test run
366
+ parameter: parameter code
367
+ value: The new value
368
+ """
369
+ global db_response
370
+ try:
371
+ db_response = session.post("setTestRunParameter",
372
+ json={"testRun": test_run, "code": parameter, "value": value})
373
+ return None
374
+
375
+ except Exception as E:
376
+ return (str(E))
377
+
378
+ def create_test_run_comment(session, test_run, comments):
379
+ """Adds a new comment in testRun."""
380
+ global db_response
381
+ if not isinstance(comments, Iterable):
382
+ comments = (comments)
383
+
384
+ try:
385
+ db_response = session.post("createTestRunComment", json={"testRun": test_run, "comments": comments})
386
+ return None
387
+
388
+ except Exception as E:
389
+ return (str(E))
293
390
 
294
391
  def create_shipment(session, sender, recipient, items, name=None, send=False,
295
- type="domestic", attachment=None, comments=None):
392
+ shipment_type="domestic", attachment=None, comments=None):
296
393
  """Create a chipment.
297
394
 
298
395
  Args:
@@ -311,7 +408,7 @@ def create_shipment(session, sender, recipient, items, name=None, send=False,
311
408
  if name is None:
312
409
  name = "From {} to {}".format(sender, recipient)
313
410
 
314
- if type not in ["domestic", "intraContinental", "continental"]:
411
+ if shipment_type not in ["domestic", "intraContinental", "continental"]:
315
412
  db_response = "Wrong shipment type."
316
413
  return None
317
414
 
@@ -330,7 +427,7 @@ def create_shipment(session, sender, recipient, items, name=None, send=False,
330
427
  "name": name,
331
428
  "sender": sender,
332
429
  "recipient": recipient,
333
- "type": type,
430
+ "type": shipment_type,
334
431
  "shipmentItems": items,
335
432
  }
336
433
 
@@ -569,3 +666,20 @@ def create_client():
569
666
  client.user.authenticate()
570
667
  print("Hello {} !".format(client.user.name))
571
668
  return client
669
+
670
+ def get_db_user(client):
671
+ """REturn PDB information of current user.
672
+
673
+ Args:
674
+ client (itkdb.Client): The DB client.
675
+
676
+ """
677
+ global db_response
678
+ if client is None:
679
+ return None
680
+
681
+ try:
682
+ db_response = client.get("getUser", json={"userIdentity": client.user.identity})
683
+ return db_response
684
+ except Exception:
685
+ return None