from datetime import datetime, timedelta
import os


settings = {
    "stagedir": "/tmp/netconns/__stage__",
    "finaldir": "/tmp/netconns/final"}

formats = {
    "day": "%Y-%m-%d",
    "hour": "%Y-%m-%dT%H",
    "minute": "%Y-%m-%dT%H:%M"}

thresholds = {
    "day": timedelta(days=14),
    "hour": timedelta(hours=4*24),
    "minute": timedelta(minutes=60)}


def get_current_timestrings():
    now = datetime.now()
    tmp = {}
    for key, format in formats.items():
        tmp[key] = now.strftime(format)
    return tmp


def get_stage_filename(timestamp):
    return os.path.join(settings["stagedir"], timestamp)


def get_final_filename(filename_or_timestamp):
    if os.sep in filename_or_timestamp:
        return filename_or_timestamp.replace(settings["stagedir"], settings["finaldir"])
    return os.path.join(settings["finaldir"], filename_or_timestamp)


def get_current_stage_filename():
    return get_stage_filename(get_current_timestrings()["minute"])


def get_timestamp(filename_or_timestamp):
    if os.sep in filename_or_timestamp:
        timestamp_string = os.path.basename(filename_or_timestamp)
    else:
        timestamp_string = filename_or_timestamp
    for level, format in formats.items():
        try:
            datetime.strptime(timestamp_string, format)
            return (level, timestamp_string)
        except:
            pass
    raise Exception("cannot determine timestamp of %s" % timestamp_string)


def get_higher_timestamp(filename_or_timestamp):
    if os.sep in filename_or_timestamp:
        timestamp_string = os.path.basename(filename_or_timestamp)
    else:
        timestamp_string = filename_or_timestamp
    last_level = None
    for level in sorted(formats):  # here: order is day -> hour -> minute, perfect :o)
        format = formats[level]
        try:
            timestamp = datetime.strptime(timestamp_string, format)
            return (last_level, timestamp.strftime(formats[last_level]))
        except:
            last_level = level
    return (None, None)
    # raise Exception("cannot determine higher timestamp of %s" % timestamp_string)


def makedirs(filename):
    try:
        os.makedirs(os.path.dirname(filename))
    except OSError as e:
        if e.errno != 17:
            raise







def calc_actual_filename():
    hour, minute = calc_actual_time()
    return os.path.join(settings["prefix"], hour, minute)


def calc_actual_dirname():
    hour, _ = calc_actual_time()
    return os.path.join(settings["prefix"], hour)


def calc_previous_hour():
    one_hour_back = timedelta(hours=-1)
    hour = datetime.now() + one_hour_back
    return hour.strftime(HOUR_FORMAT)

def calc_filename(hour):
    return os.path.join(settings["prefix"], hour)

@@ -2261,471 +2261,4 @@
 ise%0A
-%0A%0A%0A%0A%0A%0A%0Adef calc_actual_filename():%0A    hour, minute = calc_actual_time()%0A    return os.path.join(settings%5B%22prefix%22%5D, hour, minute)%0A%0A%0Adef calc_actual_dirname():%0A    hour, _ = calc_actual_time()%0A    return os.path.join(settings%5B%22prefix%22%5D, hour)%0A%0A%0Adef calc_previous_hour():%0A    one_hour_back = timedelta(hours=-1)%0A    hour = datetime.now() + one_hour_back%0A    return hour.strftime(HOUR_FORMAT)%0A%0Adef calc_filename(hour):%0A    return os.path.join(settings%5B%22prefix%22%5D, hour)%0A

remove unused code