1. jordilin
  2. alerta

Commits

jordilin  committed 79fcf09

using setuptools properly. Version option provided

  • Participants
  • Parent commits ac89b45
  • Branches default

Comments (0)

Files changed (3)

File MANIFEST.in

View file
-include ChangeLog
-include COPYING
-include log4tailerconfig.txt
-include test/__init__.py
+recursive-exclude docs *
+recursive-exclude spyke * 
+recursive-exclude gui * 
+exclude log4tail.py

File log4tail.py

View file
 from log4tailer.utils import setup_mail
 
 
+__version__ = 2.7
 logging.basicConfig(level = logging.WARNING)
 logger = logging.getLogger('log4tail')
 
             dest="nomailsilence", help="silent mode but no specific notification")
     parser.add_option("--executable", action="store_true", 
             dest="executable", help="executes a program")
+    parser.add_option("--version", action="store_true", 
+            dest="version", help="shows log4tailer version number and exists")
+
+ 
+    (options,args) = parser.parse_args()
+    # defaults 
+    pause = 1
+    silence = False 
+    throttle = 0
+    printAction = notifications.Print()
+    actions = [printAction]
+    nlines = False
+    target = None
+    properties = None
+    logcolors = LogColors.LogColors()
+    alt_config = os.path.expanduser('~/.log4tailer')
+    config = options.configfile or alt_config
+    if options.version:
+        print __version__
+        sys.exit(0)
+    if os.path.exists(config):
+        logger.info("Configuration file [%s] found" % config)
+        properties = parseConfig(config)
+        logcolors.parseConfig(properties)
+    if options.pause:
+        pause = int(options.pause)
+    if options.throttle:
+        throttle = float(options.throttle)
+    if options.silence and properties:
+        mailAction = setup_mail(properties)
+        actions.append(mailAction)
+        silence = True
+    if options.nomailsilence:
+        # silence option with no mail
+        # up to user to provide notification by mail 
+        # or do some kind of reporting 
+        silence = True
+    if options.mail and properties:
+        mailAction = setup_mail(properties)
+        actions.append(mailAction)
+    if options.filter:
+        # overrides Print notifier
+        actions[0] = notifications.Filter(re.compile(options.filter))
+    if options.tailnlines:
+        nlines = int(options.tailnlines)
+    if options.target:
+        target = options.target
+    if options.inactivity:
+        inactivityAction = notifications.Inactivity(options.inactivity, properties)
+        if inactivityAction.getNotificationType() == 'mail':
+            if options.mail or options.silence:
+                inactivityAction.setMailNotification(actions[len(actions)-1])
+            else:
+                mailAction = setup_mail(properties)
+                inactivityAction.setMailNotification(mailAction)
+        actions.append(inactivityAction)
+
+    if options.cornermark:
+        cornermark = notifications.CornerMark(options.cornermark)
+        actions.append(cornermark)
+
+    if options.executable and properties:
+        executor = notifications.Executor(properties)
+        actions.append(executor)
+    
+    if options.remote:
+        from log4tailer import SSHLogTailer
+        tailer = SSHLogTailer.SSHLogTailer(logcolors,target,pause,
+                                           throttle,silence,
+                                           printAction,
+                                           properties)
+        if not tailer.sanityCheck():
+            print "missing config file parameters"
+            sys.exit()
+        tailer.createCommands()
+        try:
+            tailer.createChannels()
+        except Exception,e:
+            print "Could not connect"
+            print "Trace [%s]" % e
+            sys.exit()
+        tailer.tailer()
+        sys.exit()
+    tailer = LogTailer.LogTailer(logcolors,target,pause,
+                                 throttle,silence,
+                                 actions,
+                                 properties)
+    if args[0] == '-':
+        tailer.pipeOut()
+        sys.exit()
+    for i in args:
+        log = Log.Log(i,properties,options)
+        tailer.addLog(log)
+    if nlines:
+        try:
+            tailer.printLastNLines(nlines)
+            print "Ended log4tailer, because colors are fun"
+            sys.exit()
+        except KeyboardInterrupt:
+            print "Ended log4tailer, because colors are fun"
+            sys.exit()
+    tailer.tailer()
+    sys.exit()
+
+if __name__ == '__main__':
+    main()
 
  
     (options,args) = parser.parse_args()

File setup.py

View file
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 import sys 
-from distutils.core import setup, Command
+from setuptools import setup, find_packages
+from distutils.core import Command
 from unittest import TextTestRunner, TestLoader
 from glob import glob
 from os.path import isdir, splitext, basename, join as pjoin
             out,err = svnproc.communicate()
             print out
         
-        self.run_command("test")
+        #self.run_command("test")
         self.run_command("sdist")
-        if not os.path.isdir('dist'):
+        if not isdir('dist'):
             print "I just run sdist and no dist??"
             sys.exit()
         self.run_command("dodoc")
         
-def getDeployPackages():
-    import glob
-    log4tailerpackages = []
-    for file in glob.glob('./log4tailer/*'):
-        if isdir(file):
-            log4tailerpackages.append(basename(file))
-    return log4tailerpackages
-
-PACKAGES = getDeployPackages()
-
 setup(name="log4tailer",
       version=__version__,
       description="Not just a simple log tailer",
       author_email = "jordilin@gmail.com",
       url = "http://code.google.com/p/log4tailer/",
       license = "GNU GPL v3",
-      packages=["log4tailer"] + map("log4tailer.".__add__,PACKAGES),
+      packages= find_packages(),
       scripts = ["log4tail"],
       cmdclass = {"release":Release,
                   "test":Test,