| OLD | NEW | 
|---|
| (Empty) |  | 
|  | 1 #!/usr/bin/env python | 
|  | 2 # -*- coding: utf-8 -*- ------------------------------------------------ | 
|  | 3 # vi:set fenc=utf-8 ft=python ts=8 et sw=4 sts=4: | 
|  | 4 | 
|  | 5 __doc__ = """ Redirect STDIN into an ABP log channel. | 
|  | 6 | 
|  | 7 """ | 
|  | 8 import argparse | 
|  | 9 import fcntl | 
|  | 10 import os | 
|  | 11 import shutil | 
|  | 12 import sys | 
|  | 13 | 
|  | 14 try: | 
|  | 15     parser = argparse.ArgumentParser(allow_abbrev=False, description=__doc__) | 
|  | 16 except TypeError: | 
|  | 17     parser = argparse.ArgumentParser(description=__doc__) | 
|  | 18 | 
|  | 19 parser.add_argument( | 
|  | 20     'name', | 
|  | 21     help='The base name of the logfile to import', | 
|  | 22     metavar='LOG', | 
|  | 23     type=str, | 
|  | 24 ) | 
|  | 25 | 
|  | 26 parser.add_argument( | 
|  | 27     '-s', '--source', | 
|  | 28     help='The name (recommended) or IP of the source host', | 
|  | 29     metavar='HOSTNAME', | 
|  | 30     type=str, | 
|  | 31 ) | 
|  | 32 | 
|  | 33 parser.add_argument( | 
|  | 34     '-t', '--target', | 
|  | 35     help='The location of the upload/import directory', | 
|  | 36     metavar='DIRECTORY', | 
|  | 37     type=str, | 
|  | 38 ) | 
|  | 39 | 
|  | 40 arguments = parser.parse_args() | 
|  | 41 destination = os.path.join(arguments.target, arguments.source, arguments.name) | 
|  | 42 output = open(destination, 'a') | 
|  | 43 fcntl.flock(output, fcntl.F_WRLCK | fcntl.F_EXLCK) | 
|  | 44 | 
|  | 45 try: | 
|  | 46     shutil.copyfileobj(sys.stdin, output) | 
|  | 47 finally: | 
|  | 48     fcntl.flock(output, fcntl.F_UNLCK) | 
|  | 49 | 
|  | 50 output.close() | 
| OLD | NEW | 
|---|