Example #1
0
File: git.py Project: ubutnux/lemon
def git_update():
    """ Merge upstream changes into the local repository with `git pull` """

    # Delete the cache file, forcing a request to the GitHub API the next time
    # get_last_github_commit() is called. Otherwise, although up-to-date after
    # running `git pull`, we would be comparing the SHA1 hash of HEAD with the
    # cached one.

    try:
        os.unlink(GITHUB_CACHE_FILE)
    except OSError:
        pass

    args = ['git', 'pull']
    with methods.tmp_chdir(LEMON_DIR):
        return subprocess.call(args)
Example #2
0
File: git.py Project: ubutnux/lemon
def lemon_check_output(args):
    """ Run a command in the LEMON directory and return its output.

    This convenience function chdirs to the LEMON directory, runs a command
    with arguments and returns its output as a string with leading and trailing
    characters removed. If the return code is non-zero, the CalledProcessError
    exception is raised.

    """

    # subprocess.check_output() new in 2.7; we need 2.6 compatibility
    with methods.tmp_chdir(LEMON_DIR):
        with tempfile.TemporaryFile() as fd:
            subprocess.check_call(args, stdout = fd)
            fd.seek(0)
            return fd.readline().strip()
Example #3
0
# Otherwise we will get annoying warning messages (such as "could not open
# XWindow display" or "No graphics display available for this session") when
# working at a remote terminal or at a terminal without any X Windows support.
# Any tasks which attempt to display graphics will fail, of course, but we are
# not going to make use of any of them, anyway.

os.environ['PYRAF_NO_DISPLAY'] = '1'

# When PyRAF is imported, it creates, unless it already exists, a pyraf/
# directory for cache in the current working directory. It also complains that
# "Warning: no login.cl found" if this IRAF file cannot be found either. Avoid
# these two annoying messages, and do not clutter the filesystem with pyraf/
# directories, by temporarily changing the current working directory to that of
# LEMON, where the pyraf/ directory and login.cl were generated by setup.py.

with methods.tmp_chdir(os.path.dirname(os.path.abspath(__file__))):
    import pyraf.iraf
    from pyraf.iraf import digiphot, apphot  # 'digiphot.apphot' package

# Turn PyRAF process caching off; otherwise, if we spawn multiple processes
# and run them in parallel, each one of them would use the same IRAF running
# executable, which could sometimes result in the most arcane of errors.
pyraf.iraf.prcacheOff()

# Decorate pyraf.subproc.Subprocess.__del__() to catch the SubprocessError
# exception that it occasionally raises (when the process is not gone after
# sending the TERM and KILL signals to it) and log it with level DEBUG on the
# root logger. As explained in the Python data model, uncaught exceptions in
# __del__() are ignored and a warning message, which we want to get rid of,
# such as the following, printed to the standard error instead:
#
Example #4
0
# Tell PyRAF to skip all graphics initialization and run in terminal-only mode.
# Otherwise we will get annoying warning messages (such as "could not open
# XWindow display" or "No graphics display available for this session") when
# working at a remote terminal or at a terminal without any X Windows support.
# Any tasks which attempt to display graphics will fail, of course, but we are
# not going to make use of any of them, anyway.

os.environ['PYRAF_NO_DISPLAY'] = '1'

# Avoid PyRAF "Warning: no login.cl found" messages and do not clutter the
# filesystem with pyraf/ cache directories. The current working directory is
# also temporarily changed in fitsimage.py, for the same reason, so refer to
# that module for a more detailed explanation.

with methods.tmp_chdir(os.path.dirname(os.path.abspath(__file__))):
    import pyraf.iraf
    from pyraf.iraf import digiphot, apphot  # 'digiphot.apphot' package

# Turn PyRAF process caching off; otherwise, if we spawn multiple processes
# and run them in parallel, each one of them would use the same IRAF running
# executable, which could sometimes result in the most arcane of errors.
pyraf.iraf.prcacheOff()

# Decorate pyraf.subproc.Subprocess.__del__() to catch the SubprocessError
# exception that it occasionally raises (when the process is not gone after
# sending the TERM and KILL signals to it) and log it with level DEBUG on the
# root logger. As explained in the Python data model, uncaught exceptions in
# __del__() are ignored and a warning message, which we want to get rid of,
# such as the following, printed to the standard error instead:
#