#!/usr/bin/python

import os.path
import sys
from lpltk import LaunchpadService
from lpltk.utils import (
    load_file,
    write_file,
    file_age
    )

cache_file = os.path.join(
    "/tmp/lpltk.cache",
    os.path.basename(sys.argv[0])
    )

# First try using the cached information
if os.path.exists(cache_file):
    if file_age(cache_file) < 24*60*60:
        print load_file(cache_file)
        sys.exit(0)

try:
    lp   = LaunchpadService(config={'read_only':True})
    d    = lp.distributions['ubuntu']
    text = d.stable_series.name
    assert(type(text) in [str, unicode])
    print text
    write_file(cache_file, text)

except:
    sys.exit(7)

sys.exit(0)
