44import sys
55import os .path as op
66import subprocess
7+ from textwrap import dedent
8+
79
810def main ():
911 """Main"""
@@ -50,9 +52,7 @@ def main():
5052 # Which repos use a development branch?
5153 dev_branch_repos = neuroml2_spec_repo + neuroml_repos + jlems_repo
5254
53-
54- all_repos = lems_repos + neuroml_repos
55-
55+ all_repos = lems_repos + neuroml_repos
5656
5757 # Set the preferred method for cloning from GitHub
5858 github_pref = "HTTP"
@@ -68,32 +68,31 @@ def main():
6868
6969 local_dir = ".." + os .sep + repo .split ("/" )[1 ]
7070
71- if mode is "clean" :
72- print ("------ Cleaning: %s -------" % repo )
71+ if mode == "clean" :
72+ print ("------ Cleaning: %s -------" % repo )
7373 if repo in java_repos :
7474 command = "mvn clean"
7575 print ("It's a Java repository, so cleaning using Maven..." )
7676 info = execute_command_in_dir (command , local_dir )
7777
78- if mode is "update" :
79-
80- print ("------ Updating: %s -------" % repo )
78+ if mode == "update" :
79+ print ("------ Updating: %s -------" % repo )
8180
8281 runMvnInstall = False
8382
8483 if not op .isdir (local_dir ):
8584 command = "git clone %s%s" % (pre_gh [github_pref ], repo )
86- print ("Creating a new directory: %s by cloning from GitHub" % \
87- (local_dir ))
85+ print ("Creating a new directory: %s by cloning from GitHub" %
86+ (local_dir ))
8887 execute_command_in_dir (command , ".." )
8988
9089 runMvnInstall = True
9190
9291 if switch_to_branch :
9392 if (repo in dev_branch_repos ):
9493 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"
94+ print ("Switching to branch: %s" % (switch_to_branch ))
95+ exit_on_fail = switch_to_branch != "experimental"
9796 execute_command_in_dir (command , local_dir , exit_on_fail )
9897 runMvnInstall = True
9998
@@ -107,55 +106,54 @@ def main():
107106 or not op .isdir (local_dir + os .sep + "target" ) \
108107 or ("jNeuroML" in repo )
109108
110- if (repo in java_repos or repo in neuroml2_spec_repo ) and runMvnInstall :
109+ if (repo in java_repos or repo in neuroml2_spec_repo ) \
110+ and runMvnInstall :
111111 command = "mvn install"
112112 print ("It's a Java repository, so installing using Maven..." )
113113 info = execute_command_in_dir (command , local_dir )
114114
115- #The code below needs a non trivial rewrite due to python3 differences.
116-
117- #
115+ # The code below needs a non trivial rewrite due to python3
116+ # differences.
118117 if str ("BUILD SUCCESS" ) in str (info ):
119- print ("Successful installation using : %s!" % command )
118+ print ("Successful installation using : %s!" % command )
120119 else :
121- print ("Problem installing using : %s!" % command )
120+ print ("Problem installing using : %s!" % command )
122121 print (info )
123122 exit (1 )
124123
125- if mode is "update" :
124+ if mode == "update" :
126125 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" )
126+ print ("You should be able to run examples straight away using jnml: " )
127+ if os .name != 'nt' :
128+ print (" ./jnml " +
129+ "-validate ../NeuroML2/examples/NML2_FullNeuroML.nml" )
130+ print (" ./jnml " +
131+ "../NeuroML2/LEMSexamples/LEMS_NML2_Ex2_Izh.xml" )
134132 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" :
133+ print (" jnml -validate " +
134+ "..\\ NeuroML2\\ examples\\ NML2_FullNeuroML.nml" )
135+ print (" jnml " +
136+ "..\\ NeuroML2\\ LEMSexamples\\ LEMS_NML2_Ex2_Izh.xml" )
137+ if mode == "clean" :
140138 print ("All repositories successfully cleaned!" )
141139
142140
143-
144-
145141def execute_command_in_dir (command , directory , exit_on_fail = True ):
146142 """Execute a command in specific working directory"""
147143 if os .name == 'nt' :
148144 directory = os .path .normpath (directory )
149145
150- print (">>> Executing: (%s) in dir: %s (%s)" % (command , directory , os .path .abspath (directory )))
146+ print (">>> Executing: (%s) in dir: %s (%s)" %
147+ (command , directory , os .path .abspath (directory )))
151148
152- p = subprocess .Popen (command , cwd = directory , shell = True , stdout = subprocess .PIPE )
149+ p = subprocess .Popen (command , cwd = directory , shell = True ,
150+ stdout = subprocess .PIPE )
153151 return_str = p .communicate ()
154152
155- if p .returncode != 0 :
156- print ("Error: %s" % p .returncode )
153+ if p .returncode != 0 :
154+ print ("Error: %s" % p .returncode )
157155 print (return_str [0 ])
158- if exit_on_fail :
156+ if exit_on_fail :
159157 exit (p .returncode )
160158 if (sys .version_info > (3 , 0 )):
161159 return return_str [0 ].decode ("utf-8" )
@@ -164,15 +162,27 @@ def execute_command_in_dir(command, directory, exit_on_fail=True):
164162
165163
166164def 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 " )
165+ usage = (
166+ """\
167+ Usage: python getNeuroML.py [OPTION]
168+ Script to install NeuroML libraries.
169+ Note: requires internet connectivity.
170+
171+ python getNeuroML.py
172+ Pull (or clone) the latest version of all NeuroML 2 repos &
173+ compile/install with Maven if applicable
174+
175+ python getNeuroML.py clean
176+ Run 'mvn clean' on all Java repos
177+
178+ python getNeuroML.py master
179+ Switch all repos to master branch
180+
181+ python getNeuroML.py development
182+ Switch relevant repos to development branch
183+ """
184+ )
185+ print (dedent (usage ))
176186
177187
178188if __name__ == "__main__" :
0 commit comments