コード例 #1
0
   def get_kmdi_version(self, path, verb=1):
      """for the given program, run: mdls -name kMDItemVersion

         return found version string, or an empty one on failure
      """

      cmd = 'mdls -name kMDItemVersion %s' % path
      s, soe = UTIL.exec_tcsh_command(cmd, lines=1)

      # return on failure
      if len(soe) == 0: return ''

      rstr = soe[0]
      rposn = rstr.find('kMDItemVersion')
      if rposn < 0: return ''
      
      rlist = rstr[rposn:].split()
      if verb > 1: print("-- kmdi_v: list is %s" % rlist)
      
      if len(rlist) < 3: return ''
      if rlist[0] != 'kMDItemVersion' or rlist[1] != '=':
         return ''

      # found something, remove any quotes, tabs and spaces, and return
      rstr = rlist[2].strip('\'" \t')

      return rstr
コード例 #2
0
ファイル: tedana_wrapper.py プロジェクト: pab2163/afni
def check_output(cmd, showerr=1):
    """return text output from the given command, executed via 'tcsh -c cmd'

       if showerr and there is a command error, show it
    """
    status, output = afni_util.exec_tcsh_command(cmd)
    if status and showerr:
        print(cmd)
        print(output)
    return output
コード例 #3
0
ファイル: tedana_wrapper.py プロジェクト: pab2163/afni
def exec_or_error(cmd_str, error_msg="ERROR!!!"):
    """Execute subprocess.Popen(cmd_str,stdout=subprocess.PIPE,shell=True)
       Return status and shell output.
       On non 0 status print error_msg and exit.
    """
    print("")
    print(cmd_str)
    sys.stdout.flush()

    # use local library, which returns strings instead of bytes
    retcode, cmd_output = afni_util.exec_tcsh_command(cmd_str)
    if retcode != 0:
        print("\n%s\n\n%s" % (error_msg, cmd_output))
        sys.exit(1)
    return retcode, cmd_output
コード例 #4
0
   def show_general_afni_info(self, header=1):
      print(UTIL.section_divider('AFNI and related program tests', hchar='-'))

      self.afni_dir = self.get_afni_dir()
      check_list = ['afni', 'afni label', 'AFNI_version.txt',
                    'python', 'R', 'tcsh']
      nfound = self.check_for_progs(check_list, show_missing=1)
      if nfound < len(check_list):
         self.comments.append('failure under initial ' \
                              '"AFNI and related program tests"')

      # make generic but pretty
      print("instances of various programs found in PATH:")
      proglist = ['afni', 'R', 'python', 'python2', 'python3']
      ml = UTIL.max_len_in_list(proglist)
      for prog in proglist:
         rv, files = UTIL.search_path_dirs(prog, mtype=1)
         if not rv:
            if len(files) > 1:   fstr = '\n      '+'\n      '.join(files)
            elif len(files) > 0: fstr = '  (%s)' % files[0]
            else:                fstr = ''
            print('    %-*s : %d %s' % (ml, prog, len(files), fstr))

            if prog == 'afni':
               if len(files) > 1:
                  self.comments.append("have multiple versions of AFNI in PATH")
               if len(files) > 0:
                  if os.stat(files[0]).st_uid == 0:
                     self.comments.append("'afni' executable is owned by root")
      print('')

      # explicit python2 vs python3 check    7 Dec 2016
      n2 = UTIL.num_found_in_path('python2', mtype=1)
      n3 = UTIL.num_found_in_path('python3', mtype=1)
      if n3 > 0 and n2 <= 0:
         print("** have python3 but not python2")
      print('')

      # try select AFNI programs
      print('testing ability to start various programs...')
      ind = '%8s' % ' '
      indn = '\n%8s' % ' '
      proglist = ['afni', 'suma', '3dSkullStrip', 'uber_subject.py',
                   '3dAllineate', '3dRSFC', 'SurfMesh', '3dClustSim', '3dMVM']
      fcount = 0
      for prog in proglist:
         st, so, se = BASE.shell_exec2('%s -help'%prog, capture=1)
         # if 3dMVM, status will be 0 on failed library load (fix that, too)
         if prog == '3dMVM' and not st:
            mesg = ''.join(se)
            if mesg.find('Error in dyn.load') >= 0:
               st = 1
         if st:
            print('    %-20s : FAILURE' % prog)
            print(ind + indn.join(se))
            fcount += 1
         else:
            print('    %-20s : success' % prog)

            # no OpenMP problem
            if prog == '3dAllineate': self.ok_openmp = 1
      print('')
      pfailure = fcount == len(proglist)
      if fcount > 0:
         self.afni_fails = fcount
         self.comments.append('AFNI programs show FAILURE')

      # if complete failure, retry from exec dir
      ascdir = UTIL.executable_dir()
      if pfailure and self.afni_dir != ascdir:
         fcount = 0
         print('none working, testing programs under implied %s...' % ascdir)
         for prog in proglist:
            st, so, se = BASE.shell_exec2('%s/%s -help'%(ascdir,prog),capture=1)
            if st:
               print('    %-20s : FAILURE' % prog)
               print(ind + indn.join(se))
               fcount += 1
            else: print('    %-20s : success' % prog)
         print('')
         if fcount < len(proglist):
            self.comments.append('consider adding %s to your PATH' % ascdir)
      # if afni_dir is not set, use ascdir
      if self.afni_dir == '': self.afni_dir = ascdir

      print('checking for R packages...')
      cmd = 'rPkgsInstall -pkgs ALL -check'
      st, so, se = BASE.shell_exec2(cmd, capture=1)
      if st or len(se) < 2: okay = 0
      else:
         if se[1].startswith('++ Note:'): se = se[2:]
         okay = 1
         # do not require "verified", but fail on "not installed"
         # (to avoid failing on 'unknown timezone' warnings)
         for estr in se:
            if estr != '' and estr.find('not installed') >= 0:
               okay = 0   # any failure is terminal
               break
      if okay:
         print('    %-20s : success' % cmd)
      else:
         print('    %-20s : FAILURE' % cmd)
         print(ind + indn.join(se))
         self.comments.append('missing R packages (see rPkgsInstall)')
      print('')

      status, cout = UTIL.exec_tcsh_command("R RHOME")
      print('R RHOME : %s' % cout.strip())
      print('')

      print('checking for $HOME files...')
      flist = ['.afnirc', '.sumarc', '.afni/help/all_progs.COMP']
      for ff in flist:
         if os.path.isfile('%s/%s'%(self.home_dir, ff)): fstr = 'found'
         else:                                           fstr = 'missing'
         print('    %-25s : %s' % (ff, fstr))

      # add to comments
      if self.afni_dir:
         ccc = 'run: cp %s/AFNI.afnirc ~/.afnirc' % self.afni_dir
      else:
         ccc = 'copy AFNI.afnirc to ~/.afnirc'
      self.add_file_comment(None, '.afnirc', 'please %s' % ccc)

      self.add_file_comment(None, '.sumarc',
                            'please run: "suma -update_env" for .sumarc')
      self.add_file_comment(None, '.afni/help/all_progs.COMP',
                            'please run: apsearch -update_all_afni_help')

      print('')