# Path: src/foolscap/logging/interfaces.py
# class RILogObserver(RemoteInterface):
#     __remote_name__ = "RILogObserver.foolscap.lothar.com"
#     def msg(logmsg=Event):
#         return None
#     def done():
#         return None
# 
#     def new_incident(name=Any(), trigger=Event):
#         # should this give (tubid, incarnation, trigger) like list_incidents?
#         return None
#     def done_with_incident_catchup():
#         return None


import six, os, sys, time
from zope.interface import implementer
from twisted.internet import reactor
from twisted.python import usage
from foolscap import base32
from foolscap.api import Tub, Referenceable, fireEventually
from foolscap.logging import log, flogfile
from foolscap.referenceable import SturdyRef
from foolscap.util import format_time, FORMAT_TIME_MODES, ensure_dict_str, ensure_dict_str_keys
from .interfaces import RILogObserver
    synopsis = "Usage: flogtool tail (LOGPORT.furl/furlfile/nodedir)"

    optFlags = [
        ("verbose", "v", "Show all event arguments"),
        ("catch-up", "c", "Catch up with recent events"),
        ]
    optParameters = [
        ("save-to", "s", None,
         "Save events to the given file. The file will be overwritten."),
        ("timestamps", "t", "short-local",
         "Format for timestamps: " + " ".join(FORMAT_TIME_MODES)),
        ]

    def opt_timestamps(self, arg):
        if arg not in FORMAT_TIME_MODES:
            raise usage.UsageError("--timestamps= must be one of (%s)" %
                                   ", ".join(FORMAT_TIME_MODES))
        self["timestamps"] = arg

    def parseArgs(self, target):
        if target.startswith("pb:"):
            self.target_furl = target
        elif os.path.isfile(target):
            self.target_furl = open(target, "r").read().strip()
        elif os.path.isdir(target):
            fn = os.path.join(target, "logport.furl")
            self.target_furl = open(fn, "r").read().strip()
        else:
            raise RuntimeError("Can't use tail target: %s" % target)


# Path: src/foolscap/logging/interfaces.py
# class RILogObserver(RemoteInterface):
#     __remote_name__ = "RILogObserver.foolscap.lothar.com"
#     def msg(logmsg=Event):
#         return None
#     def done():
#         return None
# 
#     def new_incident(name=Any(), trigger=Event):
#         # should this give (tubid, incarnation, trigger) like list_incidents?
#         return None
#     def done_with_incident_catchup():
#         return None


# Path: src/foolscap/logging/tail.py
import six, os, sys, time
from zope.interface import implementer
from twisted.internet import reactor
from twisted.python import usage
from foolscap import base32
from foolscap.api import Tub, Referenceable, fireEventually
from foolscap.logging import log, flogfile
from foolscap.referenceable import SturdyRef
from foolscap.util import format_time, FORMAT_TIME_MODES, ensure_dict_str, ensure_dict_str_keys
from .interfaces import RILogObserver

    synopsis = "Usage: flogtool tail (LOGPORT.furl/furlfile/nodedir)"

    optFlags = [
        ("verbose", "v", "Show all event arguments"),
        ("catch-up", "c", "Catch up with recent events"),
        ]
    optParameters = [
        ("save-to", "s", None,
         "Save events to the given file. The file will be overwritten."),
        ("timestamps", "t", "short-local",
         "Format for timestamps: " + " ".join(FORMAT_TIME_MODES)),
        ]

    def opt_timestamps(self, arg):
        if arg not in FORMAT_TIME_MODES:
            raise usage.UsageError("--timestamps= must be one of (%s)" %
                                   ", ".join(FORMAT_TIME_MODES))
        self["timestamps"] = arg

    def parseArgs(self, target):
        if target.startswith("pb:"):
            self.target_furl = target
        elif os.path.isfile(target):
            self.target_furl = open(target, "r").read().strip()
        elif os.path.isdir(target):
            fn = os.path.join(target, "logport.furl")
            self.target_furl = open(fn, "r").read().strip()
        else:
            raise RuntimeError("Can't use tail target: %s" % target)


@implementer(RILogObserver)