12
12
13
13
# locate all module models of the repository and return a list with their full path
14
14
def findModels (dirName ):
15
- # list given directory's files and subdirectories
15
+ # list given directory's files and subdirectories
16
16
dirContents = os .listdir (dirName )
17
17
modelFiles = list ()
18
18
# iterate over directory contents
@@ -23,123 +23,123 @@ def findModels(dirName):
23
23
if os .path .isdir (fullPath ):
24
24
modelFiles = modelFiles + findModels (fullPath )
25
25
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 )
33
33
return modelFiles
34
34
35
35
def main (args ):
36
36
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 ()
44
44
45
45
# 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" ))
48
48
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" ))
55
55
56
56
# 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" ))
59
59
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." )
87
87
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." )
101
101
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" )
120
120
except :
121
- print "An error occurred during command execution"
121
+ print ( "An error occurred during command execution" )
122
122
sys .exit (1 )
123
123
124
124
125
125
if __name__ == '__main__' :
126
126
127
- # Add usage messages
127
+ # Add usage messages
128
128
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:
133
133
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.
135
135
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.
137
137
list:
138
- list available models or generated implementations.
138
+ list available models or generated implementations.
139
139
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.
143
143
Alternatively, either a shorthand for the generate command:
144
144
all:
145
145
generates the implementation of every existent model
@@ -156,14 +156,14 @@ def main(args):
156
156
{module name}:
157
157
deletes the files related to said module (i.e. "force" would delete generated/force).
158
158
''' )
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.' )
161
161
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 )
166
166
167
- args = parser .parse_args ()
167
+ args = parser .parse_args ()
168
168
169
- main (args )
169
+ main (args )
0 commit comments