Skip to content
This repository was archived by the owner on Nov 13, 2019. It is now read-only.

Commit 7960c6d

Browse files
authored
Merge branch 'master' into avoid-lxml-exception
2 parents 838f786 + 2146d92 commit 7960c6d

File tree

24 files changed

+905
-1249
lines changed

24 files changed

+905
-1249
lines changed

README.md

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -46,20 +46,15 @@ A preliminary whitepaper about this work is available at https://arxiv.org/abs/1
4646
```
4747

4848
### Install dependencies
49-
```
50-
sudo apt-get install python-lxml
51-
```
52-
53-
Alternatively, the OS-independent `pip` command would be:
5449
```bash
55-
pip install lxml
50+
pip3 install lxml
5651
```
5752

5853
### Script usage
5954

6055
The command structure would be the following:
6156
```
62-
python hrim.py [-h] [-p {ros2}] [-e] {show,generate,list,clear} filePath
57+
python3 hrim.py [-h] [-p {ros2}] [-e] {show,generate,list,clear} filePath
6358
```
6459
Where:
6560

@@ -149,16 +144,16 @@ If the chosen action is **clear** it can either represent a directory name or a
149144

150145
While positioned at the repository's root all of the following are valid command executions:
151146

152-
* `python hrim.py show $(pwd)/models/sensor/torque/torque.xml`
153-
* `python hrim.py show ./models/sensor/torque/torque.xml`
154-
* `python hrim.py -e show /models/sensor/torque/torque.xml`
155-
* `python hrim.py show --extend models/sensor/torque/torque.xml`
156-
* `python hrim.py show models/sensor/torque/torque.xml`
157-
* `python hrim.py generate $(pwd)/models/sensor/torque/torque.xml`
158-
* `python hrim.py generate ./models/sensor/torque/torque.xml`
159-
* `python hrim.py -p ros2 generate /models/sensor/torque/torque.xml`
160-
* `python hrim.py generate models/sensor/torque/torque.xml`
161-
* `python hrim.py generate --platform ros2 all`
162-
* `python hrim.py generate allClean`
163-
* `python hrim.py clear force`
164-
* `python hrim.py clear all`
147+
* `python3 hrim.py show $(pwd)/models/sensor/torque/torque.xml`
148+
* `python3 hrim.py show ./models/sensor/torque/torque.xml`
149+
* `python3 hrim.py -e show /models/sensor/torque/torque.xml`
150+
* `python3 hrim.py show --extend models/sensor/torque/torque.xml`
151+
* `python3 hrim.py show models/sensor/torque/torque.xml`
152+
* `python3 hrim.py generate $(pwd)/models/sensor/torque/torque.xml`
153+
* `python3 hrim.py generate ./models/sensor/torque/torque.xml`
154+
* `python3 hrim.py -p ros2 generate /models/sensor/torque/torque.xml`
155+
* `python3 hrim.py generate models/sensor/torque/torque.xml`
156+
* `python3 hrim.py generate --platform ros2 all`
157+
* `python3 hrim.py generate allClean`
158+
* `python3 hrim.py clear force`
159+
* `python3 hrim.py clear all`

hrim.py

Lines changed: 103 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
# locate all module models of the repository and return a list with their full path
1414
def findModels(dirName):
15-
# list given directory's files and subdirectories
15+
# list given directory's files and subdirectories
1616
dirContents = os.listdir(dirName)
1717
modelFiles = list()
1818
# iterate over directory contents
@@ -23,123 +23,123 @@ def findModels(dirName):
2323
if os.path.isdir(fullPath):
2424
modelFiles = modelFiles + findModels(fullPath)
2525
else:
26-
# else check the file is a model: look for xml files inside model
27-
# categories and ignore files inside "topics" directories
28-
if (
29-
bool(re.search('models.(actuator|sensor|communication|cognition|ui|power|composite).*\.xml$', fullPath)) and
30-
not bool(re.search('.*models.*topics', fullPath))
31-
):
32-
modelFiles.append(fullPath)
26+
# else check the file is a model: look for xml files inside model
27+
# categories and ignore files inside "topics" directories
28+
if (
29+
bool(re.search('models.(actuator|sensor|communication|cognition|ui|power|composite).*\.xml$', fullPath)) and
30+
not bool(re.search('.*models.*topics', fullPath))
31+
):
32+
modelFiles.append(fullPath)
3333
return modelFiles
3434

3535
def main(args):
3636
try:
37-
parser = ModuleParser()
38-
if args.action == "show":
39-
extend = args.extend
40-
module = parser.parseFile(args.filePath)
41-
ModulePrinter().printModule(module, args.platform, extend)
42-
elif args.action == "generate":
43-
path = os.getcwd()
37+
parser = ModuleParser()
38+
if args.action == "show":
39+
extend = args.extend
40+
module = parser.parseFile(args.filePath)
41+
ModulePrinter().printModule(module, args.platform, extend)
42+
elif args.action == "generate":
43+
path = os.getcwd()
4444

4545
# if generic package exists we delete it
46-
if os.path.exists(os.path.join(os.getcwd(), "generated", "generic")):
47-
shutil.rmtree(os.path.join(os.getcwd(), "generated", "generic"))
46+
if os.path.exists(os.path.join(os.getcwd(), "generated", "generic")):
47+
shutil.rmtree(os.path.join(os.getcwd(), "generated", "generic"))
4848

49-
generic = parser.parseBase(os.path.join(path, "models", "generic", "base.xml"))
50-
compiler = ModuleCompiler()
51-
compiler.compileGeneric(generic, args.platform)
52-
print "Succesfully generated "+args.platform+" implementation of HRIM's generic package."
53-
os.chdir(path)
54-
geometry = parser.parseBase(os.path.join(path, "models", "geometry", "geometry.xml"))
49+
generic = parser.parseBase(os.path.join(path, "models", "generic", "base.xml"))
50+
compiler = ModuleCompiler()
51+
compiler.compileGeneric(generic, args.platform)
52+
print("Succesfully generated "+args.platform+" implementation of HRIM's generic package.")
53+
os.chdir(path)
54+
geometry = parser.parseBase(os.path.join(path, "models", "geometry", "geometry.xml"))
5555

5656
# if geometry package exists we delete it
57-
if os.path.exists(os.path.join(os.getcwd(), "generated", "geometry")):
58-
shutil.rmtree(os.path.join(os.getcwd(), "generated", "geometry"))
57+
if os.path.exists(os.path.join(os.getcwd(), "generated", "geometry")):
58+
shutil.rmtree(os.path.join(os.getcwd(), "generated", "geometry"))
5959

60-
compiler.compileGeneric(geometry, args.platform, "geometry")
61-
print "Succesfully generated "+args.platform+" implementation of HRIM's geometry package."
62-
os.chdir(path)
63-
# check for file generation shorthands
64-
if args.filePath == "all":
65-
fileList = findModels(os.path.join(path, "models"))
66-
for item in fileList:
67-
# if the model isn't a development file process it
68-
if not bool(re.search('.*_clean.xml$', item)):
69-
os.chdir(path)
70-
module = parser.parseFile(item)
71-
compiler.compileModule(module, args.platform)
72-
print "Succesfully generated "+args.platform+" implementation of "+module.name+" module."
73-
elif args.filePath == "allClean":
74-
fileList = findModels(os.path.join(path, "models"))
75-
for item in fileList:
76-
# if the model is a development file process it
77-
if bool(re.search('.*_clean.xml$', item)):
78-
os.chdir(path)
79-
module = parser.parseFile(item)
80-
compiler.compileModule(module, args.platform)
81-
print "Succesfully generated "+args.platform+" implementation of "+module.name+" module."
82-
# else try to generate the implementation based on the passed file
83-
else:
84-
module = parser.parseFile(args.filePath)
85-
compiler.compileModule(module, args.platform)
86-
print "Succesfully generated "+args.platform+" implementation of "+module.name+" module."
60+
compiler.compileGeneric(geometry, args.platform, "geometry")
61+
print("Succesfully generated "+args.platform+" implementation of HRIM's geometry package.")
62+
os.chdir(path)
63+
# check for file generation shorthands
64+
if args.filePath == "all":
65+
fileList = findModels(os.path.join(path, "models"))
66+
for item in fileList:
67+
# if the model isn't a development file process it
68+
if not bool(re.search('.*_clean.xml$', item)):
69+
os.chdir(path)
70+
module = parser.parseFile(item)
71+
compiler.compileModule(module, args.platform)
72+
print("Succesfully generated "+args.platform+" implementation of "+module.name+" module.")
73+
elif args.filePath == "allClean":
74+
fileList = findModels(os.path.join(path, "models"))
75+
for item in fileList:
76+
# if the model is a development file process it
77+
if bool(re.search('.*_clean.xml$', item)):
78+
os.chdir(path)
79+
module = parser.parseFile(item)
80+
compiler.compileModule(module, args.platform)
81+
print("Succesfully generated "+args.platform+" implementation of "+module.name+" module.")
82+
# else try to generate the implementation based on the passed file
83+
else:
84+
module = parser.parseFile(args.filePath)
85+
compiler.compileModule(module, args.platform)
86+
print("Succesfully generated "+args.platform+" implementation of "+module.name+" module.")
8787
elif args.action == "list":
88-
if args.filePath == "models":
89-
modelList = findModels(os.path.join(os.getcwd(), "models"))
90-
for model in sorted(modelList):
91-
if not bool(re.search('.*_clean.xml$', model)):
92-
pathList = model.split(os.sep)
93-
print pathList[-3]+"/"+pathList[-2]+"/"+pathList[-1].replace('.xml',"")
94-
elif args.filePath == "implementations":
95-
impList = os.listdir("generated")
96-
if len(impList) > 0:
97-
for implementation in sorted(impList):
98-
print implementation
99-
else:
100-
print "There's no generated implementations."
88+
if args.filePath == "models":
89+
modelList = findModels(os.path.join(os.getcwd(), "models"))
90+
for model in sorted(modelList):
91+
if not bool(re.search('.*_clean.xml$', model)):
92+
pathList = model.split(os.sep)
93+
print(pathList[-3]+"/"+pathList[-2]+"/"+pathList[-1].replace('.xml',""))
94+
elif args.filePath == "implementations":
95+
impList = os.listdir("generated")
96+
if len(impList) > 0:
97+
for implementation in sorted(impList):
98+
print(implementation)
99+
else:
100+
print("There's no generated implementations.")
101101
elif args.action == "clear":
102-
if len(os.listdir("generated")) > 0:
103-
if args.filePath == "all":
104-
delDirs = os.listdir("generated")
105-
for delPath in sorted(delDirs):
106-
fullPath = os.path.join(os.getcwd(), "generated", delPath)
107-
shutil.rmtree(fullPath)
108-
print "Deleted "+fullPath
109-
else:
110-
fullPath = os.path.join(os.getcwd(), "generated", args.filePath)
111-
if os.path.exists(fullPath):
112-
shutil.rmtree(fullPath)
113-
print "Deleted "+fullPath
114-
else:
115-
print "Couldn't find passed directory for deletion."
116-
else:
117-
print "There is no implementation to delete (generated directory is empty)."
118-
else:
119-
print "Unknown command"
102+
if len(os.listdir("generated")) > 0:
103+
if args.filePath == "all":
104+
delDirs = os.listdir("generated")
105+
for delPath in sorted(delDirs):
106+
fullPath = os.path.join(os.getcwd(), "generated", delPath)
107+
shutil.rmtree(fullPath)
108+
print("Deleted "+fullPath)
109+
else:
110+
fullPath = os.path.join(os.getcwd(), "generated", args.filePath)
111+
if os.path.exists(fullPath):
112+
shutil.rmtree(fullPath)
113+
print("Deleted "+fullPath)
114+
else:
115+
print("Couldn't find passed directory for deletion.")
116+
else:
117+
print("There is no implementation to delete (generated directory is empty).")
118+
else:
119+
print("Unknown command")
120120
except:
121-
print "An error occurred during command execution"
121+
print("An error occurred during command execution")
122122
sys.exit(1)
123123

124124

125125
if __name__ == '__main__':
126126

127-
# Add usage messages
127+
# Add usage messages
128128

129-
parser=argparse.ArgumentParser(
130-
description='''Hardware Robot Information Model (HRIM) implementation generation tool.''',
131-
formatter_class=argparse.RawTextHelpFormatter)
132-
parser.add_argument('action', choices=['show','generate', 'list', 'clear'], help='''Action to take:
129+
parser=argparse.ArgumentParser(
130+
description='''Hardware Robot Information Model (HRIM) implementation generation tool.''',
131+
formatter_class=argparse.RawTextHelpFormatter)
132+
parser.add_argument('action', choices=['show','generate', 'list', 'clear'], help='''Action to take:
133133
show:
134-
print a representation of the passed valid XML module's model structure and values.
134+
print a representation of the passed valid XML module's model structure and values.
135135
generate:
136-
generate the platform-specific implementation of the passed valid XML model.
136+
generate the platform-specific implementation of the passed valid XML model.
137137
list:
138-
list available models or generated implementations.
138+
list available models or generated implementations.
139139
clear:
140-
delete the passed generated implementation.
141-
''')
142-
parser.add_argument('filePath', help='''The path to a valid xml model file.
140+
delete the passed generated implementation.
141+
''')
142+
parser.add_argument('filePath', help='''The path to a valid xml model file.
143143
Alternatively, either a shorthand for the generate command:
144144
all:
145145
generates the implementation of every existent model
@@ -156,14 +156,14 @@ def main(args):
156156
{module name}:
157157
deletes the files related to said module (i.e. "force" would delete generated/force).
158158
''')
159-
parser.add_argument('-p', '--platform', default='ros2', choices=['ros2'], help='The platform for the generated model, ros2 by default.')
160-
parser.add_argument('-e', '--extend', action='store_true', default=False, help='Whether to expand topic definitions when "show"-ing.')
159+
parser.add_argument('-p', '--platform', default='ros2', choices=['ros2'], help='The platform for the generated model, ros2 by default.')
160+
parser.add_argument('-e', '--extend', action='store_true', default=False, help='Whether to expand topic definitions when "show"-ing.')
161161

162-
# If no argument is provided, show usage
163-
if len(sys.argv) == 1:
164-
parser.print_help()
165-
sys.exit(0)
162+
# If no argument is provided, show usage
163+
if len(sys.argv) == 1:
164+
parser.print_help()
165+
sys.exit(0)
166166

167-
args=parser.parse_args()
167+
args=parser.parse_args()
168168

169-
main(args)
169+
main(args)

0 commit comments

Comments
 (0)