ticket:66 add pep8 support with clean command
diff --git a/AlluraTesting/alluratest/command/__init__.py b/AlluraTesting/alluratest/command/__init__.py
new file mode 100644
index 0000000..437ffb7
--- /dev/null
+++ b/AlluraTesting/alluratest/command/__init__.py
@@ -0,0 +1 @@
+from clean import CleanSampleData
diff --git a/AlluraTesting/alluratest/command/base.py b/AlluraTesting/alluratest/command/base.py
new file mode 100644
index 0000000..8474d1b
--- /dev/null
+++ b/AlluraTesting/alluratest/command/base.py
@@ -0,0 +1,4 @@
+from allura.command.base import Command
+
+class TestingCommand(Command):
+    group_name = 'AlluraTesting'
diff --git a/AlluraTesting/alluratest/command/clean.py b/AlluraTesting/alluratest/command/clean.py
new file mode 100644
index 0000000..d850348
--- /dev/null
+++ b/AlluraTesting/alluratest/command/clean.py
@@ -0,0 +1,19 @@
+import os
+import pkg_resources
+
+import base
+from allura.command import base as allura_base
+
+class CleanSampleData(base.TestingCommand):
+    summary = 'Clean sample data folder'
+    parser = base.TestingCommand.standard_parser(verbose=True)
+
+    def command(self):
+        self.basic_setup()
+
+        samples_dir = pkg_resources.resource_filename(
+           'alluratest', 'data')
+        for fname in os.listdir(samples_dir):
+            fpath = os.path.join(samples_dir, fname)
+            if os.path.isfile(fpath):
+                os.unlink(fpath)
diff --git a/AlluraTesting/alluratest/test_syntax.py b/AlluraTesting/alluratest/test_syntax.py
index 2335a62..190c414 100644
--- a/AlluraTesting/alluratest/test_syntax.py
+++ b/AlluraTesting/alluratest/test_syntax.py
@@ -1,7 +1,9 @@
 import os.path
+import shutil
 from glob import glob
 from subprocess import Popen, PIPE
 import sys
+import pkg_resources
 
 toplevel_dir = os.path.abspath(os.path.dirname(__file__) + "/../..")
 
@@ -13,6 +15,13 @@
     sys.stderr.write(stderr)
     return proc.returncode
 
+def run_with_output(cmd):
+    proc = Popen(cmd, shell=True, cwd=toplevel_dir, stdout=PIPE, stderr=PIPE)
+    # must capture & reprint stdount, so that nosetests can capture it
+    (stdout, stderr) = proc.communicate()
+    sys.stderr.write(stderr)
+    return proc.returncode, stdout, stderr
+
 find_py = "find Allura Forge* -name '*.py'"
 
 # a recepe from itertools doc
@@ -75,3 +84,86 @@
 def test_no_tabs():
     if run(find_py + " | xargs grep '	' ") not in [1,123]:
         raise Exception('These should not use tab chars')
+
+def test_pep8():
+    samples_dir = pkg_resources.resource_filename(
+      'alluratest', 'data')
+    pep8_sample_path = os.path.join(samples_dir, 'pep8_sample.txt')
+    pep8_work_path = os.path.join(samples_dir, 'pep8_work.txt')
+
+    initialize_mode = True
+    if os.path.isfile(pep8_sample_path):
+        initialize_mode = False
+
+    if initialize_mode:
+        fsample = open(pep8_sample_path, "w")
+    else:
+        fsample = open(pep8_sample_path, "r")
+        sample_list = fsample.read().splitlines()
+        fsample.close()
+        fwork = open(pep8_work_path, "w")
+        work_list = []
+
+    proc = Popen(find_py, shell=True, cwd=toplevel_dir, stdout=PIPE, stderr=PIPE)
+    (find_stdout, stderr) = proc.communicate()
+    sys.stderr.write(stderr)
+    assert proc.returncode == 0, proc.returncode
+
+    all_files = [f for f in find_stdout.split('\n')
+                 if '/migrations/' not in f and f.strip()]
+    for files in grouper(20, all_files, fillvalue=''):
+        cmd = "pep8 " + ' '.join(files)
+        retval, stdout, stderr = run_with_output(cmd)
+
+        if initialize_mode:
+            fsample.write(stdout)
+        else:
+            fwork.write(stdout)
+            work_list = work_list + stdout.splitlines()
+
+    if initialize_mode:
+        fsample.close()
+    else:
+        fwork.close()
+
+        error = False
+        for l in work_list:
+            if l == '':
+                 continue
+
+            if l not in sample_list:
+                sys.stdout.write("%s\n" % l)
+                error = True
+        if error:
+            raise Exception('pep8 failure, see stdout')
+        else:
+            shutil.copyfile(pep8_work_path, pep8_sample_path)
+
+def test_pylint():
+    # TODO
+    return
+    samples_dir = pkg_resources.resource_filename(
+      'alluratest', 'tests/data')
+    pep8_sample_path = os.path.join(samples_dir, 'pep8_sample.txt')
+    run_with_output()
+    assert False
+    """
+    proc = Popen(find_py, shell=True, cwd=toplevel_dir, stdout=PIPE, stderr=PIPE)
+    (find_stdout, stderr) = proc.communicate()
+    sys.stderr.write(stderr)
+    assert proc.returncode == 0, proc.returncode
+
+    error = False
+    all_files = [f for f in find_stdout.split('\n')
+                 if '/migrations/' not in f and f.strip()]
+    for files in grouper(20, all_files, fillvalue=''):
+        cmd = "pylint -e " + ' '.join(files)
+        retval = run(cmd)
+        if retval == 1:
+            print
+            #print 'Command was: %s' % cmd
+            print 'Returned %s' % retval
+            error = True
+
+    assert False
+    """
diff --git a/AlluraTesting/setup.py b/AlluraTesting/setup.py
index 1149ee9..35ec0d9 100644
--- a/AlluraTesting/setup.py
+++ b/AlluraTesting/setup.py
@@ -18,5 +18,9 @@
       install_requires=[
         "poster",
           # -*- Extra requirements: -*-
-      ]
+      ],
+      entry_points="""
+      [paste.paster_command]
+      clean-sample-data = alluratest.command.clean:CleanSampleData
+      """
       )