diff options
author | jturner <jturner@gemini.edu> | 2016-08-10 17:20:45 -0400 |
---|---|---|
committer | jturner <jturner@gemini.edu> | 2016-08-10 17:20:45 -0400 |
commit | 793690e5795442dd736c5cecfcc1ff6444dcbb4d (patch) | |
tree | cdda31d4685dc3bed1ae5e45b40af20149c9c289 /scripts | |
parent | cf51a7b9156ec5ddf2f13be3607f6594a1056aae (diff) | |
download | astroconda-iraf-helpers-793690e5795442dd736c5cecfcc1ff6444dcbb4d.tar.gz |
Add python script to create the IRAF help & apropos databases for a specified package (or the IRAF core), copied from Ureka (https://aeon.stsci.edu/ssb/svn/u-rel/trunk/bin/ur-genhelp).
Here's a poor-man's copy of the history:
------------------------------------------------------------------------
r3321 | cslocum | 2014-06-20 09:34:36 -0400 (Fri, 20 Jun 2014) | 1 line
update print statements in trunk/bin to be compatible with Python 3
------------------------------------------------------------------------
r1630 | gemini_jturner | 2013-01-17 19:05:22 -0500 (Thu, 17 Jan 2013) | 2 lines
Handle building the main help in iraf$lib as a special case
------------------------------------------------------------------------
r1627 | gemini_jturner | 2013-01-17 18:20:56 -0500 (Thu, 17 Jan 2013) | 2 lines
Suppress PyRAF X display so it doesn't complain in the non-interactive build
------------------------------------------------------------------------
r1610 | gemini_jturner | 2013-01-16 19:25:54 -0500 (Wed, 16 Jan 2013) | 2 lines
Create temporary iraf directory with login.cl if not run from one
------------------------------------------------------------------------
r1601 | gemini_jturner | 2013-01-16 12:24:09 -0500 (Wed, 16 Jan 2013) | 2 lines
Updated one specified package at a time (will call from build.iraf_package)
------------------------------------------------------------------------
r1450 | stsci_cslocum | 2012-12-11 11:53:31 -0500 (Tue, 11 Dec 2012) | 1 line
renamed bin scripts per ticket 95
------------------------------------------------------------------------
r469 | gemini_jturner | 2012-03-06 16:22:33 -0500 (Tue, 06 Mar 2012) | 2 lines
Don't only build help databases if they already exist; do them anyway.
------------------------------------------------------------------------
r345 | gemini_jturner | 2011-11-16 18:03:18 -0500 (Wed, 16 Nov 2011) | 3 lines
Update ur_genhelp for new STScI fileutil location
Fix ur_genhelp uparm$ error and left-over pyraf cache in ur-normalize
------------------------------------------------------------------------
r129 | stsci_sienkiew | 2010-09-15 16:22:40 -0400 (Wed, 15 Sep 2010) | 1 line
regenerate iraf help files during ur-normalize
------------------------------------------------------------------------
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/make_helpdb | 136 |
1 files changed, 136 insertions, 0 deletions
diff --git a/scripts/make_helpdb b/scripts/make_helpdb new file mode 100755 index 0000000..d22612f --- /dev/null +++ b/scripts/make_helpdb @@ -0,0 +1,136 @@ +#!/usr/bin/env python +# +# Usage: ur-genhelp pkgname +# - The package should already have been defined in extern.pkg, otherwise +# IRAF can't find it. +# +# Instead of trying to get a list of IRAF package definitions for the +# current variant and normalize them all, we now call this script (from +# build.iraf_package) to update one specified package at a time. +# Although the generated database files contain some hard-wired paths, in +# practice the databases can be moved and still work without modification, +# so they only need generating once, at compile time. + +import sys, os, os.path + +# Get the package name argument: +if len(sys.argv) == 2: + pkgname = sys.argv[1] +else: + sys.exit('Usage: make_helpdb pkgname') + +# Before importing iraf, we must be running in an IRAF home directory with a +# login.cl etc. The user may not have one already, so unless the current +# directory has a login.cl, we create a temporary IRAF directory here. This +# script will be most efficient if run from an existing IRAF directory, to +# avoid setting one up for each invocation/pkg here, but this only adds ~3s. +if not os.access('login.cl', os.R_OK): + import tempfile, shutil, subprocess, atexit + tmpdir = tempfile.mkdtemp(prefix='tmp_iraf_') # makes a dir in /tmp + def cleantmp(): + # print("Deleting "+tmpdir) + shutil.rmtree(tmpdir) + atexit.register(cleantmp) # clean up temp dir automatically + os.chdir(tmpdir) + subprocess.call('echo xterm | mkiraf > /dev/null', shell=True) # setup + os.mkdir('pyraf') # else pyraf takes time to generate this & outputs text + +# Functions we need for working with IRAF tasks & definitions: +os.environ['PYRAF_NO_DISPLAY'] = 'please' # Avoid errors about X display +import pyraf.iraffunctions +import stsci.tools.fileutil +import stsci.tools.irafglobals as irafglobals + +# This is how you load iraf packages. +from pyraf import iraf +from iraf import stsdas +from iraf import softools + + +# Find the real directory name where a package lives (this will find +# sub-packages only once the parent package has been loaded into the current +# Python session, eg. with iraf.<pkgname>.run(), but for building help we +# are normally only concerned with top-level packages that are already +# defined when PyRAF/IRAF is started). +# +def pkgname_to_dir(pkgname) : + + # treat iraf$lib as a special case because it doesn't show up in + # PyRAF's list of packages but its help still needs compiling + if pkgname == 'iraf': + s = 'iraf$' + + else: + # here is the object that describes the package + p = pyraf.iraffunctions._pkgs[pkgname] + + # get the full package name if IRAF matched an abbreviation + pkgname = p.getName() + + # here is the name of the .cl file + s = p.getFilename() + + # turn the iraf-like filename into a normal filename + # (if it is already a normal filename, it comes through unchanged) + s = stsci.tools.fileutil.osfn(s) + + # get just the directory part + s = os.path.dirname(s) + + # these are the full package name & directory where the package is + return pkgname, s + + +# We could either 1. make a central apropos database (eg. per variant) or 2. +# make one database per package and set the aproposdb environment variable +# to a list of the individual databases, the same as for helpdb. Pick the +# latter for consistency with helpdb and so we only have to generate each +# database when compiling the corresponding package, rather than regenerating +# a common database with ur-normalize whenever something changes. We then +# append each package's path to aproposdb in extern.pkg, as is standard for +# the help. +def mkapropos(pkgname): + + print("\nMake apropos.db for package %s" % pkgname) + + # Call the STSDAS version of the IRAF mkapropos task to make the + # database for this package: + try: + iraf.mkapropos(pkglist=pkgname, helpdir='lib/root.hd', \ + aproposdb=pkgname+'$lib/apropos.db', verbose=0) + except irafglobals.IrafError: + sys.exit('ur-genhelp: error running mkapropos for '+pkgname) + + +# Use IRAF to compile the help database for this package: +def mkhelpdb(pkgname) : + + print("\nMake helpdb for package %s" % pkgname) + + # Call mkhelpdb from IRAF's softools: + try: + iraf.mkhelpdb(helpdir = pkgname+'$lib/root.hd', + helpdb = pkgname + '$lib/helpdb.mip', verbose=0) + except irafglobals.IrafError: + sys.exit('ur-genhelp: error running mkhelpdb for '+pkgname) + + + +# Check that the pkg$lib directory is actually defined/accessible: +try: + pkgname, pkgdir = pkgname_to_dir(pkgname) +except: + sys.exit('ur-genhelp: error: path to package %s not found/defined' \ + % pkgname) + +pkgdir = pkgdir + '/lib' + +if not os.access(pkgdir, os.W_OK): + sys.exit('ur-genhelp: error: path %s not found or isn\'t writeable' \ + % pkgdir) + + +# Call IRAF to build the databases: +mkhelpdb(pkgname) +mkapropos(pkgname) + |