44import sys
55import os .path as op
66import subprocess
7+ from textwrap import dedent
8+
79
810def main ():
911 """Main"""
@@ -21,6 +23,8 @@ def main():
2123 switch_to_branch = "experimental"
2224 elif arg == "master" :
2325 switch_to_branch = "master"
26+ elif "osb" in arg :
27+ switch_to_branch = arg
2428 else :
2529 help_info ()
2630 exit ()
@@ -48,11 +52,9 @@ def main():
4852 lems_repos = jlems_repo + lems_spec_repos + pylems_repos
4953
5054 # Which repos use a development branch?
51- dev_branch_repos = neuroml2_spec_repo + neuroml_repos + jlems_repo
52-
53-
54- all_repos = lems_repos + neuroml_repos
55+ dev_branch_repos = neuroml2_spec_repo + java_neuroml_repos + jlems_repo
5556
57+ all_repos = lems_repos + neuroml_repos
5658
5759 # Set the preferred method for cloning from GitHub
5860 github_pref = "HTTP"
@@ -68,32 +70,31 @@ def main():
6870
6971 local_dir = ".." + os .sep + repo .split ("/" )[1 ]
7072
71- if mode is "clean" :
72- print ("------ Cleaning: %s -------" % repo )
73+ if mode == "clean" :
74+ print ("------ Cleaning: %s -------" % repo )
7375 if repo in java_repos :
7476 command = "mvn clean"
7577 print ("It's a Java repository, so cleaning using Maven..." )
7678 info = execute_command_in_dir (command , local_dir )
7779
78- if mode is "update" :
79-
80- print ("------ Updating: %s -------" % repo )
80+ if mode == "update" :
81+ print ("------ Updating: %s -------" % repo )
8182
8283 runMvnInstall = False
8384
8485 if not op .isdir (local_dir ):
8586 command = "git clone %s%s" % (pre_gh [github_pref ], repo )
86- print ("Creating a new directory: %s by cloning from GitHub" % \
87- (local_dir ))
87+ print ("Creating a new directory: %s by cloning from GitHub" %
88+ (local_dir ))
8889 execute_command_in_dir (command , ".." )
8990
9091 runMvnInstall = True
9192
9293 if switch_to_branch :
9394 if (repo in dev_branch_repos ):
9495 command = "git checkout %s" % (switch_to_branch )
95- print ("Switching to branch: %s" % (switch_to_branch ))
96- exit_on_fail = switch_to_branch is not "experimental"
96+ print ("Switching to branch: %s" % (switch_to_branch ))
97+ exit_on_fail = switch_to_branch != "experimental"
9798 execute_command_in_dir (command , local_dir , exit_on_fail )
9899 runMvnInstall = True
99100
@@ -107,72 +108,88 @@ def main():
107108 or not op .isdir (local_dir + os .sep + "target" ) \
108109 or ("jNeuroML" in repo )
109110
110- if (repo in java_repos or repo in neuroml2_spec_repo ) and runMvnInstall :
111+ if (repo in java_repos or repo in neuroml2_spec_repo ) \
112+ and runMvnInstall :
111113 command = "mvn install"
112114 print ("It's a Java repository, so installing using Maven..." )
113115 info = execute_command_in_dir (command , local_dir )
114116
115- #The code below needs a non trivial rewrite due to python3 differences.
116-
117- #
117+ # The code below needs a non trivial rewrite due to python3
118+ # differences.
118119 if str ("BUILD SUCCESS" ) in str (info ):
119- print ("Successful installation using : %s!" % command )
120+ print ("Successful installation using : %s!" % command )
120121 else :
121- print ("Problem installing using : %s!" % command )
122+ print ("Problem installing using : %s!" % command )
122123 print (info )
123124 exit (1 )
124125
125- if mode is "update" :
126+ if mode == "update" :
126127 print ("All repositories successfully updated & Java modules built!" )
127- print ("You should be able to run some examples straight " \
128- "away using jnml: " )
129- if os .name is not 'nt' :
130- print (" ./jnml " \
131- "-validate ../NeuroML2/examples/NML2_FullNeuroML.nml" )
132- print (" ./jnml " \
133- "../NeuroML2/LEMSexamples/LEMS_NML2_Ex2_Izh.xml" )
128+ print ("You should be able to run examples straight away using jnml: " )
129+ if os .name != 'nt' :
130+ print (" ./jnml " +
131+ "-validate ../NeuroML2/examples/NML2_FullNeuroML.nml" )
132+ print (" ./jnml " +
133+ "../NeuroML2/LEMSexamples/LEMS_NML2_Ex2_Izh.xml" )
134134 else :
135- print (" jnml -validate " \
136- "..\\ NeuroML2\\ examples\\ NML2_FullNeuroML.nml" )
137- print (" jnml " \
138- "..\\ NeuroML2\\ LEMSexamples\\ LEMS_NML2_Ex2_Izh.xml" )
139- if mode is "clean" :
135+ print (" jnml -validate " +
136+ "..\\ NeuroML2\\ examples\\ NML2_FullNeuroML.nml" )
137+ print (" jnml " +
138+ "..\\ NeuroML2\\ LEMSexamples\\ LEMS_NML2_Ex2_Izh.xml" )
139+ if mode == "clean" :
140140 print ("All repositories successfully cleaned!" )
141141
142142
143-
144-
145143def execute_command_in_dir (command , directory , exit_on_fail = True ):
146144 """Execute a command in specific working directory"""
147145 if os .name == 'nt' :
148146 directory = os .path .normpath (directory )
149147
150- print (">>> Executing: (%s) in dir: %s (%s)" % (command , directory , os .path .abspath (directory )))
148+ print (">>> Executing: (%s) in dir: %s (%s)" %
149+ (command , directory , os .path .abspath (directory )))
151150
152- p = subprocess .Popen (command , cwd = directory , shell = True , stdout = subprocess .PIPE )
151+ p = subprocess .Popen (command , cwd = directory , shell = True ,
152+ stdout = subprocess .PIPE )
153153 return_str = p .communicate ()
154154
155- if p .returncode != 0 :
156- print ("Error: %s" % p .returncode )
157- print (return_str [0 ])
158- if exit_on_fail :
155+ if p .returncode != 0 :
156+
157+ print ("Error: %s" % p .returncode )
158+ print (return_str [0 ].decode ("utf-8" ) if sys .version_info [0 ]>= 3 else return_str [0 ])
159+ if exit_on_fail :
159160 exit (p .returncode )
161+
160162 if (sys .version_info > (3 , 0 )):
161163 return return_str [0 ].decode ("utf-8" )
162164 else :
163165 return return_str [0 ]
164166
165167
166168def help_info ():
167- print ("\n Usage:\n \n python getNeuroML.py\n " \
168- "Pull (or clone) the latest version of all NeuroML 2 repos & " \
169- "compile/install with Maven if applicable\n \n " \
170- " python getNeuroML.py clean\n "
171- "Run 'mvn clean' on all Java repos\n \n " \
172- " python getNeuroML.py master\n " \
173- "Switch all repos to master branch\n \n " \
174- " python getNeuroML.py development\n " \
175- "Switch relevant repos to development branch\n \n " )
169+ usage = (
170+ """\
171+ Usage: python getNeuroML.py [OPTION]
172+ Script to install NeuroML libraries.
173+ Note: requires internet connectivity.
174+
175+ python getNeuroML.py
176+ Pull (or clone) the latest version of all NeuroML 2 repos &
177+ compile/install with Maven if applicable
178+
179+ python getNeuroML.py clean
180+ Run 'mvn clean' on all Java repos
181+
182+ python getNeuroML.py master
183+ Switch all repos to master branch
184+
185+ python getNeuroML.py development
186+ Switch relevant repos to development branch
187+
188+ python getNeuroML.py experimental
189+ Switch relevant repos to experimental branch
190+ """
191+ )
192+ print (dedent (usage ))
176193
177194
178195if __name__ == "__main__" :
0 commit comments