#!/usr/bin/env python3

import os
import os.path
import stat

# Synopsis: birchtmpdir.sh
#
# returns the location of a temporary directory
# that can be used by scripts which require
# large amounts of disk space for temporary files.

# for test purposes, uncomment one of these
#BIRCH_TMP=""
#BIRCH_TMP="/usr/local/tmp"

USER_TMP = ""
USERID   = os.getlogin()

if os.environ.has_key("BIRCH_TMP"):
    BIRCH_TMP = os.environ.get("BIRCH_TMP");
    if os.path.exists(BIRCH_TMP) and os.path.isdir(BIRCH_TMP):
        os.chdir(BIRCH_TMP)
        if not os.path.exists(USERID):
            os.mkdir(USERID, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR)

        USER_TMP = os.path.join(BIRCH_TMP, USERID)

print USER_TMP
