#!/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)

# Next try retrieving it from Launchpad, printing, and caching
try:
    lp   = LaunchpadService(config={'read_only':True})
    d    = lp.distributions['ubuntu']
    text = d.current_series.name
    print text
    write_file(cache_file, text)

except:
    sys.exit(7)

sys.exit(0)
