mailr20142 - /trunk/devel_scripts/find_unused_imports.py


Others Months | Index by Date | Thread Index
>>   [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Header


Content

Posted by edward on June 16, 2013 - 11:42:
Author: bugman
Date: Sun Jun 16 11:42:25 2013
New Revision: 20142

URL: http://svn.gna.org/viewcvs/relax?rev=20142&view=rev
Log:
Created a script to look through the entire relax source tree for unused 
imports.


Added:
    trunk/devel_scripts/find_unused_imports.py   (with props)

Added: trunk/devel_scripts/find_unused_imports.py
URL: 
http://svn.gna.org/viewcvs/relax/trunk/devel_scripts/find_unused_imports.py?rev=20142&view=auto
==============================================================================
--- trunk/devel_scripts/find_unused_imports.py (added)
+++ trunk/devel_scripts/find_unused_imports.py Sun Jun 16 11:42:25 2013
@@ -1,0 +1,35 @@
+#! /usr/bin/env python
+
+"""Find all unused imports within all relax *.py files using the pylint 
program."""
+
+# Python module imports.
+from os import getcwd, path, waitpid, sep, walk
+from re import search
+from subprocess import PIPE, Popen
+
+
+# Walk through the current dir.
+for root, dirs, files in walk(getcwd()):
+    # Loop over the files.
+    for file in files:
+        # Only check Python files.
+        if not search("\.py$", file):
+            continue
+
+        # Full path to the file.
+        path = root + sep + file
+
+        # The command.
+        cmd = 'pylint %s' % path
+
+        # Execute.
+        pipe = Popen(cmd, shell=True, stdout=PIPE, close_fds=False)
+        waitpid(pipe.pid, 0)
+
+        # The STDOUT data.
+        data = pipe.stdout.readlines()
+
+        # Only display the import information.
+        for line in data:
+            if search("Unused import", line):
+                print("File:  %s;  %s" % (path, line[:-1]))

Propchange: trunk/devel_scripts/find_unused_imports.py
------------------------------------------------------------------------------
    svn:executable = *




Related Messages


Powered by MHonArc, Updated Sun Jun 16 13:40:02 2013