Skip to content

Commit

Permalink
MRG: Merge branch 'release/0.3.10'
Browse files Browse the repository at this point in the history
* release/0.3.10:
  DOC: HISTORY.rst: git-changelog.py --hdr=+ --rev 'release/0.3.10' | pbcopy
  RLS,DOC: setup.py,pyline.py: version 0.3.10
  UBY: pyline.py: log.info(('_rgx', _regexstr))
  BUG,REF: opts['cmd'], main->(int, results[]), log opts after all config
  BUG,UBY: pyline.py: log.info(('argv', argv))
  UBY,DOC: pyline.py: log.info(('pyline.version', __version__)) at startup
  BUG,UBY: pyline.py: logging config (default INFO, -q/--quiet, -v/--verbose (DEBUG))
  • Loading branch information
westurner committed Feb 15, 2016
2 parents 38e0393 + 5266662 commit aa2529a
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 43 deletions.
22 changes: 19 additions & 3 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,34 @@ History



release/0.3.10 (2016-02-14 21:55:05 -0600)
++++++++++++++++++++++++++++++++++++++++++
::

git log --reverse --pretty=format:'* %s [%h]' v0.3.9..release/0.3.10

* MRG: Merge tag 'v0.3.9' into develop [f7c8a16]
* BUG,UBY: pyline.py: logging config (default INFO, -q/--quiet, -v/--verbose (DEBUG)) [8a060ab]
* UBY,DOC: pyline.py: log.info(('pyline.version', __version__)) at startup [da1e883]
* BUG,UBY: pyline.py: log.info(('argv', argv)) [ede1d5e]
* BUG,REF: opts['cmd'], main->(int, results[]), log opts after all config [3cf9585]
* UBY: pyline.py: log.info(('_rgx', _regexstr)) [02bd234]
* RLS,DOC: setup.py,pyline.py: version 0.3.10 [ea6a1fd]


release/0.3.9 (2016-02-14 17:56:26 -0600)
+++++++++++++++++++++++++++++++++++++++++
v0.3.9 (2016-02-14 17:58:36 -0600)
++++++++++++++++++++++++++++++++++
::

git log --reverse --pretty=format:'* %s [%h]' v0.3.8..release/0.3.9
git log --reverse --pretty=format:'* %s [%h]' v0.3.8..v0.3.9

* ENH: pyline.py: --version arg [a38bf5a]
* MRG: Merge tag 'v0.3.8' into develop [85cd8e9]
* BUG,REF: pyline.py: output-filetype/-> output-format [fbcd9e2]
* BUG: pyline.py: only print version when opts.get('version') [ef8ac20]
* RLS,DOC: setup.py,pyline.py: version 0.3.9 [5f2c4a6]
* DOC: HISTORY.rst: git-changelog.py --hdr=+ --rev 'release/0.3.9' | pbcopy [ce95bae]
* MRG: Merge branch 'release/0.3.9' [38e0393]


v0.3.8 (2016-02-14 17:34:08 -0600)
Expand Down Expand Up @@ -275,6 +290,7 @@ v0.1.0 (2014-05-12 04:03:15 -0500)




0.0.1 (Unreleased)
+++++++++++++++++++
| Source: http://code.activestate.com/recipes/437932-pyline-a-grep-like-sed-like-command-line-tool/
Expand Down
70 changes: 34 additions & 36 deletions pyline/pyline.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def backwards(line):
"""

__version__ = version = "0.3.9"
__version__ = version = "0.3.10"

import cgi
import csv
Expand Down Expand Up @@ -108,20 +108,16 @@ def backwards(line):

STANDARD_REGEXES = {}

log = logging.getLogger()
#log.setLevel(logging.INFO)
DEFAULT_LOGGER='pyline'
log = logging.getLogger(DEFAULT_LOGGER)
hdlr = logging.StreamHandler(stream=sys.stderr)
# fmt = logging.Formatter(logging.BASIC_FORMAT)
fmt = logging.Formatter('%(levelname)-5s %(name)s:%(lineno)5s: %(message)s')
hdlr.setFormatter(fmt)
log.addHandler(hdlr)
# log.setLevel(logging.INFO)
log.setLevel(logging.DEBUG)


class NullHandler(logging.Handler):
def emit(self, record):
pass

log.debug("DEBUG!")

#h = NullHandler()
#log.addHandler(h)

Result = namedtuple('Result', ('n', 'result')) # , 'uri', 'meta'))


Expand Down Expand Up @@ -253,7 +249,7 @@ def pyline(iterable,
# l.lower() for l in regex_options
# if l.lower() in REGEX_OPTIONS),
# _regexstr)
log.debug("_rgx = %r" % _regexstr)
log.info(('_rgx', _regexstr))
_rgx = re.compile(_regexstr)

Path = str
Expand All @@ -276,7 +272,7 @@ def pyline(iterable,
codeobj = None
if cmd:
try:
log.info("_cmd: %r" % cmd)
log.info(("cmd", cmd))
codeobj = compile(cmd, 'command', 'eval')
except Exception as e:
e.message = "%s\ncmd: %s" % (e.message, cmd)
Expand Down Expand Up @@ -578,7 +574,7 @@ def keyfunc(obj, sortstr=sortstr, col_map=col_map):
errdata = [
(('keyvalue', keyvalue),
('sortstr', sortstr))]
log_((errdata,))
log.debug((errdata,))
return keyvalue

sorted_values = sorted(iterable,
Expand Down Expand Up @@ -880,8 +876,8 @@ class ResultWriter_jinja(ResultWriter):
escape_func = staticmethod(cgi.escape)

def setup(self, *args, **kwargs):
log_(('args', args))
log_(('kwargs', kwargs))
log.debug(('args', args))
log.debug(('kwargs', kwargs))
import jinja2, os
self.escape_func = jinja2.escape
templatepath = kwargs.get('template', kwargs.get('tmpl'))
Expand Down Expand Up @@ -1061,12 +1057,12 @@ def get_sort_function(**kwargs): # (sort_asc, sort_desc)
raise ValueError("sort_asc and sort_desc are both specified")
if sort_asc:
sortstr = sort_asc
log.info("sort_asc: %r" % sortstr)
reverse = False
log.info((("sort_asc", sortstr), ('reverse', reverse)))
if sort_desc:
sortstr = sort_desc
log.info("sort_desc: %r" % sortstr)
reverse = True
log.info((("sort_desc", sortstr), ('reverse', reverse)))
if sortstr:
def sortfunc(iterable,
sortstr=sortstr,
Expand Down Expand Up @@ -1114,10 +1110,9 @@ def main(args=None, iterable=None, output=None, results=None, opts=None):

prs = get_option_parser()

args = list(args) if args is not None else [] # sys.argv[1:]
argv = args = list(args) if args is not None else [] # sys.argv[1:]
if opts is None:
(opts, args) = prs.parse_args(args)
log_(('args1', args))
optsdict = None
if hasattr(opts, '__dict__'):
optsdict = opts.__dict__
Expand All @@ -1129,20 +1124,23 @@ def main(args=None, iterable=None, output=None, results=None, opts=None):
optsdict = {}
opts = optsdict

log = logging.getLogger()
log = logging.getLogger(DEFAULT_LOGGER)
if not opts.get('quiet'):
logging.basicConfig()
log = logging.getLogger()
log.setLevel(logging.DEBUG)
#logging.basicConfig(
#)
log.setLevel(logging.INFO)

if opts.get('verbose'):
log = logging.getLogger()
log.setLevel(logging.DEBUG)
log.debug(('opts', opts))
else:
log.setLevel(logging.WARN)
log.info(('pyline.version', __version__))
log.info(('argv', argv))
log.info(('args', args))

if opts.get('version'):
print(__version__)
return 0
return 0, None

opts['col_map'] = collections.OrderedDict()
if opts.get('col_mapstr'):
Expand All @@ -1154,7 +1152,6 @@ def main(args=None, iterable=None, output=None, results=None, opts=None):

if 'cmd' not in opts:
cmd = ' '.join(args)
log_(('args', args))
if not cmd.strip():
if opts.get('regex'):
if (opts.get('_output_format') == 'json'
Expand All @@ -1165,11 +1162,8 @@ def main(args=None, iterable=None, output=None, results=None, opts=None):
else:
cmd = 'obj'
opts['cmd'] = cmd.strip()
log_(('cmd', cmd))

if opts.get('verbose'):
log_(('opts', opts))

log.info(('cmd', opts['cmd']))
# opts['attrs'] = PylineResult._fields # XX
opts['attrs'] = list(opts['col_map'].keys()) if 'col_map' in opts else None

Expand Down Expand Up @@ -1200,6 +1194,9 @@ def main(args=None, iterable=None, output=None, results=None, opts=None):
#opts['_output_format'] = 'csv'
opts['_output_format'] = 'json'
#TODO
log.info(('_output_format', opts['_output_format']))

log.info(('opts', opts))

writer = ResultWriter.get_writer(
opts['_output'],
Expand Down Expand Up @@ -1243,9 +1240,10 @@ def main(args=None, iterable=None, output=None, results=None, opts=None):
# results
# sorted_results
# if passed, results are .append-ed to results
return 0
return 0, results


if __name__ == "__main__":
import sys
sys.exit(main(args=sys.argv[1:]))
retval, _ = main(args=sys.argv[1:])
sys.exit(retval)
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def build_long_description():

setup(
name='pyline',
version='0.3.9',
version='0.3.10',
description=(
'Pyline is a grep-like, sed-like, awk-like command-line tool '
'for line-based text processing in Python.'),
Expand Down
6 changes: 3 additions & 3 deletions tests/test_pyline.py
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,6 @@ def test_pyline_jinja__TemplateNotFound(self):

def test_pyline_jinja__testtemplate(self):
iterable = TEST_INPUT_A0
results = []
template_name = 'obj-newline.jinja2'
templatespath = os.path.realpath(os.path.join(
os.path.dirname(__file__),
Expand All @@ -623,13 +622,14 @@ def test_pyline_jinja__testtemplate(self):
'templates'))
templatepath = os.path.join(templatespath, template_name)
output_formatstr = 'jinja:template={}'.format(templatepath)
retcode = pyline.main(
results = []
retcode, _results = pyline.main(
#args=['-O', 'jinja:template=obj-newline.jinja'],
args=['-O', output_formatstr],
results=results,
iterable=iterable)
self.assertEqual(0, retcode)
self.assertTrue(results)
self.assertEqual(results, _results)

if __name__ == '__main__':
sys.exit(unittest.main())

0 comments on commit aa2529a

Please sign in to comment.