old_contents: #!/usr/bin/env python
  # -*- coding: utf-8 -*-
  #
  # Script to create links for FSL when filenames starts with FSL5.0-
  #
  # Author: Benjamin De Leener
  # Modified: 2014-09-03
  
  import os
  import getopt
  import sys
  import commands
  sys.path.append('../scripts')
  import sct_utils as sct
  
  
  def usage():
      print 'USAGE: \n' \
          ''+os.path.basename(__file__)+'\n' \
          '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n' \
          'Part of the Spinal Cord Toolbox <https://sourceforge.net/projects/spinalcordtoolbox>\n' \
          '\n'\
          'DESCRIPTION\n' \
          '  Create a package of the Spinal Cord Toolbox.\n' \
          '\n' \
          'USAGE\n' \
          '  '+os.path.basename(__file__)+'\n' \
          '\n' \
          'MANDATORY ARGUMENTS\n' \
          '  -s <OS name>      name of the OS {osx,linux}.\n' \
          '\n'\
          'EXAMPLE:\n' \
          '  create_package.py -s linux\n'
      sys.exit(2)
  
  issudo = 'sudo '
  path_fsl = ''
  prefix_fsl = ''
  # Check input param
  try:
      opts, args = getopt.getopt(sys.argv[1:], 'ha:f:p:')
  except getopt.GetoptError as err:
      print str(err)
      usage()
  for opt, arg in opts:
      if opt == '-h':
          usage()
      elif opt in '-a':
          issudo = ''
      elif opt in '-f':
          path_fsl = arg
      elif opt in '-p':
          prefix_fsl = arg
  
  # get path of SCT
  status, path_sct = commands.getstatusoutput('echo $SCT_DIR')
  
  # create soft link to each script in SCT_DIR/script
  if prefix_fsl is '':
      prefix_fsl = 'fsl5.0-'
  print "Creating soft links for each fsl script that start with ", prefix_fsl
  
  if path_fsl is '':
      status, path_fsl = commands.getstatusoutput('which ' + prefix_fsl + 'fslmaths')
  if path_fsl is '':
      print 'ERROR: the FSL folder was not found! Please provide it using -f option.'
  
  for fsl_script in os.listdir(path_fsl):
      if fsl_script.startswith(prefix_fsl):
          script_name = fsl_script[len(prefix_fsl):]
          sct.run(issudo + 'ln -sf ' + path_sct+'/bin/'+fsl_script + script_name)
  
  print "Done!"
new_contents: #!/usr/bin/env python
  # -*- coding: utf-8 -*-
  #
  # Script to create links for FSL when filenames starts with FSL5.0-
  #
  # Author: Benjamin De Leener
  # Modified: 2014-09-03
  
  import os
  import getopt
  import sys
  import commands
  sys.path.append('../scripts')
  import sct_utils as sct
  
  
  def usage():
      print 'USAGE: \n' \
          ''+os.path.basename(__file__)+'\n' \
          '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n' \
          'Part of the Spinal Cord Toolbox <https://sourceforge.net/projects/spinalcordtoolbox>\n' \
          '\n'\
          'DESCRIPTION\n' \
          '  Create a package of the Spinal Cord Toolbox.\n' \
          '\n' \
          'USAGE\n' \
          '  '+os.path.basename(__file__)+'\n' \
          '\n' \
          'MANDATORY ARGUMENTS\n' \
          '  -s <OS name>      name of the OS {osx,linux}.\n' \
          '\n'\
          'EXAMPLE:\n' \
          '  create_package.py -s linux\n'
      sys.exit(2)
  
  issudo = 'sudo '
  path_fsl = ''
  prefix_fsl = ''
  # Check input param
  try:
      opts, args = getopt.getopt(sys.argv[1:], 'ha:f:p:')
  except getopt.GetoptError as err:
      print str(err)
      usage()
  for opt, arg in opts:
      if opt == '-h':
          usage()
      elif opt in '-a':
          issudo = ''
      elif opt in '-f':
          path_fsl = arg
      elif opt in '-p':
          prefix_fsl = arg
  
  # get path of SCT
  status, path_sct = commands.getstatusoutput('echo $SCT_DIR')
  
  # create soft link to each script in SCT_DIR/script
  if prefix_fsl is '':
      prefix_fsl = 'fsl5.0-'
  print "Creating soft links for each fsl script that start with ", prefix_fsl
  
  if path_fsl is '':
      status, path_fsl = commands.getstatusoutput('which ' + prefix_fsl + 'fslmaths')
  if path_fsl is '':
      print 'ERROR: the FSL folder was not found! Please provide it using -f option.'
  
  for fsl_script in os.listdir(os.path.dirname(path_fsl)):
      if fsl_script.startswith(prefix_fsl):
          print fsl_script, len(prefix_fsl)
          script_name = fsl_script[len(prefix_fsl):]
          print script_name
          sct.run(issudo + 'ln -sf ' + path_sct+'/bin/'+fsl_script + script_name)
  
  print "Done!"
  
subject: test on fsl linking Former-commit-id: b37ce8f679566af9561959f38a43040c6e2e1c87 [formerly 9b4a1061610bc5711ae407e026a325800118afa7] Former-commit-id: e891f636a12d78040520a15e6c3846ef3e256c0f Former-commit-id: 9b701ac57357e3807a5f613781a538c1554c8c73