Welcome to onixcheck’s documentation!¶
Contents:
Overview¶
Introduction¶
ONIX for Books is an international XML standard for the publishing and book trade industry.
onixcheck
is a Python library and command line tool for validating ONIX
metadata. It allows you to validate ONIX versions 2.1 and 3.0 against the
official XML Schema.
- Free software: BSD license
Installation¶
On Windows you can download the standalone binary command line tool: onixcheck-0.9.4_win.zip
If you have Python or PyPy installed on your system you can do the usual:
pip install onixcheck
Quickstart¶
Command line usage examples¶
Validate all .xml, .onx, .onix files in current directory:
onixcheck
Validate a single onix file:
onixcheck myonixfile.xml
Validate all .xml files in /onixdata and its subdirectories:
onixcheck --path /onixdata --ext xml --recursive
Show help:
onixcheck -h
Using onixcheck as a python lib¶
Simple usage with onixcheck.validate:
>>> import onixcheck
>>> errors = onixcheck.validate('src/onixcheck/data/invalid_onix3_ref.xml')
>>> print(errors[0].short)
ERROR - SCHEMASV - invalid_onix3_ref.xml:4:0 - Element 'SentDateTime': This element is not expected. Expected is ( Sender ).
errors is either a list of Message objects (INVALID file) or an empty list (VALID file)
Documentation¶
Reference¶
onixcheck¶
-
onixcheck.
validate
(infile, schemas=(u'xsd', ))[source]¶ Validate an ONIX file.
Parameters: - infile (file or str) – File or path to file
- schemas (collections.Iterable[str]) – Iterable with paths to custom valdation profiles
Returns: List of Message objects (invalid ONIX) or empty list (valid ONIX)
Return type: list[Message]
-
class
onixcheck.models.
Message
[source]¶ A Validation message representing a single error condition.
Parameters: - level (str) – Error level
- validator (str) – The validator that raised the error
- location (str) – Location of error (filename:line:column)
- message (str) – Description of the error condiction
- error_type (str) – Type of error
-
classmethod
from_exception
(exc, filename=u'')[source]¶ Parameters: - exc (Exception) –
- filename (str) – Optional filename to prefix error location
Return Message:
-
classmethod
from_logentry
(logentry, filename=u'')[source]¶ Instanciate Message from lxml LogEntry object
Parameters: - logentry (_LogEntry) – Validatation error from LXML
- filename (str) – Optional filename to prefix error location
Return Message:
-
short
¶ Short string representation of message
-
class
onixcheck.models.
OnixFile
(infile)[source]¶ Convenience file object wrapper.
Parameters: infile (file or str) – File or path to file
-
class
onixcheck.models.
OnixMeta
[source]¶ Read and detect minimal ONIX file properties needed for validation.
Onix XML files may or may not have release and xmlns attributes on their root element. OnixMeta.from_file(infile) will detect Onix Version and Style and also patch the root element with the appropriate namespace needed for validation.
Parameters: - xml_version (str) – XML Version as str (“1.0”).
- xml_encoding (str) – XML Encoding as str (“utf-8”).
- onix_version (str) – Onix Version as string (“2.1” or “3.0”)
- onix_style (str) – Onix Style as str (“short” or “reference”)
- namespaces (dict) – dict of str with namspaces from the root element
-
onixcheck.utils.
iter_files
(root, exts=None, recursive=False)[source]¶ Iterate over file paths within root filtered by specified extensions.
Parameters: - root (str) – Root folder to start collecting files
- exts (iterable) – Restrict results to given file extensions
- recursive (bool) – Wether to walk the complete directory tree
Rtype collections.Iterable[str]: absolute file paths with given extensions
Contributing¶
Contributions are welcome, and they are greatly appreciated! Every little bit helps, and credit will always be given.
Bug reports¶
When reporting a bug please include:
- Your operating system name and version.
- Any details about your local setup that might be helpful in troubleshooting.
- Detailed steps to reproduce the bug.
Documentation improvements¶
onixcheck could always use more documentation, whether as part of the official onixcheck docs, in docstrings, or even on the web in blog posts, articles, and such.
Feature requests and feedback¶
The best way to send feedback is to file an issue at https://github.com/titusz/onixcheck/issues.
If you are proposing a feature:
- Explain in detail how it would work.
- Keep the scope as narrow as possible, to make it easier to implement.
- Remember that this is a volunteer-driven project, and that contributions are welcome :)
Development¶
To set up onixcheck for local development:
Clone your fork locally:
git clone git@github.com:your_name_here/onixcheck.git
Create a branch for local development:
git checkout -b name-of-your-bugfix-or-feature
Now you can make your changes locally.
When you’re done making changes, run all the checks, doc builder and spell checker with tox one command:
tox
Commit your changes and push your branch to GitHub:
git add . git commit -m "Your detailed description of your changes." git push origin name-of-your-bugfix-or-feature
Submit a pull request through the GitHub website.
Pull Request Guidelines¶
If you need some code review or feedback while you’re developing the code just make the pull request.
For merging, you should:
- Include passing tests (run
tox
) [1]. - Update documentation when there’s new API, functionality etc.
- Add a note to
CHANGELOG.rst
about the changes. - Add yourself to
AUTHORS.rst
.
[1] | If you don’t have all the necessary python versions available locally you can rely on Travis - it will run the tests for each change you add in the pull request. It will be slower though ... |
Tips¶
To run a subset of tests:
tox -e envname -- py.test -k test_myfeature
To run all the test environments in parallel (you need to pip install detox
):
detox
Authors¶
- Titusz Pan - http://py7.de
Changelog¶
0.9.5 (2016-08-19)¶
- Update Onix 3 to Code List issue 34
- Remove build artifacts from source distribution
0.9.4 (2016-07-15)¶
- Fix issue with windows console output encoding
- Update windows build to pyinstaller 3.1
0.9.3 (2016-05-10)¶
- Update ONIX 3.0 Schemas to Revision 3
- Add support for RELAX NG and custom schema validations
- Added validator name to short message output
0.9.2 (2016-04-11)¶
- Fix ExtentType in custom validation profile
- Fix false alarm with multiple Price elements in custom profile
0.9.1 (2016-04-11)¶
- Inital support for custom validation profiles
- Custom Google Play Books onix 3.0 validation profile
0.9.0 (2016-03-27)¶
- Added Python 3.5 testing / support
- Update to ONIX to Code List Issue 32 / 2016-01-24
0.8.1 (2015-07-23)¶
- More extensive documentation
0.8.0 (2015-07-23)¶
- Added CLI-support for fast directory traversal validation
- Secured XML-Parsing via defusedxml
- Catch basic XML syntax errors
- Windows standalone binary builds
0.4.0 (2015-07-18)¶
- First release on PyPI.