itkdb-gtk 0.10.9.dev2__py3-none-any.whl → 0.10.9.dev4__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
@@ -33,20 +31,20 @@ def find_vtrx(client, SN):
33
31
  }
34
32
  out = client.get("listComponentsByProperty", json=payload)
35
33
  vtrx = None
36
- int nitem = 0
34
+ nitem = 0
37
35
  for item in out:
38
36
  vtrx = item["serialNumber"]
39
37
  nitem += 1
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="IFIC", help_link=None):
50
48
  """Initialization.
51
49
 
52
50
  Args:
@@ -59,13 +57,14 @@ class ReceiveShipments(dbGtkUtils.ITkDBWindow):
59
57
  self.institute = None
60
58
  self.model = None
61
59
  self.store = None
60
+ self.tree = None
62
61
  self.shipments = {}
63
62
 
64
63
  global gtk_runs
65
64
  if gtk_runs:
66
65
  super().__init__(session=session, title="Upload AVS Data",
67
66
  show_search="Click to search shipments",
68
- gtk_runs=gtk_runs, help=help)
67
+ gtk_runs=gtk_runs, help_link=help_link)
69
68
 
70
69
  self.init_window()
71
70
 
@@ -189,13 +188,13 @@ class ReceiveShipments(dbGtkUtils.ITkDBWindow):
189
188
 
190
189
  # search code in the list
191
190
  if self.store:
192
- iter = self.store.get_iter_first()
193
- while iter:
194
- if (self.store.get_value(iter, 0) == txt):
191
+ lv_iter = self.store.get_iter_first()
192
+ while lv_iter:
193
+ if (self.store.get_value(lv_iter, 0) == txt):
195
194
  self.write_message("...found\n")
196
- self.store[iter][3] = False
195
+ self.store[lv_iter][3] = False
197
196
 
198
- iter = self.store.iter_next(iter)
197
+ lv_iter = self.store.iter_next(lv_iter)
199
198
 
200
199
  return True
201
200
 
@@ -234,9 +233,9 @@ class ReceiveShipments(dbGtkUtils.ITkDBWindow):
234
233
 
235
234
  # Store the model associated to this shipment.
236
235
  self.store = self.shipments[shpmnt]
237
- filter = self.store.filter_new()
238
- filter.set_visible_column(3)
239
- self.tree.set_model(filter)
236
+ sfilter = self.store.filter_new()
237
+ sfilter.set_visible_column(3)
238
+ self.tree.set_model(sfilter)
240
239
 
241
240
  def on_status_changed(self, combo):
242
241
  """Status changed."""
@@ -329,25 +328,25 @@ class ReceiveShipments(dbGtkUtils.ITkDBWindow):
329
328
 
330
329
  # self.store is the model of the tree view
331
330
  if self.store:
332
- iter = self.store.get_iter_first()
333
- while iter:
334
- shpmnt = self.store.get_value(iter, 2)
331
+ lv_iter = self.store.get_iter_first()
332
+ while lv_iter:
333
+ shpmnt = self.store.get_value(lv_iter, 2)
335
334
  if shpmnt not in data:
336
335
  data[shpmnt] = create_shipment_status(shpmnt)
337
- names[shpmnt] = self.store.get_value(iter, 4)
336
+ names[shpmnt] = self.store.get_value(lv_iter, 4)
338
337
 
339
338
  item = {
340
- "code": self.store[iter][5],
341
- "delivered": not self.store[iter][3]
339
+ "code": self.store[lv_iter][5],
340
+ "delivered": not self.store[lv_iter][3]
342
341
  }
343
342
  data[shpmnt]["shipmentItems"].append(item)
344
343
 
345
- iter = self.store.iter_next(iter)
344
+ lv_iter = self.store.iter_next(lv_iter)
346
345
 
347
346
  else:
348
347
  self.write_message("Empty list of items.\n")
349
348
 
350
- for id, S in data.items():
349
+ for oid, S in data.items():
351
350
  # Check that all items are there
352
351
  nlost = 0
353
352
  for item in S["shipmentItems"]:
@@ -366,7 +365,7 @@ class ReceiveShipments(dbGtkUtils.ITkDBWindow):
366
365
  return
367
366
 
368
367
  # Open dialog to fill-in questions
369
- create_check_list(S["checklist"]["questionList"], names[id])
368
+ create_check_list(S["checklist"]["questionList"], names[oid])
370
369
 
371
370
  # send the update to the DB
372
371
  S['status'] = "delivered"
@@ -382,10 +381,10 @@ class ReceiveShipments(dbGtkUtils.ITkDBWindow):
382
381
  self.write_message("Could not update the shipment status.\n{}\n".foramt(rc))
383
382
 
384
383
  else:
385
- self.write_message("Shipment {} received\n".format(names[id]))
384
+ self.write_message("Shipment {} received\n".format(names[oid]))
386
385
  # Now remove the current shipment
387
- iter = self.cmb_shipment.get_active_iter()
388
- self.cmb_shipment.get_model().remove(iter)
386
+ lv_iter = self.cmb_shipment.get_active_iter()
387
+ self.cmb_shipment.get_model().remove(lv_iter)
389
388
  self.cmb_shipment.set_active(0)
390
389
 
391
390
 
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/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
 
@@ -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