Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
104 changes: 57 additions & 47 deletions getNeuroML.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import sys
import os.path as op
import subprocess
from textwrap import dedent


def main():
"""Main"""
Expand Down Expand Up @@ -50,9 +52,7 @@ def main():
# Which repos use a development branch?
dev_branch_repos = neuroml2_spec_repo + neuroml_repos + jlems_repo


all_repos = lems_repos + neuroml_repos

all_repos = lems_repos + neuroml_repos

# Set the preferred method for cloning from GitHub
github_pref = "HTTP"
Expand All @@ -68,32 +68,31 @@ def main():

local_dir = ".." + os.sep + repo.split("/")[1]

if mode is "clean":
print("------ Cleaning: %s -------"%repo)
if mode == "clean":
print("------ Cleaning: %s -------" % repo)
if repo in java_repos:
command = "mvn clean"
print("It's a Java repository, so cleaning using Maven...")
info = execute_command_in_dir(command, local_dir)

if mode is "update":

print("------ Updating: %s -------" %repo)
if mode == "update":
print("------ Updating: %s -------" % repo)

runMvnInstall = False

if not op.isdir(local_dir):
command = "git clone %s%s" % (pre_gh[github_pref], repo)
print ("Creating a new directory: %s by cloning from GitHub" % \
(local_dir))
print("Creating a new directory: %s by cloning from GitHub" %
(local_dir))
execute_command_in_dir(command, "..")

runMvnInstall = True

if switch_to_branch:
if (repo in dev_branch_repos):
command = "git checkout %s" % (switch_to_branch)
print ("Switching to branch: %s" % (switch_to_branch))
exit_on_fail = switch_to_branch is not "experimental"
print("Switching to branch: %s" % (switch_to_branch))
exit_on_fail = switch_to_branch != "experimental"
execute_command_in_dir(command, local_dir, exit_on_fail)
runMvnInstall = True

Expand All @@ -107,55 +106,54 @@ def main():
or not op.isdir(local_dir + os.sep + "target") \
or ("jNeuroML" in repo)

if (repo in java_repos or repo in neuroml2_spec_repo) and runMvnInstall:
if (repo in java_repos or repo in neuroml2_spec_repo) \
and runMvnInstall:
command = "mvn install"
print("It's a Java repository, so installing using Maven...")
info = execute_command_in_dir(command, local_dir)

#The code below needs a non trivial rewrite due to python3 differences.

#
# The code below needs a non trivial rewrite due to python3
# differences.
if str("BUILD SUCCESS") in str(info):
print("Successful installation using : %s!" %command)
print("Successful installation using : %s!" % command)
else:
print("Problem installing using : %s!" %command)
print("Problem installing using : %s!" % command)
print(info)
exit(1)

if mode is "update":
if mode == "update":
print("All repositories successfully updated & Java modules built!")
print("You should be able to run some examples straight " \
"away using jnml: ")
if os.name is not 'nt':
print(" ./jnml "\
"-validate ../NeuroML2/examples/NML2_FullNeuroML.nml")
print(" ./jnml " \
"../NeuroML2/LEMSexamples/LEMS_NML2_Ex2_Izh.xml")
print("You should be able to run examples straight away using jnml: ")
if os.name != 'nt':
print(" ./jnml " +
"-validate ../NeuroML2/examples/NML2_FullNeuroML.nml")
print(" ./jnml " +
"../NeuroML2/LEMSexamples/LEMS_NML2_Ex2_Izh.xml")
else:
print(" jnml -validate " \
"..\\NeuroML2\\examples\\NML2_FullNeuroML.nml")
print(" jnml " \
"..\\NeuroML2\\LEMSexamples\\LEMS_NML2_Ex2_Izh.xml")
if mode is "clean":
print(" jnml -validate " +
"..\\NeuroML2\\examples\\NML2_FullNeuroML.nml")
print(" jnml " +
"..\\NeuroML2\\LEMSexamples\\LEMS_NML2_Ex2_Izh.xml")
if mode == "clean":
print("All repositories successfully cleaned!")




def execute_command_in_dir(command, directory, exit_on_fail=True):
"""Execute a command in specific working directory"""
if os.name == 'nt':
directory = os.path.normpath(directory)

print(">>> Executing: (%s) in dir: %s (%s)" % (command, directory, os.path.abspath(directory)))
print(">>> Executing: (%s) in dir: %s (%s)" %
(command, directory, os.path.abspath(directory)))

p = subprocess.Popen(command, cwd=directory, shell=True, stdout=subprocess.PIPE)
p = subprocess.Popen(command, cwd=directory, shell=True,
stdout=subprocess.PIPE)
return_str = p.communicate()

if p.returncode != 0:
print("Error: %s" % p.returncode)
if p.returncode != 0:
print("Error: %s" % p.returncode)
print(return_str[0])
if exit_on_fail:
if exit_on_fail:
exit(p.returncode)
if (sys.version_info > (3, 0)):
return return_str[0].decode("utf-8")
Expand All @@ -164,15 +162,27 @@ def execute_command_in_dir(command, directory, exit_on_fail=True):


def help_info():
print("\nUsage:\n\n python getNeuroML.py\n " \
"Pull (or clone) the latest version of all NeuroML 2 repos & " \
"compile/install with Maven if applicable\n\n" \
" python getNeuroML.py clean\n "
"Run 'mvn clean' on all Java repos\n\n" \
" python getNeuroML.py master\n " \
"Switch all repos to master branch\n\n" \
" python getNeuroML.py development\n " \
"Switch relevant repos to development branch\n\n")
usage = (
"""\
Usage: python getNeuroML.py [OPTION]
Script to install NeuroML libraries.
Note: requires internet connectivity.

python getNeuroML.py
Pull (or clone) the latest version of all NeuroML 2 repos &
compile/install with Maven if applicable

python getNeuroML.py clean
Run 'mvn clean' on all Java repos

python getNeuroML.py master
Switch all repos to master branch

python getNeuroML.py development
Switch relevant repos to development branch
"""
)
print(dedent(usage))


if __name__ == "__main__":
Expand Down