"""Get wikinames for installed software by Joel Hedlund. Small helper utility that may help you get your list of installed software on a cluster correctly reported in a jiffy. The product from running this code is a list of softwares that you can paste right into the |software= line on a cluster page on the snicdocs wiki. You'll need to find out the following information, and replace my examples with your own data in order to make it work (see comments in code below): reported = # what does the wiki say right now? installed = # your "autogenerated list" of installed software. additional = # stuff not covered in autogenerated list. ignored = # literals or compiled REs for stuff you want suppress. wikinames = # translation table from local names to wikinames. spam_filter = # REs for things that probably shouldn't be pasted onto the wiki. """ import re # copy-paste installed software from wiki page. reported = "ARC client,blast,clustalw,CPMD,dalton,edge,Fluent,gaussian,gnuplot,grace,gromacs,hmmer,LAMMPS,mafft,matlab,molden,muscle,octave,openmpi,p4vasp,povray,R,ruby,sam,siesta,swig,vasp,vmd" # automagickally generated list of software from your cluster. I use eg: (module avail; ls /software/apps) | sort | uniq installed = "meep-poop,ansys,base-config,blast,clustalw,cmake,CPMD,dalton,default,default.new,default.rpmorig,dotmodules,edge,emacs,Fluent,gaussian,gnuplot,grace,gromacs,hmmer,icc,idb,ifort,impi,inspector-xe,intel,itac,kappa,LAMMPS,mafft,mathematica,matlab,mkl,moab,moab.backup-2011-04-06,molden,muscle,mvapich2,ncbi_blast,octave,openmpi,p4vasp,pgi,povray,pyenv,python,R,R.remove,ruby,sam,siesta,slurm,snic,swig,testing,toolworks,totalview,vasp,vmd,vtune-amplifier-xe,xmgr" # Any additional softwares you want to advertise, but which aren't revealed by automagic tricks. additional = ['ARC client'] # Stuff reported by automagic tricks that you do *not* wish to advertise # Use literal strings or compiled regular expressions. ignored = ['base-config', 'cmake', re.compile('default.*'), 'dotmodules', 'emacs', 'icc', 'idb', 'ifort', 'kappa', re.compile('moab.*'), 'ncbi_blast', 'pyenv', 'python', 'R.remove', 'slurm', 'snic', 'testing', 'toolworks', 'xmgr'] # Translation table from local module/dir names to wikinames. # Also used to force weird names past the spam filter, if you think that's a good idea. wikinames = {'impi': 'Intel MPI', 'inspector-xe': 'Inspector', 'intel': 'Intel compiler suite', 'itac': 'Trace analyzer and collector', 'vtune-amplifier-xe': 'VTune Amplifier'} # Rules as string literals or compiled REs to catch weird names before you paste them into the wiki. spam_filter = [re.compile(r'.*\W+.*')] def split_names(text): names = [] for name in text.split(','): name = name.strip() if name: names.append(name) names.sort() return names def match(name, compare): for x in compare: if name == x: return True if not isinstance(x, basestring) and x.match(name): return True def get_wikinames(installed, reported): names = set(additional) suspicious = set([]) for name in installed: if match(name, ignored): continue elif name in wikinames: names.add(wikinames[name]) elif match(name, spam_filter): suspicious.add(name) else: names.add(name) missed = set([]) locased = set(name.lower() for name in names) for name in sorted(reported): if name.lower() not in locased: missed.add(name) return names, missed, suspicious names, missed, suspicious = get_wikinames(split_names(installed), split_names(reported)) print "Wikinames:" print ','.join(sorted(names, key=lambda k: k.lower())) print print "Reported but not installed (should be None; add to additional if any should be kept):" print ('\n'.join(sorted(missed, key=lambda k: k.lower())) or None) print print "Caught in spam filter (should be None; add to wikinames if any should be kept, or add to ignored to suppress them):" print ('\n'.join(sorted(suspicious, key=lambda k: k.lower())) or None)