Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: modules/adblockplus/files/log/import.py

Issue 29333248: Issue 3306 - Create uplinks for pushing log files (Closed)
Patch Set: Created Jan. 6, 2016, 12:09 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | modules/adblockplus/manifests/log.pp » ('j') | modules/adblockplus/manifests/log.pp » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: modules/adblockplus/files/log/import.py
diff --git a/modules/adblockplus/files/log/import.py b/modules/adblockplus/files/log/import.py
new file mode 100644
index 0000000000000000000000000000000000000000..fc55fa4bfe2bf3c977152bb65d738729e4c41f54
--- /dev/null
+++ b/modules/adblockplus/files/log/import.py
@@ -0,0 +1,50 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*- ------------------------------------------------
+# vi:set fenc=utf-8 ft=python ts=8 et sw=4 sts=4:
+
+__doc__ = """ Redirect STDIN into an ABP log channel.
+
+"""
+import argparse
+import fcntl
+import os
+import shutil
+import sys
+
+try:
+ parser = argparse.ArgumentParser(allow_abbrev=False, description=__doc__)
+except TypeError:
+ parser = argparse.ArgumentParser(description=__doc__)
+
+parser.add_argument(
+ 'name',
+ help='The base name of the logfile to import',
+ metavar='LOG',
+ type=str,
+)
+
+parser.add_argument(
+ '-s', '--source',
+ help='The name (recommended) or IP of the source host',
+ metavar='HOSTNAME',
+ type=str,
+)
+
+parser.add_argument(
+ '-t', '--target',
+ help='The location of the upload/import directory',
+ metavar='DIRECTORY',
+ type=str,
+)
+
+arguments = parser.parse_args()
+destination = os.path.join(arguments.target, arguments.source, arguments.name)
+output = open(destination, 'a')
+fcntl.flock(output, fcntl.F_WRLCK | fcntl.F_EXLCK)
+
+try:
+ shutil.copyfileobj(sys.stdin, output)
+finally:
+ fcntl.flock(output, fcntl.F_UNLCK)
+
+output.close()
« no previous file with comments | « no previous file | modules/adblockplus/manifests/log.pp » ('j') | modules/adblockplus/manifests/log.pp » ('J')

Powered by Google App Engine
This is Rietveld