Beispiel #1
0
def getPreferredStatsCacheFileName(options):
    """ Determine if the jobtree or the os.getcwd() version should be used.
    If no good option exists, return a nonexistent file path.
    Note you MUST check to see if the return value exists before using.
    """
    null_file = getNullFile()
    location_jt = getStatsCacheFileName(options.jobTree)
    location_local = os.path.abspath(
        os.path.join(os.getcwd(), ".stats_cache.pickle"))
    # start by looking for the current directory cache.
    if os.path.exists(location_local):
        loc_file = open(location_local, "r")
        data, loc = cPickle.load(loc_file)
        if getStatsFileName(options.jobTree) != loc:
            # the local cache is from looking up a *different* jobTree
            location_local = null_file
    if os.path.exists(location_jt) and not os.path.exists(location_local):
        # use the jobTree directory version
        return location_jt
    elif not os.path.exists(location_jt) and os.path.exists(location_local):
        # use the os.getcwd() version
        return location_local
    elif os.path.exists(location_jt) and os.path.exists(location_local):
        # check file modify times and use the most recent version
        mtime_jt = os.path.getmtime(location_jt)
        mtime_local = os.path.getmtime(location_local)
        if mtime_jt > mtime_local:
            return location_jt
        else:
            return location_local
    else:
        return null_file
Beispiel #2
0
def getPreferredStatsCacheFileName(options):
    """ Determine if the jobtree or the os.getcwd() version should be used.
    If no good option exists, return a nonexistent file path.
    Note you MUST check to see if the return value exists before using.
    """
    null_file = getNullFile()
    location_jt = getStatsCacheFileName(options.jobTree)
    location_local = os.path.abspath(os.path.join(os.getcwd(),
                                                  ".stats_cache.pickle"))
    # start by looking for the current directory cache.
    if os.path.exists(location_local):
        loc_file = open(location_local, "r")
        data, loc = cPickle.load(loc_file)
        if getStatsFileName(options.jobTree) != loc:
            # the local cache is from looking up a *different* jobTree
            location_local = null_file
    if os.path.exists(location_jt) and not os.path.exists(location_local):
        # use the jobTree directory version
        return location_jt
    elif not os.path.exists(location_jt) and os.path.exists(location_local):
        # use the os.getcwd() version
        return location_local
    elif os.path.exists(location_jt) and os.path.exists(location_local):
        # check file modify times and use the most recent version
        mtime_jt = os.path.getmtime(location_jt)
        mtime_local = os.path.getmtime(location_local)
        if mtime_jt > mtime_local:
            return location_jt
        else:
            return location_local
    else:
        return null_file
Beispiel #3
0
def packData(data, options):
    """ packData stores all of the data in the appropriate pickle cache file.
    """
    stats_file = getStatsFileName(options.jobTree)
    cache_file = getStatsCacheFileName(options.jobTree)
    try:
        # try to write to the jobTree directory
        payload = (data, stats_file)
        f = open(cache_file, "wb")
        cPickle.dump(payload, f, 2)  # 2 is binary format
        f.close()
    except IOError:
        if not options.cache:
            return
        # try to write to the current working directory only if --cache
        cache_file = os.path.abspath(
            os.path.join(os.getcwd(), ".stats_cache.pickle"))
        payload = (data, stats_file)
        f = open(cache_file, "wb")
        cPickle.dump(payload, f, 2)  # 2 is binary format
        f.close()
Beispiel #4
0
def packData(data, options):
    """ packData stores all of the data in the appropriate pickle cache file.
    """
    stats_file = getStatsFileName(options.jobTree)
    cache_file = getStatsCacheFileName(options.jobTree)
    try:
        # try to write to the jobTree directory
        payload = (data, stats_file)
        f = open(cache_file, "wb")
        cPickle.dump(payload, f, 2)  # 2 is binary format
        f.close()
    except IOError:
        if not options.cache:
            return
        # try to write to the current working directory only if --cache
        cache_file = os.path.abspath(os.path.join(os.getcwd(),
                                                  ".stats_cache.pickle"))
        payload = (data, stats_file)
        f = open(cache_file, "wb")
        cPickle.dump(payload, f, 2)  # 2 is binary format
        f.close()