def get_prog_version(self, prog): """return a simple string with program version each program might be handled a little differently ** but a common method might be PROG --version return status and string - status > 0 means to use, == 0 means not, < 0 means error """ if prog == 'afni': cmd = 'afni -ver' s, so, se = UTIL.limited_shell_exec(cmd, nlines=2) if s: if len(se) > 0: return 1, se[0] else: return 1, '' if len(so) > 1: off1 = so[1].find('[[') off2 = so[1].find(']]') if off1 >= 0 and off2 >= 0: return 1, so[1][off1 + 2:off2] else: return 1, so[1] else: off1 = so[0].find('(') if off1 > 0: vstr = so[0][0:off1] off2 = so[0].find('AFNI_') if off2 > off1: ll = so[0][off2:] self.afni_label = ll.split(')')[0] else: vstr = so[0] return 1, vstr elif prog == 'python': return 1, platform.python_version() elif prog == 'tcsh': # no version return 0, '' elif prog == 'port': # no dashes for version cmd = '%s version' % prog s, so, se = UTIL.limited_shell_exec(cmd, nlines=1) if s: return 1, se[0] else: return 1, so[0] elif prog in ['dnf', 'yum', 'apt-get', 'brew', 'port', 'fink', 'R']: cmd = '%s --version' % prog s, so, se = UTIL.limited_shell_exec(cmd, nlines=1) if s: return 1, se[0] else: return 1, so[0] else: print('** no version method for prog : %s' % prog) return -1, ''
def show_data_info(self, header=1): """checks that are specific to data - class data existence and tree root - assume $HOME if not found - disk space under data root - maybe check for mounted file system - atlases (maybe just @Find TT_N27+tlrc?) """ if header: print(UTIL.section_divider('data checks', hchar='-')) # locate various data trees, and possibly show recent history rv = 0 rv += self.show_data_dir_info('AFNI_data6', 'history.txt') rv += self.show_data_dir_info('AFNI_demos', 'history.txt') rv += self.show_data_dir_info('suma_demo', 'README.archive_creation') rv += self.show_data_dir_info('afni_handouts') if rv: self.comments.append('insufficient data for AFNI bootcamp') evar = 'AFNI_ATLAS_DIR' tryenv = 0 # might suggest setting evar haveenv = evar in os.environ if haveenv: edir = os.environ[evar] else: edir = '' # look for atlases in multiple directories atlas = 'TT_N27+tlrc' if os.path.isfile('%s/%s.HEAD' % (edir, atlas)): glist = [edir] else: glist = [] cmd = '@FindAfniDsetPath %s' % atlas s, so, se = UTIL.limited_shell_exec(cmd, nlines=1) if s: tryenv = 1 # failed elif len(so) > 0: glist.append(so[0]) for ddir in ['/usr/share/afni/atlases', '/usr/local/afni/atlases']: if os.path.isfile('%s/%s.HEAD' % (ddir, atlas)): glist.append(ddir) if tryenv: self.comments.append('consider setting %s to %s' % (evar, ddir)) # fix to work with found after the fact glist = UTIL.get_unique_sublist(glist) if len(glist) == 0: print('atlas : did not find %s' % atlas) self.comments.append('possibly missing atlases') else: for ddir in glist: print('atlas : found %-12s under %s' % (atlas, ddir)) if haveenv: print("\natlas var: %s = %s" % (evar, edir)) print('')
def show_data_info(self, header=1): """checks that are specific to data - class data existence and tree root - assume $HOME if not found - disk space under data root - maybe check for mounted file system - atlases (maybe just @Find TT_N27+tlrc?) """ if header: print UTIL.section_divider('data checks', hchar='-') # locate various data trees, and possibly show recent history rv = 0 rv += self.show_data_dir_info('AFNI_data6', 'history.txt') rv += self.show_data_dir_info('suma_demo', 'README.archive_creation') rv += self.show_data_dir_info('FATCAT_DEMO', 'README.timestamp') rv += self.show_data_dir_info('afni_handouts') if rv: self.comments.append('insufficient data for AFNI bootcamp') evar = 'AFNI_ATLAS_DIR' tryenv = 0 # might suggest setting evar haveenv = os.environ.has_key(evar) if haveenv: edir = os.environ[evar] else: edir = '' # look for atlases in multiple directories atlas = 'TT_N27+tlrc' if os.path.isfile('%s/%s.HEAD'%(edir,atlas)): glist = [edir] else: glist = [] cmd = '@FindAfniDsetPath %s' % atlas s, so, se = UTIL.limited_shell_exec(cmd, nlines=1) if s: tryenv = 1 # failed elif len(so) > 0: glist.append(so[0]) for ddir in ['/usr/share/afni/atlases', '/usr/local/afni/atlases']: if os.path.isfile('%s/%s.HEAD'%(ddir,atlas)): glist.append(ddir) if tryenv: self.comments.append('consider setting %s to %s' % (evar,ddir)) # fix to work with found after the fact glist = UTIL.get_unique_sublist(glist) if len(glist) == 0: print 'atlas : did not find %s' % atlas self.comments.append('possibly missing atlases') else: for ddir in glist: print 'atlas : found %-12s under %s' % (atlas, ddir) if haveenv: print "\natlas var: %s = %s" % (evar, edir) print
def get_prog_version(self, prog): """return a simple string with program version each program might be handled a little differently ** but a common method might be PROG --version return status and string - status > 0 means to use, == 0 means not, < 0 means error """ if prog == 'afni': cmd = 'afni -ver' s, so, se = UTIL.limited_shell_exec(cmd, nlines=2) if s: if len(se) > 0: return 1, se[0] else: return 1, '' if len(so) > 1: off1 = so[1].find('[[') off2 = so[1].find(']]') if off1 >= 0 and off2 >= 0: return 1, so[1][off1+2:off2] else: return 1, so[1] else: off1 = so[0].find('(') if off1 > 0: return 1, so[0][0:off1] else: return 1, so[0] elif prog == 'python': return 1, platform.python_version() elif prog == 'tcsh': # no version return 0, '' elif prog in ['dnf', 'yum', 'apt-get', 'brew', 'port', 'fink', 'R']: cmd = '%s --version' % prog s, so, se = UTIL.limited_shell_exec(cmd, nlines=1) if s: return 1, se[0] else: return 1, so[0] else: print '** no version method for prog : %s' % prog return -1, ''
def get_prog_version(self, prog): """return a simple string with program version each program might be handled a little differently return status and string - status > 0 means to use, == 0 means not, < 0 means error """ if prog == 'afni': cmd = 'afni -ver' s, so, se = UTIL.limited_shell_exec(cmd, nlines=2) if s: if len(se) > 0: return 1, se[0] else: return 1, '' if len(so) > 1: off1 = so[1].find('[[') off2 = so[1].find(']]') if off1 >= 0 and off2 >= 0: return 1, so[1][off1 + 2:off2] else: return 1, so[1] else: off1 = so[0].find('(') if off1 > 0: return 1, so[0][0:off1] else: return 1, so[0] elif prog == 'python': return 1, platform.python_version() elif prog == 'R': cmd = 'R --version' s, so, se = UTIL.limited_shell_exec(cmd, nlines=1) if s: return 1, se[0] else: return 1, so[0] elif prog == 'tcsh': # no version return 0, '' else: print '** no version method for prog : %s' % prog return -1, ''
def get_shell_value(self, shell, evar, verb=0): """really cheap way to grab a value from a new shell""" cmd = "%s -ci 'echo $%s'" % (shell, evar) s, so, se = UTIL.limited_shell_exec(cmd) if len(so) > 0: so = so[-1] else: so = '' if verb: print('++ status = %s for command: %s' % (s, cmd)) print(' stdout = %s' % so) se = '\n'.join(se) if se: print(' stderr = %s' % se) return s, so
def set_shell_rc_file(self, slist): """and many any useful comments""" cc = [] self.rc_file = 'NONE' if 'sh' in slist: # non-login shell ref: NONE # login shell ref: .profile" fname = '.profile' self.rc_file = fname if os.path.isfile('%s/%s' % (self.home_dir, fname)): cc.append("shell sh : found login shell setup file %s" % fname) else: cc.append("shell sh : MISSING login shell setup file %s" % fname) if 'bash' in slist: # non-login shell ref: .bashrc # login shell ref, first of: .bash_profile, .bash_login, .profile f1name = '.bash_profile' f2name = '.bashrc' self.rc_file = f2name f1found = 1 f2found = 1 if not self.home_file_exists(f1name): f1name = '.bash_login' if not self.home_file_exists(f1name): f1name = '.profile' if not self.home_file_exists(f1name): f1name = '.bash_profile' # call this the default cc.append("shell bash: MISSING login setup file, e.g. %s" % f1name) f1found = 0 if not self.home_file_exists(f2name): cc.append("shell bash: MISSING non-login setup file %s" % f2name) f2found = 0 gfound = 0 if f1found and f2found: # does f1name reference f2name? st, so, se = UTIL.limited_shell_exec("\grep %s %s" % (f2name, f1name)) if not st: gfound = 1 if not f1found or not f2found or not gfound: ss="shell bash: consider sourcing (non-login) %s from (login) %s" \ % (f2name, f1name) cc.append(ss) # choose between tcsh and csh, if either is used sname = '' if 'tcsh' in slist: sname = 'tcsh' if sname == '' and 'csh' in slist: sname = 'csh' if sname != '': f1name = '.tcshrc' if not self.home_file_exists(f1name): f1name = '.cshrc' self.rc_file = f1name if not self.home_file_exists(f1name): cc.append('shell %-4s: missing setup file %s' % (sname, f1name)) self.comments.extend(cc)
def get_prog_version(self, prog): """return a simple string with program version each program might be handled a little differently ** but a common method might be PROG --version return status and string - status > 0 means to use, == 0 means not, < 0 means error """ if prog == 'afni': cmd = 'afni -ver' s, so, se = UTIL.limited_shell_exec(cmd, nlines=2) if s: if len(se) > 0: return 1, se[0] else: return 1, '' if len(so) > 1: off1 = so[1].find('[[') off2 = so[1].find(']]') if off1 >= 0 and off2 >= 0: return 1, so[1][off1 + 2:off2] else: return 1, so[1] else: off1 = so[0].find('(') if off1 > 0: vstr = so[0][0:off1] off2 = so[0].find('AFNI_') if off2 > off1: ll = so[0][off2:] self.afni_label = ll.split(')')[0] else: vstr = so[0] return 1, vstr elif prog == 'python': return 1, platform.python_version() elif prog == 'tcsh': # no version return 0, '' elif prog == 'port': # no dashes for version cmd = '%s version' % prog s, so, se = UTIL.limited_shell_exec(cmd, nlines=1) if s: return 1, se[0] else: return 1, so[0] elif prog in ['XQuartz', 'X11']: droot = '/Applications/Utilities' pname = '%s.app' % prog app = '%s/%s' % (droot, pname) dstr = '' # get version string vstr = self.get_kmdi_version(app) # on failure, check the other app if vstr == '': if prog == 'XQuartz': pname = 'X11.app' else: pname = 'XQuartz.app' dstr = '(%s) ' % pname app = '%s/%s' % (droot, pname) vstr = self.get_kmdi_version(app) # clear on failure if vstr == '': dstr = '' return 1, (dstr + vstr) elif prog in ['dnf', 'yum', 'apt-get', 'brew', 'port', 'fink', 'R']: cmd = '%s --version' % prog s, so, se = UTIL.limited_shell_exec(cmd, nlines=1) if s: return 1, se[0] else: return 1, so[0] else: print('** no version method for prog : %s' % prog) return -1, ''
def set_shell_rc_file(self, slist): """and many any useful comments""" cc = [] self.rc_file = 'NONE' if 'sh' in slist: # non-login shell ref: NONE # login shell ref: .profile" fname = '.profile' self.rc_file = fname if os.path.isfile('%s/%s' % (self.home_dir,fname)): cc.append("shell sh : found login shell setup file %s" % fname) else: cc.append("shell sh : MISSING login shell setup file %s" % fname) if 'bash' in slist: # non-login shell ref: .bashrc # login shell ref, first of: .bash_profile, .bash_login, .profile f1name = '.bash_profile' f2name = '.bashrc' self.rc_file = f2name f1found = 1 f2found = 1 if not self.home_file_exists(f1name): f1name = '.bash_login' if not self.home_file_exists(f1name): f1name = '.profile' if not self.home_file_exists(f1name): f1name = '.bash_profile' # call this the default cc.append("shell bash: MISSING login setup file, e.g. %s" % f1name) f1found = 0 if not self.home_file_exists(f2name): cc.append("shell bash: MISSING non-login setup file %s" % f2name) f2found = 0 gfound = 0 if f1found and f2found: # does f1name reference f2name? st, so, se = UTIL.limited_shell_exec("\grep %s %s"%(f2name,f1name)) if not st: gfound = 1 if not f1found or not f2found or not gfound: ss="shell bash: consider sourcing (non-login) %s from (login) %s" \ % (f2name, f1name) cc.append(ss) # choose between tcsh and csh, if either is used sname = '' if 'tcsh' in slist: sname = 'tcsh' if sname == '' and 'csh' in slist: sname = 'csh' if sname != '': f1name = '.tcshrc' if not self.home_file_exists(f1name): f1name = '.cshrc' self.rc_file = f1name if not self.home_file_exists(f1name): cc.append('shell %-4s: missing setup file %s' % (sname, f1name)) self.comments.extend(cc)