file_example.py
Go to the documentation of this file.
1 
2 import sys
3 import qi
4 import qi.path
5 import time
6 
7 
8 app = qi.Application()
9 qicore = qi.module('qicore')
10 
11 log = qi.Logger("qicore.file.example")
12 
13 def print_tranfer_progress(progress_value):
14  log.info(">>>> File Transfer Progress = {0}%".format(progress_value * 100))
15 
16 def work_on_image_file(image_file_path):
17  log.info("Working on image file at {0} ...".format(image_file_path))
18  # we fake working on it...
19  time.sleep(1)
20  log.info("Working on image file at {0} - DONE".format(image_file_path))
21 
22 
23 def store_image(image_store, name, image_file_path):
24 
25  log.info("Storing image {1} at {0} into the ImageStore...".format(image_file_path, name))
26 
27  # First open the file with read-only shareable access.
28  file = qicore.openLocalFile(image_file_path)
29 
30  # Now we can share reading access to this file.
31  image_store.store_image(file, name)
32 
33  log.info("Storing image {1} at {0} into the ImageStore - DONE".format(image_file_path, name))
34 
35 
36 def process_image(image_store, image_file_name, image_file_path):
37 
38  # We acquire read-only access to the file and retrieve it locally.
39  file = image_store.get_image(image_file_name)
40  qicore.copyToLocal(file, image_file_path)
41 
42  # We don't need the remote access anymore.
43  del file
44 
45  # Now work on the file located at `fileLocation`.
46  work_on_image_file(image_file_path)
47 
48 
49 def process_image_with_progress(image_store, image_file_name, image_file_path):
50 
51  # We acquire read-only access to the file.
52  file = image_store.get_image(image_file_name)
53 
54  # We prepare the operation without launching it yet:
55  file_operation = qicore.FileCopyToLocal(file, image_file_path)
56 
57  # We want to see the progress so we plug a logging function.
58  file_operation.notifier().progress.connect(print_tranfer_progress)
59 
60  # Launch the copy and wait for it to end before continuing.
61  file_operation.start() # In real projects, prefer file_operation.start(_async=True).then(nextFunction) instead.
62 
63  # We don't need the remote access anymore.
64  del file
65  del file_operation
66 
67  # Now work on the file located at `fileLocation`.
68  work_on_image_file(image_file_path)
69 
70 
71 def do_some_work(client_session, image_path, image_name):
72 
73  image_store = client_session.service('ImageStore')
74  assert image_store
75  store_image(image_store, image_name, image_path)
76  process_image(image_store, image_name, "./tempfile")
77  process_image_with_progress(image_store, image_name, "./tempfile")
78 
79 
80 
81 path_to_file = sys.argv[1]
82 assert path_to_file
83 
84 file_id = sys.argv[2]
85 assert file_id
86 
87 app.start()
88 
89 do_some_work(app.session, path_to_file, file_id)
90 
91 
92 
file_example.process_image
def process_image(image_store, image_file_name, image_file_path)
Definition: file_example.py:36
file_example.do_some_work
def do_some_work(client_session, image_path, image_name)
Definition: file_example.py:71
file_example.process_image_with_progress
def process_image_with_progress(image_store, image_file_name, image_file_path)
Definition: file_example.py:49
file_example.work_on_image_file
def work_on_image_file(image_file_path)
Definition: file_example.py:16
file_example.store_image
def store_image(image_store, name, image_file_path)
Definition: file_example.py:23
file_example.print_tranfer_progress
def print_tranfer_progress(progress_value)
Definition: file_example.py:13


naoqi_libqicore
Author(s): Aldebaran
autogenerated on Wed Sep 14 2022 02:22:41