Skip to content

Commit 044fcba

Browse files
committed
Changes in generate_robot
Search elements with different name of the class and the file didn't work on the RPI with python 3.5; it worked fine with newer versions. Now it is fixed and works for both python versions.
1 parent b36a1ce commit 044fcba

File tree

1 file changed

+28
-6
lines changed

1 file changed

+28
-6
lines changed

developing/generator/generate_robot.py

+28-6
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ def get_PYRO4BOT_HOME():
4444
sys.path.append(PYRO4BOT_HOME)
4545
from node.libs.myjson import MyJson
4646

47+
error = False
48+
4749

4850
def check_args(args=None):
4951
""" It checks the arguments passed to the main program and returns them in a dictionary """
@@ -119,11 +121,21 @@ def __get_source_list():
119121
def __search_in(collection, element):
120122
""" It searches an element in a collection of data dictionaries and returns the url path of the element back
121123
This is used to searches the name of a component or a service in a collection of data sources of modules """
124+
path = False
122125
for (url, repo) in collection:
123-
path = next((description['path'] for name, description
124-
in [(k, v) for k, v in
125-
[it for sublist in [elements.items() for module, elements in repo.items()] for it in sublist]]
126-
if element.lower == name.lower() or description['content'].lower() == element.lower()), False)
126+
for k, v in repo.items():
127+
for name, description in v.items():
128+
if element.lower() == name.lower() or element.lower() == description['content'].lower():
129+
path = description['path']
130+
break
131+
if path:
132+
break
133+
# this code doesn't work in the RPI (py3.5) for elements like picam_socket (elemts w/ diff names than the file)
134+
# path = next((description['path'] for name, description
135+
# in [(k, v) for k, v in
136+
# [it for sublist in [elements.items() for module, elements in repo.items()]
137+
# for it in sublist]]
138+
# if element.lower == name.lower() or description['content'].lower() == element.lower()), False)
127139
if path:
128140
return url, path
129141
return False
@@ -143,6 +155,7 @@ def find_elements(json_module_classes, source_list, local_list, botname):
143155
::return: list of each element with its url (repository url header, url_path specific location in the repository)
144156
::rtype: list of [ tuple (repository: string, url_path: string) ] """
145157
global configuration
158+
global error
146159
downloadable_elements = []
147160
for element in json_module_classes:
148161
print("Searching the element: ", element)
@@ -158,6 +171,7 @@ def find_elements(json_module_classes, source_list, local_list, botname):
158171
print("Found in local: ", os.path.abspath(local_path))
159172
else:
160173
print("ERROR with the element: ", element, ".\t It's not found in the repository.")
174+
error = True
161175
print("You should define it in the directories of your robot")
162176

163177
return downloadable_elements
@@ -240,7 +254,9 @@ def create_robot(conf):
240254
print("The robot {} exists".format(conf["robot"]))
241255
return True
242256
except:
257+
global error
243258
print("ERROR: There has been an error with the files and folders of your robot")
259+
error = True
244260
return False
245261

246262

@@ -263,9 +279,15 @@ def create_robot(conf):
263279
if create_robot(args):
264280
if args['update']:
265281
update_robot(args)
266-
print("Completed.")
282+
if error:
283+
print("Some error have occur.")
284+
else:
285+
print("Completed.")
267286
else:
268-
print("Completed")
287+
if error:
288+
print("Some error have occur.")
289+
else:
290+
print("Completed.")
269291
else:
270292
if args['update']:
271293
print("You cannot update the robot because it still doesn't exist.")

0 commit comments

Comments
 (0)