Skip to content
Commits on Source (7)
/testenv/*
/build/*
/dist/*
/tests/unittests/__init__.pyc
/tests/unittests/test_parser.pyc
/tests/unittests/test_parser.py~
/tests/integrationtests/__init__.pyc
/tests/integrationtests/test_parser.pyc
/tests/integrationtests/test_parser.py~
/tests/__init__.pyc
/tests/unittest/__init__.pyc
/trollsift.egg-info/PKG-INFO
/trollsift.egg-info/SOURCES.txt
/trollsift.egg-info/dependency_links.txt
/trollsift.egg-info/not-zip-safe
/trollsift.egg-info/top_level.txt
/trollsift/version.pyc
/doc/source/api.rst~
/doc/source/index.rst~
/doc/source/installation.rst~
/doc/source/usage.rst~
/doc/build/doctrees/api.doctree
/doc/build/doctrees/environment.pickle
/doc/build/doctrees/index.doctree
/doc/build/doctrees/installation.doctree
/doc/build/doctrees/usage.doctree
/doc/build/html/.buildinfo
/doc/build/html/_sources/api.txt
/doc/build/html/_sources/index.txt
/doc/build/html/_sources/installation.txt
/doc/build/html/_sources/usage.txt
/doc/build/html/_static/ajax-loader.gif
/doc/build/html/_static/basic.css
/doc/build/html/_static/comment-bright.png
/doc/build/html/_static/comment-close.png
/doc/build/html/_static/comment.png
/doc/build/html/_static/default.css
/doc/build/html/_static/doctools.js
/doc/build/html/_static/down-pressed.png
/doc/build/html/_static/down.png
/doc/build/html/_static/file.png
/doc/build/html/_static/jquery.js
/doc/build/html/_static/minus.png
/doc/build/html/_static/plus.png
/doc/build/html/_static/pygments.css
/doc/build/html/_static/searchtools.js
/doc/build/html/_static/sidebar.js
/doc/build/html/_static/underscore.js
/doc/build/html/_static/up-pressed.png
/doc/build/html/_static/up.png
/doc/build/html/_static/websupport.js
/doc/build/html/api.html
/doc/build/html/genindex.html
/doc/build/html/index.html
/doc/build/html/installation.html
/doc/build/html/objects.inv
/doc/build/html/py-modindex.html
/doc/build/html/search.html
/doc/build/html/searchindex.js
/doc/build/html/usage.html
/.coverage
/tests/unittest/test_parser.pyc
/trollsift/__init__.pyc
/trollsift/parser.pyc
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
# C extensions
*.so
# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
pip-wheel-metadata/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST
# Jupyter Notebook
.ipynb_checkpoints
doc/build/*
.coverage
linters:
flake8:
python: 3
config: setup.cfg
......@@ -23,7 +23,8 @@ matrix:
os: osx
language: generic
install:
- git clone --depth 1 git://github.com/astropy/ci-helpers.git
#- git clone --depth 1 git://github.com/astropy/ci-helpers.git
- git clone --depth 1 -b all-the-fixes git://github.com/djhoese/ci-helpers.git
- source ci-helpers/travis/setup_conda.sh
script:
- coverage run --source=trollsift setup.py test
......
## Version 0.3.3 (2019/10/09)
### Pull Requests Merged
#### Bugs fixed
* [PR 15](https://github.com/pytroll/trollsift/pull/15) - Fix parse accepting strings with trailing characters
#### Features added
* [PR 14](https://github.com/pytroll/trollsift/pull/14) - Adding .stickler.yml configuration file
In this release 2 pull requests were closed.
## Version 0.3.2 (2019/01/14)
......
......@@ -19,10 +19,10 @@ environment:
NUMPY_VERSION: "stable"
install:
- "git clone --depth 1 git://github.com/astropy/ci-helpers.git"
# - "git clone --depth 1 git://github.com/astropy/ci-helpers.git"
- "git clone --depth 1 -b all-the-fixes git://github.com/djhoese/ci-helpers.git"
- "powershell ci-helpers/appveyor/install-miniconda.ps1"
- "SET PATH=%PYTHON%;%PYTHON%\\Scripts;%PATH%"
- "activate test"
- "conda activate test"
build: false # Not a C# project, build stuff at the test step instead.
......
trollsift (0.3.2-2) UNRELEASED; urgency=medium
trollsift (0.3.3-1) unstable; urgency=medium
* Team upload.
[ Bas Couwenberg ]
* Update gbp.conf to use --source-only-changes by default.
* Bump Standards-Version to 4.4.1, no changes.
-- Bas Couwenberg <sebastic@debian.org> Sun, 07 Jul 2019 10:22:36 +0200
[ Antonio Valentino ]
* New upstream release.
* Bump debhelper from old 11 to 12.
* Remove obsolete fields Name from debian/upstream/metadata.
* Explicitly set Rules-Requires-Root: no.
-- Antonio Valentino <antonio.valentino@tiscali.it> Fri, 11 Oct 2019 05:59:20 +0000
trollsift (0.3.2-1) unstable; urgency=medium
......
......@@ -4,7 +4,8 @@ Uploaders: Antonio Valentino <antonio.valentino@tiscali.it>
Section: python
Priority: optional
Testsuite: autopkgtest-pkg-python
Build-Depends: debhelper (>= 11),
Rules-Requires-Root: no
Build-Depends: debhelper-compat (= 12),
dh-python,
python3-all,
python3-setuptools,
......
---
Bug-Database: https://github.com/pytroll/trollsift/issues
Bug-Submit: https://github.com/pytroll/trollsift/issues/new
Name: Trollsift
Repository: https://github.com/pytroll/trollsift.git
Repository-Browse: https://github.com/pytroll/trollsift
......@@ -41,11 +41,11 @@ class Parser(object):
def __str__(self):
return self.fmt
def parse(self, stri):
def parse(self, stri, full_match=True):
'''Parse keys and corresponding values from *stri* using format
described in *fmt* string.
'''
return parse(self.fmt, stri)
return parse(self.fmt, stri, full_match=full_match)
def compose(self, keyvals):
'''Return string composed according to *fmt* string and filled
......@@ -295,8 +295,19 @@ class RegexFormatter(string.Formatter):
field_name, value = value
return self.regex_field(field_name, value, format_spec)
def extract_values(self, fmt, stri):
def extract_values(self, fmt, stri, full_match=True):
"""Extract information from string matching format.
Args:
fmt (str): Python format string to match against
stri (str): String to extract information from
full_match (bool): Force the match of the whole string. Default
to ``True``.
"""
regex = self.format(fmt)
if full_match:
regex = '^' + regex + '$'
match = re.match(regex, stri)
if match is None:
raise ValueError("String does not match pattern.")
......@@ -307,9 +318,10 @@ regex_formatter = RegexFormatter()
def _get_number_from_fmt(fmt):
"""
Helper function for extract_values,
figures out string length from format string.
"""Helper function for extract_values.
Figures out string length from format string.
"""
if '%' in fmt:
# its datetime
......@@ -362,10 +374,18 @@ def get_convert_dict(fmt):
return convdef
def parse(fmt, stri):
"""Parse keys and corresponding values from *stri* using format described in *fmt* string."""
def parse(fmt, stri, full_match=True):
"""Parse keys and corresponding values from *stri* using format described in *fmt* string.
Args:
fmt (str): Python format string to match against
stri (str): String to extract information from
full_match (bool): Force the match of the whole string. Default
True.
"""
convdef = get_convert_dict(fmt)
keyvals = regex_formatter.extract_values(fmt, stri)
keyvals = regex_formatter.extract_values(fmt, stri, full_match=full_match)
for key in convdef.keys():
keyvals[key] = _convert(convdef[key], keyvals[key])
......
......@@ -97,6 +97,15 @@ class TestParser(unittest.TestCase):
fmt = '/somedir/{directory}/hrpt_{platform:4s}{platnum:2s}_{time:%Y%m%d_%H%M}_{orbit:4d}.l1b'
self.assertRaises(ValueError, regex_formatter.extract_values, fmt, self.string)
def test_extract_values_full_match(self):
"""Test that a string must completely match."""
fmt = '{orbit:05d}'
val = regex_formatter.extract_values(fmt, '12345')
self.assertEqual(val, {'orbit': '12345'})
self.assertRaises(ValueError, regex_formatter.extract_values, fmt, '12345abc')
val = regex_formatter.extract_values(fmt, '12345abc', full_match=False)
self.assertEqual(val, {'orbit': '12345'})
def test_convert_digits(self):
self.assertEqual(_convert('d', '69022'), 69022)
self.assertRaises(ValueError, _convert, 'd', '69dsf')
......
......@@ -23,9 +23,9 @@ def get_keywords():
# setup.py/versioneer.py will grep for the variable names, so they must
# each be defined on a line of their own. _version.py will just call
# get_keywords().
git_refnames = " (HEAD -> master, tag: v0.3.2)"
git_full = "d0e5b6006e248974d806d0dd8e20cc6641d778fb"
git_date = "2019-01-14 17:05:37 -0600"
git_refnames = " (HEAD -> master, tag: v0.3.3)"
git_full = "e0a82d62b317df5f62eb2532480ef110f2fe3b16"
git_date = "2019-10-09 08:55:57 -0500"
keywords = {"refnames": git_refnames, "full": git_full, "date": git_date}
return keywords
......