Skip to content

Commit

Permalink
added freshen-list as comman (in setup.py)
Browse files Browse the repository at this point in the history
  • Loading branch information
aleszoulek committed Sep 8, 2010
1 parent 695b3de commit 15662f2
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 80 deletions.
81 changes: 81 additions & 0 deletions freshen/commands.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
#!/usr/bin/env python

import sys
from os import listdir
from os.path import dirname, relpath, isdir, join

from freshen.core import TagMatcher, load_language, load_feature
from freshen.stepregistry import StepImplLoader, StepImplRegistry, UndefinedStepImpl



LANGUAGE = 'en'

class Colors(object):
HEADER = '\033[95m'
FILE = '\033[93m'
ENDC = '\033[0m'

@classmethod
def disable(cls):
cls.HEADER = ''
cls.FILE = ''
cls.ENDC = ''

@classmethod
def write(cls, text, color):
return "%s%s%s" % (color, text, cls.ENDC)



def load_file(filepath):
feature = load_feature(filepath, load_language(LANGUAGE))
registry = StepImplRegistry(TagMatcher)
loader = StepImplLoader()
loader.load_steps_impl(registry, dirname(feature.src_file), feature.use_step_defs)
return registry

def load_dir(dirpath):
registry = StepImplRegistry(TagMatcher)
loader = StepImplLoader()
def walktree(top, filter_func=lambda x: True):
names = listdir(top)
for name in names:
path = join(top, name)
if filter_func(path):
yield path
if isdir(path):
for i in walktree(path, filter_func):
yield i
for feature_file in walktree(dirpath, lambda x: x.endswith('.feature')):
feature = load_feature(feature_file, load_language(LANGUAGE))
loader.load_steps_impl(registry, dirname(feature.src_file), feature.use_step_defs)
return registry

def print_registry(registry):
steps = {}
for keyword in ['given', 'when', 'then']:
steps[keyword] = {}
for step in registry.steps[keyword]:
path = relpath(step.get_location())
filename = path.rsplit(':', 1)[0]
if filename not in steps[keyword]:
steps[keyword][filename] = []
if step not in steps[keyword][filename]:
steps[keyword][filename].append(step)
for keyword in ['given', 'when', 'then']:
print Colors.write(keyword.upper(), Colors.HEADER)
for filename in steps[keyword]:
print " %s" % Colors.write(filename, Colors.FILE)
for step in steps[keyword][filename]:
print " %s" % step.spec


def list_steps():
file_or_dir = sys.argv[1]
if isdir(file_or_dir):
registry = load_dir(file_or_dir)
else:
registry = load_file(file_or_dir)
print_registry(registry)

80 changes: 2 additions & 78 deletions scripts/freshen-list.py
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,84 +1,8 @@
#!/usr/bin/env python

import sys
from os import listdir
from os.path import dirname, relpath, isdir, join
from freshen.commands import list_steps

from freshen.core import TagMatcher, load_language, load_feature
from freshen.stepregistry import StepImplLoader, StepImplRegistry, UndefinedStepImpl



LANGUAGE = 'en'

class Colors(object):
HEADER = '\033[95m'
FILE = '\033[93m'
ENDC = '\033[0m'

@classmethod
def disable(cls):
cls.HEADER = ''
cls.FILE = ''
cls.ENDC = ''

@classmethod
def write(cls, text, color):
return "%s%s%s" % (color, text, cls.ENDC)



def load_file(filepath):
feature = load_feature(filepath, load_language(LANGUAGE))
registry = StepImplRegistry(TagMatcher)
loader = StepImplLoader()
loader.load_steps_impl(registry, dirname(feature.src_file), feature.use_step_defs)
return registry

def load_dir(dirpath):
registry = StepImplRegistry(TagMatcher)
loader = StepImplLoader()
def walktree(top, filter_func=lambda x: True):
names = listdir(top)
for name in names:
path = join(top, name)
if filter_func(path):
yield path
if isdir(path):
for i in walktree(path, filter_func):
yield i
for feature_file in walktree(dirpath, lambda x: x.endswith('.feature')):
feature = load_feature(feature_file, load_language(LANGUAGE))
loader.load_steps_impl(registry, dirname(feature.src_file), feature.use_step_defs)
return registry

def print_registry(registry):
steps = {}
for keyword in ['given', 'when', 'then']:
steps[keyword] = {}
for step in registry.steps[keyword]:
path = relpath(step.get_location())
filename = path.rsplit(':', 1)[0]
if filename not in steps[keyword]:
steps[keyword][filename] = []
if step not in steps[keyword][filename]:
steps[keyword][filename].append(step)
for keyword in ['given', 'when', 'then']:
print Colors.write(keyword.upper(), Colors.HEADER)
for filename in steps[keyword]:
print " %s" % Colors.write(filename, Colors.FILE)
for step in steps[keyword][filename]:
print " %s" % step.spec


def main():
file_or_dir = sys.argv[1]
if isdir(file_or_dir):
registry = load_dir(file_or_dir)
else:
registry = load_file(file_or_dir)
print_registry(registry)


if __name__ == '__main__':
main()
list_steps()
7 changes: 5 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,11 @@
'nose.plugins.0.10': [
'freshen = freshen.noseplugin:FreshenNosePlugin',
'freshenerr = freshen.noseplugin:FreshenErrorPlugin'
]
},
],
'console_scripts': [
'freshen-list = freshen.commands:list_steps',
],
},
classifiers = [
"Development Status :: 4 - Beta",
"License :: OSI Approved :: GNU General Public License (GPL)",
Expand Down

0 comments on commit 15662f2

Please sign in to comment.