Ori.livneh has submitted this change and it was merged.

Change subject: librenms: Fix PEP8 violations
......................................................................


librenms: Fix PEP8 violations

* E203 whitespace before ','
* E211 whitespace before '('
* E221 multiple spaces before operator
* E265 block comment should start with '# '
* E302 expected 2 blank lines, found 1
* E401 multiple imports on one line
* E501 line too long (n > 100 characters)
* E701 multiple statements on one line (colon)
* W291 trailing whitespace
* W293 blank line contains whitespace

Change-Id: I2d5f6340d6701e6ea83261c6f88550ae7362f325
---
M modules/librenms/files/purge.py
1 file changed, 38 insertions(+), 23 deletions(-)

Approvals:
  Ori.livneh: Verified; Looks good to me, approved
  Andrew Bogott: Looks good to me, but someone else must approve



diff --git a/modules/librenms/files/purge.py b/modules/librenms/files/purge.py
index fd2dcb4..346e165 100644
--- a/modules/librenms/files/purge.py
+++ b/modules/librenms/files/purge.py
@@ -1,6 +1,7 @@
 #! /usr/bin/env python
 """
- purge.py       A small tool that allows you to easily purge old entries in 
the eventlog and syslog table
+ purge.py       A small tool that allows you to easily purge old entries in
+                the eventlog and syslog table
 
  Author:        Mathieu Poussin <mathieu.pous...@sodexo.com>
  Date:          Mar 2014
@@ -10,8 +11,10 @@
                 --eventlog : Enable the eventlog table purge
                 --perftimes : Enable the perftime table purge
                 --devices-perftimes : Enable the device_pertimes table purge
-                INTERVAL : A MySQL compatible interval like "1 YEAR" or "3 
MONTH", this is how long you should keep your log,
-                any entried older than the given interval will be deleted. 
(Defautl is 1 YEAR)
+                INTERVAL : A MySQL compatible interval like "1 YEAR" or
+                "3 MONTH", this is how long you should keep your log,
+                any entried older than the given interval will be deleted.
+                (Defautl is 1 YEAR)
 
 
  Ubuntu Linux:  apt-get install python-mysqldb
@@ -19,10 +22,12 @@
  FreeBSD:       cd /usr/ports/*/py-MySQLdb && make install clean
 
  Tested on:     Python 2.7.5 / Ubuntu 13.10
-  
 """
 try:
-    import subprocess, sys, os, json
+    import subprocess
+    import sys
+    import os
+    import json
 except:
     print "ERROR: missing one or more of the following python modules:"
     print "sys, subprocess, os, json"
@@ -44,16 +49,22 @@
     especially as more features want to be added to this wrapper.
     and
     Take the amount of threads we want to run in parallel from the commandline
-    if None are given or the argument was garbage, fall back to default of 16 
+    if None are given or the argument was garbage, fall back to default of 16
 """
 try:
     import argparse
     parser = argparse.ArgumentParser(description='Purge task for Observium')
-    parser.add_argument('interval', nargs='?', type=str, default="1 YEAR", 
help='How much data to keep')
-    parser.add_argument('--syslog', help='Purge the syslog table', 
action='store_true', default=False)
-    parser.add_argument('--eventlog', help='Purge the eventlog table', 
action='store_true', default=False)
-    parser.add_argument('--perftimes', help='Purge the perf_times table', 
action='store_true', default=False)
-    parser.add_argument('--devices-perftimes', help='Purge the 
devices_pertimes table', action='store_true', default=False)
+    parser.add_argument(
+        'interval', nargs='?', type=str, default="1 YEAR", help='How much data 
to keep')
+    parser.add_argument(
+        '--syslog', help='Purge the syslog table', action='store_true', 
default=False)
+    parser.add_argument(
+        '--eventlog', help='Purge the eventlog table', action='store_true', 
default=False)
+    parser.add_argument(
+        '--perftimes', help='Purge the perf_times table', action='store_true', 
default=False)
+    parser.add_argument(
+        '--devices-perftimes', help='Purge the devices_pertimes table',
+        action='store_true', default=False)
     args = parser.parse_args()
     interval = args.interval
     purge_syslog = args.syslog
@@ -75,6 +86,7 @@
 ob_install_dir = os.path.dirname(os.path.realpath(__file__))
 config_file = ob_install_dir + '/config.php'
 
+
 def get_config_data():
     config_cmd = ['/usr/bin/env', 'php', '%s/config_to_json.php' % 
ob_install_dir]
     try:
@@ -85,7 +97,8 @@
     return proc.communicate()[0]
 
 try:
-    with open(config_file) as f: pass
+    with open(config_file) as f:
+        pass
 except IOError as e:
     print "ERROR: Oh dear... %s does not seem readable" % config_file
     sys.exit(2)
@@ -96,13 +109,13 @@
     print "ERROR: Could not load or parse observium configuration, are PATHs 
correct?"
     sys.exit(2)
 
-db_username  = config['db_user']
-db_password  = config['db_pass']
-db_server    = config['db_host']
-db_dbname    = config['db_name']
+db_username = config['db_user']
+db_password = config['db_pass']
+db_server = config['db_host']
+db_dbname = config['db_name']
 
 try:
-    db = MySQLdb.connect (host=db_server, user=db_username , 
passwd=db_password, db=db_dbname)
+    db = MySQLdb.connect(host=db_server, user=db_username, passwd=db_password, 
db=db_dbname)
     cursor = db.cursor()
 except:
     print "ERROR: Could not connect to MySQL database!"
@@ -112,26 +125,28 @@
 if purge_syslog:
     print "Purging syslog"
     query = """DELETE FROM syslog WHERE timestamp <= DATE(NOW() - INTERVAL 
%s);""" % (interval)
-    #print query
+    # print query
     cursor.execute(query)
 
 
 if purge_eventlog:
     print "Purging eventlog"
     query = """DELETE FROM eventlog WHERE datetime <= DATE(NOW() - INTERVAL 
%s);""" % (interval)
-    #print query
+    # print query
     cursor.execute(query)
 
 if purge_devices_perftimes:
     print "Purging devices_perftimes"
-    query = """DELETE FROM devices_perftimes WHERE from_unixtime(start) <= 
DATE(NOW() - INTERVAL %s);""" % (interval)
-    #print query
+    query = ("DELETE FROM devices_perftimes "
+             "WHERE from_unixtime(start) <= DATE(NOW() - INTERVAL %s);") % 
(interval)
+    # print query
     cursor.execute(query)
 
 if purge_perftimes:
     print "Purging perftimes"
-    query = """DELETE FROM perf_times WHERE from_unixtime(start) <= DATE(NOW() 
- INTERVAL %s);""" % (interval)
-    #print query
+    query = ("DELETE FROM perf_times "
+             "WHERE from_unixtime(start) <= DATE(NOW() - INTERVAL %s);") % 
(interval)
+    # print query
     cursor.execute(query)
 
 db.commit()

-- 
To view, visit https://gerrit.wikimedia.org/r/291174
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I2d5f6340d6701e6ea83261c6f88550ae7362f325
Gerrit-PatchSet: 5
Gerrit-Project: operations/puppet
Gerrit-Branch: production
Gerrit-Owner: BryanDavis <bda...@wikimedia.org>
Gerrit-Reviewer: Andrew Bogott <abog...@wikimedia.org>
Gerrit-Reviewer: Ori.livneh <o...@wikimedia.org>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to