Skip to content
This repository was archived by the owner on Apr 12, 2021. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ See the **Get Involved** section at the end of this readme to see the current st
- Unix-based OS, such as Mac or Linux (Windows support is unclear at this time.)
- [git](http://git-scm.com/)
- [Python 2.7](https://www.python.org/download/releases/2.7/)
or [Python 3.4](https://www.python.org/downloads/release/python-343/)
- [virtualenv](https://virtualenv.pypa.io/en/latest/)

See the [requirements.txt](requirements.txt) file for additional dependencies to be installed in the quick setup.
Expand Down
6 changes: 3 additions & 3 deletions clouseau/clients/abstract.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from builtins import object

from abc import ABCMeta, abstractmethod
from future.utils import with_metaclass



class AbstractClient:
__metaclass__ = ABCMeta

class AbstractClient(with_metaclass(ABCMeta, object)):
@abstractmethod
def render(self,data):
"""
Expand Down
5 changes: 3 additions & 2 deletions clouseau/clients/console.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from abstract import AbstractClient
from __future__ import absolute_import
from .abstract import AbstractClient
from jinja2 import Template, Environment, PackageLoader
from colors import *
from .colors import *
import re
import subprocess
import sys
Expand Down
6 changes: 4 additions & 2 deletions clouseau/clients/console_thin.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from abstract import AbstractClient
from __future__ import print_function
from __future__ import absolute_import
from .abstract import AbstractClient
from jinja2 import Template, Environment, PackageLoader

class ConsoleThinClient(AbstractClient):
Expand All @@ -19,4 +21,4 @@ def render(self, terms, data):
template = env.get_template('console_thin.html')

data_to_render = template.render(data=data, has_matches=len(matches) > 0)
print data_to_render
print(data_to_render)
28 changes: 16 additions & 12 deletions clouseau/clouseau.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
from __future__ import print_function
from __future__ import absolute_import
from builtins import object
#! /usr/bin/env python
# -*- coding: utf-8 -*-
#
Expand All @@ -9,17 +12,17 @@
import pprint
import sys
import subprocess
from clients import *
from clients.colors import *
from parser import Parser
from commit_parser import CommitParser
from terms_collector import TermsCollector
from clouseau_model import ClouseauModel
from .clients import *
from .clients.colors import *
from .parser import Parser
from .commit_parser import CommitParser
from .terms_collector import TermsCollector
from .clouseau_model import ClouseauModel


VERSION='0.2.0'

class Clouseau:
class Clouseau(object):
"""
Wrap and delegate
"""
Expand All @@ -41,7 +44,7 @@ def main(self , _args, client):
if(not args['skip']):
self.clone_repo( args['url'], args['repo_dir'] )
else:
print blue( 'Skipping git-clone or git-pull as --skip was found on the command line.' )
print(blue( 'Skipping git-clone or git-pull as --skip was found on the command line.' ))

if args['revlist'] != None and args['revlist'] != 'all':
parser = CommitParser()
Expand All @@ -61,14 +64,14 @@ def clone_repo(self, url, destination):
_out = subprocess.check_output(['git', 'clone', url, destination])

except subprocess.CalledProcessError:
print blue( "Directory, %s, exits. Trying git-pull instead of clone." % destination )
print(blue( "Directory, %s, exits. Trying git-pull instead of clone." % destination ))
_out = subprocess.check_output(['git', '--git-dir=%s/.git' % destination, 'pull'])
print smoke( "Git says: %s" % _out )
print(smoke( "Git says: %s" % _out ))
return _out

except :
e = sys.exc_info()[0]
print red( 'Problem writing to destination: %s' % destination )
print(red( 'Problem writing to destination: %s' % destination ))
raise

return _out
Expand All @@ -83,7 +86,8 @@ def parse_args( self, arguments ):
_pattern_path = os.path.join( _dir, _default_pattern_file )
_temp = os.path.join( _dir, "../temp")

p = arse.ArgumentParser (prog="clouseau", description=" Clouseau: A silly git inspector", version=VERSION)
p = arse.ArgumentParser (prog="clouseau", description=" Clouseau: A silly git inspector")
p.add_argument('--version', action='version', version=VERSION)
p.add_argument('--url', '-u', required=True, action="store", dest="url",
help="The fully qualified git URL (http://www.kernel.org/pub/software/scm/git/docs/git-clone.html)")
p.add_argument('--term', '-t', required=False, action="store", dest="term",
Expand Down
1 change: 1 addition & 0 deletions clouseau/clouseau_model.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from builtins import object
#! /usr/bin/env python
# -*- coding: utf-8 -*-
#
Expand Down
11 changes: 7 additions & 4 deletions clouseau/commit_parser.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
from __future__ import print_function
from __future__ import absolute_import
from builtins import object

import os
import sys
import re
import subprocess
import pprint
from clouseau_model import ClouseauModel
from .clouseau_model import ClouseauModel


# -----------------------------------------------------------------------------------------------
class CommitParser:
class CommitParser(object):
"""
Converts git-show's stdout to Python dictionary for any commit messages and file changes that match the terms in the patterns files
"""
Expand All @@ -25,7 +28,7 @@ def parse( self, terms, repo, revlist, clouseau_model, **kwargs ):
for rev in revlist.strip().split(' '):
output = self.get_commit(git_dir, rev)
if output.strip() == '':
print "WARNING: No output was returned from git for commit [%s]. Ensure the commit exists" % rev
print("WARNING: No output was returned from git for commit [%s]. Ensure the commit exists" % rev)
else:
self.parse_commit( terms, output, clouseau_model )

Expand All @@ -38,7 +41,7 @@ def get_commit(self, git_dir, commit):
git_show = subprocess.Popen(git_show_cmd, stderr=subprocess.PIPE, stdout=subprocess.PIPE) # , cwd=git_dir
(out,err) = git_show.communicate()
if err:
print "ERROR running git command [%s]: %s" % (git_show_cmd, err)
print("ERROR running git command [%s]: %s" % (git_show_cmd, err))

return out

Expand Down
16 changes: 9 additions & 7 deletions clouseau/parser.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
from builtins import str
from builtins import object

import os
import sys
import re
import subprocess

# -----------------------------------------------------------------------------------------------
class Parser:
class Parser(object):
"""
Converts git-grep's stdout to Python dictionary
"""
Expand Down Expand Up @@ -60,32 +62,32 @@ def search( self, git_dir, terms, revlist, clouseau ):
stdout=subprocess.PIPE)

(out,err) = git_grep.communicate()

clouseau.update( {term: {}} )

for line in out.split('\n'):
for line in out.split(b'\n'):
# We don't know how a lot of the data is encoded, so make sure it's utf-8 before
# processing
if line == '':
continue
try:
line = unicode( line, 'utf-8' )
line = str( line, 'utf-8' )
except UnicodeDecodeError:
line = unicode( line, 'latin-1' )
line = str( line, 'latin-1' )


if file_name_heading.match( line ):
title = line.split(':', 1)[1]
title = line.replace('/','_')
title = title.replace('.','_').strip()
_src = line.strip().encode('utf-8')
_srca = _src.split(':', 1)
_srca = _src.split(b':', 1)
clouseau[term][title] = {'src' : _srca[1] }
clouseau[term][title]['refspec'] = _srca[0]
git_log_cmd = subprocess.Popen( ['git', '--git-dir', git_dir, 'log', _srca[0] , '-1'],\
stderr=subprocess.PIPE, stdout=subprocess.PIPE )
git_log = git_log_cmd.communicate()[0]
clouseau[term][title]['git_log'] = [ x.strip() for x in git_log.split('\n') if x != '' ]
clouseau[term][title]['git_log'] = [ x.strip() for x in git_log.split(b'\n') if x != '' ]
#clouseau[term][title] = {'ref' : _srca[0] }
clouseau[term][title]['matched_lines'] = []
continue
Expand Down
3 changes: 2 additions & 1 deletion clouseau/terms_collector.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from builtins import object
import os
import sys


# -----------------------------------------------------------------------------------------------
class TermsCollector:
class TermsCollector(object):
"""
Collects all search terms from the patterns files
"""
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
jinja2
nose
nose-progressive
future
2 changes: 1 addition & 1 deletion tests/clouseau_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def commit_parser_merge_only_test():
terms = TermsCollector().collect_terms('clouseau/patterns/default.txt', None)
model = ClouseauModel('https://github.com/cfpb/clouseau', terms)
parser.parse_commit(terms, commit_output.read(), model)
exec_in_commit = model.model['exec'].keys()[0]
exec_in_commit = list(model.model['exec'].keys())[0]
eq_(1, model.model['exec'][exec_in_commit]['matched_lines'][0][0])
eq_('Commit Message', model.model['exec'][exec_in_commit]['src'])

Expand Down
15 changes: 8 additions & 7 deletions tests/color_tests.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,28 @@
#! /usr/bin/env python
# -*- coding: utf-8 -*-

from __future__ import print_function
from clouseau.clients import colors




print dir( colors )
print(dir( colors ))

for c in colors.codes:
print colors.color( c, c )
print(colors.color( c, c ))


print colors.ok()
print colors.fail()
print(colors.ok())
print(colors.fail())

print colors.ok( 'OK with text' )
print colors.fail( 'Fail with text' )
print(colors.ok( 'OK with text' ))
print(colors.fail( 'Fail with text' ))


print ('-------------------')

print colors.gray('Gray Text')
print(colors.gray('Gray Text'))



Expand Down
3 changes: 2 additions & 1 deletion tests/integration_tests.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import print_function
import os
from nose.tools import *
from clouseau.clouseau import Clouseau
Expand All @@ -15,7 +16,7 @@ def console_client_test():
terms = ['password']
args = ['-u', 'https://github.com/virtix/cato.git']
parsed = clouseau.parse_args( args )
print parsed
print(parsed)
ids = parser.parse( terms=terms, repo=parsed['repo_dir'], revlist=parsed['revlist'],
before=parsed['before'], after=parsed['after'], author=parsed['author'],
github_url=parsed['github_url'])
Expand Down